Skip to content

Commit 5450539

Browse files
committed
limayaml: add {{if .Param.rootful}}{{else}}{{end}} pattern to TestValidateParamIsUsed
Signed-off-by: Norio Nomura <norio.nomura@gmail.com>
1 parent 762d46a commit 5450539

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

pkg/limayaml/validate_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,30 @@ func TestValidateParamIsUsed(t *testing.T) {
5050
//
5151
assert.NilError(t, err)
5252
}
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+
}
5379
}

0 commit comments

Comments
 (0)