@@ -78,7 +78,7 @@ policies:
7878 )
7979
8080 p := Plugin {}
81- err := p .Config ([]byte (exampleConfig ))
81+ err := p .Config ([]byte (exampleConfig ), tmpDir )
8282 if err != nil {
8383 t .Fatal (err .Error ())
8484 }
@@ -165,7 +165,7 @@ policies:
165165 configMapPath ,
166166 )
167167 p := Plugin {}
168- err := p .Config ([]byte (defaultsConfig ))
168+ err := p .Config ([]byte (defaultsConfig ), tmpDir )
169169 if err != nil {
170170 t .Fatal (err .Error ())
171171 }
@@ -214,7 +214,7 @@ policies:
214214 - path: input/configmap.yaml
215215`
216216 p := Plugin {}
217- err := p .Config ([]byte (config ))
217+ err := p .Config ([]byte (config ), "" )
218218 if err == nil {
219219 t .Fatal ("Expected an error but did not get one" )
220220 }
@@ -223,7 +223,7 @@ policies:
223223 assertEqual (t , err .Error (), expected )
224224}
225225
226- func TestCreateInvalidPolicyName (t * testing.T ) {
226+ func TestConfigInvalidPolicyName (t * testing.T ) {
227227 t .Parallel ()
228228 tmpDir := t .TempDir ()
229229 createConfigMap (t , tmpDir , "configmap.yaml" )
@@ -247,7 +247,7 @@ policies:
247247 )
248248
249249 p := Plugin {}
250- err := p .Config ([]byte (defaultsConfig ))
250+ err := p .Config ([]byte (defaultsConfig ), tmpDir )
251251 if err == nil {
252252 t .Fatal ("Expected an error but did not get one" )
253253 }
@@ -267,7 +267,7 @@ policyDefaults:
267267 namespace: my-policies
268268`
269269 p := Plugin {}
270- err := p .Config ([]byte (config ))
270+ err := p .Config ([]byte (config ), "" )
271271 if err == nil {
272272 t .Fatal ("Expected an error but did not get one" )
273273 }
@@ -276,6 +276,43 @@ policyDefaults:
276276 assertEqual (t , err .Error (), expected )
277277}
278278
279+ func TestConfigInvalidPath (t * testing.T ) {
280+ t .Parallel ()
281+ tmpDir := t .TempDir ()
282+ createConfigMap (t , tmpDir , "configmap.yaml" )
283+ configMapPath := path .Join (tmpDir , "configmap.yaml" )
284+ policyNS := "my-policies"
285+ policyName := "policy-app-config"
286+ defaultsConfig := fmt .Sprintf (
287+ `
288+ apiVersion: policy.open-cluster-management.io/v1
289+ kind: PolicyGenerator
290+ metadata:
291+ name: policy-generator-name
292+ policyDefaults:
293+ namespace: %s
294+ policies:
295+ - name: %s
296+ manifests:
297+ - path: %s
298+ ` ,
299+ policyNS , policyName , configMapPath ,
300+ )
301+
302+ p := Plugin {}
303+ // Provide a base directory that isn't in the same directory tree as tmpDir.
304+ baseDir := t .TempDir ()
305+ err := p .Config ([]byte (defaultsConfig ), baseDir )
306+ if err == nil {
307+ t .Fatal ("Expected an error but did not get one" )
308+ }
309+
310+ expected := fmt .Sprintf (
311+ "the manifest path %s is not in the same directory tree as the kustomization.yaml file" , configMapPath ,
312+ )
313+ assertEqual (t , err .Error (), expected )
314+ }
315+
279316func TestConfigMultiplePlacements (t * testing.T ) {
280317 t .Parallel ()
281318 const config = `
@@ -295,7 +332,7 @@ policies:
295332 - path: input/configmap.yaml
296333`
297334 p := Plugin {}
298- err := p .Config ([]byte (config ))
335+ err := p .Config ([]byte (config ), "" )
299336 if err == nil {
300337 t .Fatal ("Expected an error but did not get one" )
301338 }
@@ -331,7 +368,7 @@ policies:
331368 path .Join (tmpDir , "configmap2.yaml" ),
332369 )
333370 p := Plugin {}
334- err := p .Config ([]byte (config ))
371+ err := p .Config ([]byte (config ), tmpDir )
335372 if err == nil {
336373 t .Fatal ("Expected an error but did not get one" )
337374 }
@@ -352,7 +389,7 @@ policies:
352389- name: policy-app-config
353390`
354391 p := Plugin {}
355- err := p .Config ([]byte (config ))
392+ err := p .Config ([]byte (config ), "" )
356393 if err == nil {
357394 t .Fatal ("Expected an error but did not get one" )
358395 }
@@ -381,7 +418,7 @@ policies:
381418 manifestPath ,
382419 )
383420 p := Plugin {}
384- err := p .Config ([]byte (config ))
421+ err := p .Config ([]byte (config ), tmpDir )
385422 if err == nil {
386423 t .Fatal ("Expected an error but did not get one" )
387424 }
@@ -409,7 +446,7 @@ policies:
409446 path .Join (tmpDir , "configmap.yaml" ),
410447 )
411448 p := Plugin {}
412- err := p .Config ([]byte (config ))
449+ err := p .Config ([]byte (config ), tmpDir )
413450 if err == nil {
414451 t .Fatal ("Expected an error but did not get one" )
415452 }
@@ -442,7 +479,7 @@ policies:
442479 path .Join (tmpDir , "configmap.yaml" ),
443480 )
444481 p := Plugin {}
445- err := p .Config ([]byte (config ))
482+ err := p .Config ([]byte (config ), tmpDir )
446483 if err == nil {
447484 t .Fatal ("Expected an error but did not get one" )
448485 }
0 commit comments