@@ -50,4 +50,30 @@ func TestValidateParamIsUsed(t *testing.T) {
50
50
//
51
51
assert .NilError (t , err )
52
52
}
53
+
54
+ // use "{{if .Param.rootful \"true\"}}{{else}}{{end}}"" in provision, probe, copyToHost, and portForward
55
+ rootfulYaml := `param:
56
+ rootful: true`
57
+ fieldsUsingIfParamRootfulTrue := []string {
58
+ `provision: [{"script": "echo {{if eq .Param.rootful \"true\"}}rootful{{else}}rootless{{end}}"}]` ,
59
+ `probes: [{"script": "echo {{if eq .Param.rootful \"true\"}}rootful{{else}}rootless{{end}}"}]` ,
60
+ `copyToHost: [{"guest": "/tmp/{{if eq .Param.rootful \"true\"}}rootful{{else}}rootless{{end}}", "host": "/tmp"}]` ,
61
+ `copyToHost: [{"guest": "/tmp", "host": "/tmp/{{if eq .Param.rootful \"true\"}}rootful{{else}}rootless{{end}}"}]` ,
62
+ `portForwards: [{"guestSocket": "{{if eq .Param.rootful \"true\"}}/var/run{{else}}/run/user/{{.UID}}{{end}}/docker.sock", "hostSocket": "{{.Dir}}/sock/docker.sock"}]` ,
63
+ `portForwards: [{"guestSocket": "/var/run/docker.sock", "hostSocket": "{{.Dir}}/sock/docker-{{if eq .Param.rootful \"true\"}}rootfule{{else}}rootless{{end}}.sock"}]` ,
64
+ }
65
+ for _ , fieldUsingIfParamRootfulTrue := range fieldsUsingIfParamRootfulTrue {
66
+ _ , err = Load ([]byte (fieldUsingIfParamRootfulTrue + "\n " + rootfulYaml ), "paramIsUsed.yaml" )
67
+ //
68
+ assert .NilError (t , err )
69
+ }
70
+
71
+ // use rootFul instead of rootful
72
+ rootFulYaml := `param:
73
+ rootFul: true`
74
+ for _ , fieldUsingIfParamRootfulTrue := range fieldsUsingIfParamRootfulTrue {
75
+ _ , err = Load ([]byte (fieldUsingIfParamRootfulTrue + "\n " + rootFulYaml ), "paramIsUsed.yaml" )
76
+ //
77
+ assert .Error (t , err , "field `param` key \" rootFul\" is not used in any provision, probe, copyToHost, or portForward" )
78
+ }
53
79
}
0 commit comments