@@ -9,18 +9,18 @@ import (
99
1010func TestMapMerge1 (t * testing.T ) {
1111 a := map [interface {}]interface {}{
12- "foo" : "bar" ,
12+ "foo" : "bar" ,
1313 "fizz" : "buzz" ,
1414 }
1515 b := map [interface {}]interface {}{
1616 "fizz" : "fizz" ,
1717 }
1818 c := map [interface {}]interface {}{
19- "foo" : "bar" ,
19+ "foo" : "bar" ,
2020 "fizz" : "fizz" ,
2121 }
2222 d := mergeMaps (a , b )
23- assert .Equal (t , c , d , "Maps should be equal" )
23+ assert .Equal (t , c , d , "Maps should be equal" )
2424}
2525
2626func TestMapMerge2 (t * testing.T ) {
@@ -39,7 +39,7 @@ func TestMapMerge2(t *testing.T) {
3939 "d" : "4" ,
4040 }
4141 d := mergeMaps (a , b )
42- assert .Equal (t , c , d , "Maps should be equal" )
42+ assert .Equal (t , c , d , "Maps should be equal" )
4343}
4444
4545func TestMapMerge3 (t * testing.T ) {
@@ -55,7 +55,7 @@ func TestMapMerge3(t *testing.T) {
5555 "b" : 42 ,
5656 }
5757 d := mergeMaps (a , b )
58- assert .Equal (t , c , d , "Maps should be equal" )
58+ assert .Equal (t , c , d , "Maps should be equal" )
5959}
6060
6161func TestMapMerge4 (t * testing.T ) {
@@ -71,7 +71,7 @@ func TestMapMerge4(t *testing.T) {
7171 "b" : []interface {}{"2" , "3" },
7272 }
7373 d := mergeMaps (a , b )
74- assert .Equal (t , c , d , "Maps should be equal" )
74+ assert .Equal (t , c , d , "Maps should be equal" )
7575}
7676
7777func TestTemplateValuesMerge (t * testing.T ) {
@@ -159,31 +159,57 @@ func TestTemplateValuesMerge(t *testing.T) {
159159 assert .Equal (t , expectedMergedTemplateValues , templateValues , "TemplateValues should be equal" )
160160}
161161
162-
163162func TestValuesFileLoading (t * testing.T ) {
164163 c := util .GetDummyCliContext ()
165164 util .SetCliContext (c )
166165 util .ComputeRootDir (c )
167-
168- LoadValues ()
169-
166+
167+ LoadValues ("" )
168+
170169 valuesSet1 := map [interface {}]interface {}{
171- "namespace" : "gitops-dev" ,
172- "stage" : "dev" ,
170+ "namespace" : "gitops-dev" ,
171+ "stage" : "dev" ,
173172 "databaseUsername" : "my-very-strong-username" ,
174173 "databasePassword" : "my-very-strong-password" ,
175174 }
176175
177- mergedValues1 := GetValuesForPath ("test_assets/implicit-name.gitops.secret.enc.yml" )
176+ mergedValues1 := GetValuesForPath ("test_assets/implicit-name.gitops.secret.enc.yml" , "" )
178177 assert .Equal (t , valuesSet1 , mergedValues1 , "Values should be equal" )
179178
180179 valuesSet2 := map [interface {}]interface {}{
181- "namespace" : "gitops-dev" ,
182- "stage" : "sub-dev" ,
180+ "namespace" : "gitops-dev" ,
181+ "stage" : "sub-dev" ,
183182 "databaseUsername" : "my-very-strong-username" ,
184183 "databasePassword" : "my-very-strong-password" ,
185- "key" : "fooo" ,
184+ "key" : "fooo" ,
186185 }
187- mergedValues2 := GetValuesForPath ("test_assets/subdirectory/subdir-secret.gitops.secret.enc.yml" )
186+ mergedValues2 := GetValuesForPath ("test_assets/subdirectory/subdir-secret.gitops.secret.enc.yml" , "" )
188187 assert .Equal (t , valuesSet2 , mergedValues2 , "Values should be equal" )
189- }
188+ }
189+
190+ func TestIsInParentPath (t * testing.T ) {
191+ tests := []struct {
192+ name string
193+ path1 string
194+ path2 string
195+ expected bool
196+ }{
197+ {"Direct Parent" , "a/b/c.txt" , "a/b/d/" , true },
198+ {"Grandparent" , "a/b/c.txt" , "a/b/d/e/" , true },
199+ {"Not a Parent" , "a/b/c.txt" , "f/g/h/" , false },
200+ {"Same Directory" , "a/b/c.txt" , "a/b/" , true },
201+ {"Root Directory" , "c.txt" , "/" , false },
202+ {"Path2 is Parent" , "a/b/c/d.txt" , "a/b/c" , true },
203+ {"Nested under filter" , "a/b/c/d.txt" , "a/" , true },
204+ }
205+
206+ for _ , tt := range tests {
207+ t .Run (tt .name , func (t * testing.T ) {
208+ result := valuesFileApplicable (tt .path1 , tt .path2 )
209+
210+ if result != tt .expected {
211+ t .Errorf ("isInParentPath(%q, %q) = %v; expected %v" , tt .path1 , tt .path2 , result , tt .expected )
212+ }
213+ })
214+ }
215+ }
0 commit comments