1 Star 0 Fork 0

liwen_test_sync_group/scy

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
service_test.go 1.68 KB
一键复制 编辑 原始数据 按行查看 历史
Adrian Witas 提交于 2022-04-13 01:16 +08:00 . patched base64 encoding
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)
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/liwen_test_sync_group/scy.git
git@gitee.com:liwen_test_sync_group/scy.git
liwen_test_sync_group
scy
scy
main

搜索帮助