Skip to content

Commit 0a7a1a8

Browse files
committed
fix: add more unit tests
1 parent a247c01 commit 0a7a1a8

File tree

4 files changed

+69
-2
lines changed

4 files changed

+69
-2
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11

22
OWNER := dnitsch
33
NAME := configmanager
4-
GIT_TAG := "1.0.1"
5-
VERSION := "v1.0.1"
4+
GIT_TAG := "1.1.0"
5+
VERSION := "v1.1.0"
66
# VERSION := "$(shell git describe --tags --abbrev=0)"
77
REVISION := $(shell git rev-parse --short HEAD)
88

pkg/generator/generator.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ func (c *GenVars) stripPrefix(in, prefix string) string {
262262
return stripPrefix(in, prefix, c.config.tokenSeparator, c.config.keySeparator)
263263
}
264264

265+
// stripPrefix
265266
func stripPrefix(in, prefix, tokenSeparator, keySeparator string) string {
266267
t := in
267268
b := regexp.MustCompile(`[|].*`).ReplaceAll([]byte(t), []byte(""))

pkg/generator/generator_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,38 @@ func TestStripPrefixNormal(t *testing.T) {
6262
}
6363
}
6464

65+
func Test_stripPrefix(t *testing.T) {
66+
f := newFixture(t)
67+
f.goodGenVars(standardop, standardts)
68+
tests := []struct {
69+
name string
70+
token string
71+
prefix string
72+
expect string
73+
}{
74+
{
75+
name: "simple",
76+
token: fmt.Sprintf("%s#/test/123", SecretMgrPrefix),
77+
prefix: SecretMgrPrefix,
78+
expect: "/test/123",
79+
},
80+
{
81+
name: "key appended",
82+
token: fmt.Sprintf("%s#/test/123|key", ParamStorePrefix),
83+
prefix: ParamStorePrefix,
84+
expect: "/test/123",
85+
},
86+
}
87+
for _, tt := range tests {
88+
t.Run(tt.name, func(t *testing.T) {
89+
got := f.c.stripPrefix(tt.token, tt.prefix)
90+
if tt.expect != got {
91+
t.Errorf(testutils.TestPhrase, tt.expect, got)
92+
}
93+
})
94+
}
95+
}
96+
6597
func Test_NormaliseMap(t *testing.T) {
6698
f := newFixture(t)
6799
f.goodGenVars(standardop, standardts)

pkg/generator/paramstore_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,40 @@ func Test_GetParamStoreVarHappy(t *testing.T) {
5959
},
6060
genVars: &GenVars{},
6161
},
62+
{
63+
name: "successVal with keyseparator",
64+
token: "AWSPARAMSTR#/token/1|somekey",
65+
value: tsuccessParam,
66+
mockClient: func(t *testing.T) paramStoreApi {
67+
return mockParamApi(func(ctx context.Context, params *ssm.GetParameterInput, optFns ...func(*ssm.Options)) (*ssm.GetParameterOutput, error) {
68+
t.Helper()
69+
if params.Name == nil {
70+
t.Fatal("expect name to not be nil")
71+
}
72+
73+
if strings.Contains(*params.Name, "#") {
74+
t.Errorf("incorrectly stripped token separator")
75+
}
76+
77+
if strings.Contains(*params.Name, "|somekey") {
78+
t.Errorf("incorrectly stripped key separator")
79+
}
80+
81+
if strings.Contains(*params.Name, ParamStorePrefix) {
82+
t.Errorf("incorrectly stripped prefix")
83+
}
84+
85+
if !params.WithDecryption {
86+
t.Fatal("expect WithDecryption to not be false")
87+
}
88+
89+
return &ssm.GetParameterOutput{
90+
Parameter: &types.Parameter{Value: &tsuccessParam},
91+
}, nil
92+
})
93+
},
94+
genVars: &GenVars{},
95+
},
6296
}
6397
for _, tt := range tests {
6498
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)