代码拉取完成,页面将自动刷新
package scy_test
import (
"context"
"github.com/stretchr/testify/assert"
"github.com/viant/scy"
"github.com/viant/scy/cred"
_ "github.com/viant/scy/kms/blowfish"
"path"
"testing"
)
func TestService_Load(t *testing.T) {
basePath := "/tmp/" // os.TempDir()
var testCases = []struct {
description string
secret *scy.Secret
resource *scy.Resource
expect interface{}
}{
{
description: "raw secret with local fs and key",
resource: scy.NewResource("key", path.Join(basePath, "secret.sec"), "blowfish://default"),
secret: scy.NewSecret("this is secret", nil),
expect: "this is secret",
},
{
description: "securable secrets",
resource: scy.NewResource(cred.Basic{}, path.Join(basePath, "json.sec"), "blowfish://default"),
secret: scy.NewSecret(&cred.Basic{Username: "Bob", Password: "ch@nge!Me"}, nil),
expect: &cred.Basic{Username: "Bob", Password: "ch@nge!Me"},
},
{
description: "generic secrets",
resource: scy.NewResource("", path.Join(basePath, "json.sec"), "blowfish://default"),
secret: scy.NewSecret(&cred.Basic{Username: "Bob", Password: "ch@nge!Me"}, nil),
expect: &cred.Generic{SSH: cred.SSH{Basic: cred.Basic{Username: "Bob", Password: "ch@nge!Me"}}},
},
}
for _, testCase := range testCases {
srv := scy.New()
ctx := context.Background()
testCase.secret.Resource = testCase.resource
err := srv.Store(ctx, testCase.secret)
if !assert.Nil(t, err, testCase.description) {
continue
}
secret, err := srv.Load(ctx, testCase.resource)
if !assert.Nil(t, err, testCase.description) {
continue
}
assert.EqualValues(t, testCase.expect, secret.Target, testCase.description)
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。