@@ -27,7 +27,7 @@ func newFixture(t *testing.T) *fixture {
2727 return f
2828}
2929
30- func (f * fixture ) goodGenVars (op , ts string ) {
30+ func (f * fixture ) configGenVars (op , ts string ) {
3131 conf := NewConfig ().WithOutputPath (op ).WithTokenSeparator (ts )
3232 gv := NewGenerator ().WithConfig (conf )
3333 f .rs = newRetrieveStrategy (NewDefatultStrategy (), * conf )
@@ -38,40 +38,46 @@ func TestGenVarsWithConfig(t *testing.T) {
3838
3939 f := newFixture (t )
4040
41- f .goodGenVars (customop , customts )
41+ f .configGenVars (customop , customts )
4242 if f .c .config .outpath != customop {
43- f .t .Errorf (testutils .TestPhrase , customop , f .c .config .outpath )
43+ f .t .Errorf (testutils .TestPhrase , f .c .config .outpath , customop )
4444 }
4545 if f .c .config .tokenSeparator != customts {
46- f .t .Errorf (testutils .TestPhrase , customts , f .c .config .tokenSeparator )
46+ f .t .Errorf (testutils .TestPhrase , f .c .config .tokenSeparator , customts )
4747 }
4848}
4949
5050func TestStripPrefixNormal (t * testing.T ) {
51-
52- want := "/normal/without/prefix"
53- prefix := SecretMgrPrefix
54- f := newFixture (t )
55- f .goodGenVars (standardop , standardts )
56-
57- got := f .rs .stripPrefix (fmt .Sprintf ("%s#%s" , prefix , want ), prefix )
58- if got != want {
59- f .t .Errorf (testutils .TestPhrase , want , got )
51+ ttests := map [string ]struct {
52+ prefix ImplementationPrefix
53+ token string
54+ keySeparator string
55+ tokenSeparator string
56+ f * fixture
57+ expect string
58+ }{
59+ "standard azkv" : {AzKeyVaultSecretsPrefix , "AZKVSECRET://vault1/secret2" , "|" , "://" , newFixture (t ), "vault1/secret2" },
60+ "standard hashivault" : {HashicorpVaultPrefix , "VAULT://vault1/secret2" , "|" , "://" , newFixture (t ), "vault1/secret2" },
61+ "custom separator hashivault" : {HashicorpVaultPrefix , "VAULT#vault1/secret2" , "|" , "#" , newFixture (t ), "vault1/secret2" },
6062 }
61-
62- gotNegative := f .rs .stripPrefix (fmt .Sprintf ("%s___%s" , prefix , want ), prefix )
63- if gotNegative == want {
64- f .t .Errorf (testutils .TestPhrase , want , gotNegative )
63+ for name , tt := range ttests {
64+ t .Run (name , func (t * testing.T ) {
65+ tt .f .configGenVars (tt .keySeparator , tt .tokenSeparator )
66+ got := tt .f .rs .stripPrefix (tt .token , tt .prefix )
67+ if got != tt .expect {
68+ t .Errorf (testutils .TestPhrase , got , tt .expect )
69+ }
70+ })
6571 }
6672}
6773
6874func Test_stripPrefix (t * testing.T ) {
6975 f := newFixture (t )
70- f .goodGenVars (standardop , standardts )
76+ f .configGenVars (standardop , standardts )
7177 tests := []struct {
7278 name string
7379 token string
74- prefix string
80+ prefix ImplementationPrefix
7581 expect string
7682 }{
7783 {
@@ -99,7 +105,7 @@ func Test_stripPrefix(t *testing.T) {
99105
100106func Test_NormaliseMap (t * testing.T ) {
101107 f := newFixture (t )
102- f .goodGenVars (standardop , standardts )
108+ f .configGenVars (standardop , standardts )
103109 tests := []struct {
104110 name string
105111 gv * GenVars
@@ -133,7 +139,7 @@ func Test_NormaliseMap(t *testing.T) {
133139
134140func Test_KeyLookup (t * testing.T ) {
135141 f := newFixture (t )
136- f .goodGenVars (standardop , standardts )
142+ f .configGenVars (standardop , standardts )
137143
138144 tests := []struct {
139145 name string
@@ -206,7 +212,7 @@ func Test_ConvertToExportVars(t *testing.T) {
206212 for _ , tt := range tests {
207213 t .Run (tt .name , func (t * testing.T ) {
208214 f := newFixture (t )
209- f .goodGenVars (standardop , standardts )
215+ f .configGenVars (standardop , standardts )
210216 f .c .rawMap = tt .rawMap
211217 f .c .ConvertToExportVar ()
212218 got := f .c .outString
0 commit comments