|
|
@ -104,7 +104,7 @@ func TestValidateValuesFileSchemaFailure(t *testing.T) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestValidateValuesFileSchemaOverrides(t *testing.T) {
|
|
|
|
func TestValidateValuesFileSchemaOverrides(t *testing.T) {
|
|
|
|
yaml := "username: admin\npassword:"
|
|
|
|
yaml := "username: admin"
|
|
|
|
overrides := map[string]interface{}{
|
|
|
|
overrides := map[string]interface{}{
|
|
|
|
"password": "swordfish",
|
|
|
|
"password": "swordfish",
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -118,21 +118,51 @@ func TestValidateValuesFileSchemaOverrides(t *testing.T) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestValidateValuesFileSchemaOverridesFailure(t *testing.T) {
|
|
|
|
func TestValidateValuesFile(t *testing.T) {
|
|
|
|
yaml := "username: admin\npassword:"
|
|
|
|
tests := []struct {
|
|
|
|
overrides := map[string]interface{}{
|
|
|
|
name string
|
|
|
|
"username": "anotherUser",
|
|
|
|
yaml string
|
|
|
|
|
|
|
|
overrides map[string]interface{}
|
|
|
|
|
|
|
|
errorMessage string
|
|
|
|
|
|
|
|
}{
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
name: "value added",
|
|
|
|
|
|
|
|
yaml: "username: admin",
|
|
|
|
|
|
|
|
overrides: map[string]interface{}{"password": "swordfish"},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
name: "value not overridden",
|
|
|
|
|
|
|
|
yaml: "username: admin\npassword:",
|
|
|
|
|
|
|
|
overrides: map[string]interface{}{"username": "anotherUser"},
|
|
|
|
|
|
|
|
errorMessage: "Expected: string, given: null",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
name: "value overridden",
|
|
|
|
|
|
|
|
yaml: "username: admin\npassword:",
|
|
|
|
|
|
|
|
overrides: map[string]interface{}{"username": "anotherUser", "password": "swordfish"},
|
|
|
|
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tmpdir := ensure.TempFile(t, "values.yaml", []byte(yaml))
|
|
|
|
|
|
|
|
defer os.RemoveAll(tmpdir)
|
|
|
|
|
|
|
|
createTestingSchema(t, tmpdir)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
valfile := filepath.Join(tmpdir, "values.yaml")
|
|
|
|
for _, tt := range tests {
|
|
|
|
err := validateValuesFile(valfile, overrides)
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
if err == nil {
|
|
|
|
tmpdir := ensure.TempFile(t, "values.yaml", []byte(tt.yaml))
|
|
|
|
t.Fatalf("expected values file to fail parsing")
|
|
|
|
defer os.RemoveAll(tmpdir)
|
|
|
|
|
|
|
|
createTestingSchema(t, tmpdir)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
valfile := filepath.Join(tmpdir, "values.yaml")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
err := validateValuesFile(valfile, tt.overrides)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch {
|
|
|
|
|
|
|
|
case err != nil && tt.errorMessage == "":
|
|
|
|
|
|
|
|
t.Errorf("Failed validation with %s", err)
|
|
|
|
|
|
|
|
case err == nil && tt.errorMessage != "":
|
|
|
|
|
|
|
|
t.Error("expected values file to fail parsing")
|
|
|
|
|
|
|
|
case err != nil && tt.errorMessage != "":
|
|
|
|
|
|
|
|
assert.Contains(t, err.Error(), tt.errorMessage, "Failed with unexpected error")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert.Contains(t, err.Error(), "Expected: string, given: null", "Null value for password should be caught by schema")
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func createTestingSchema(t *testing.T, dir string) string {
|
|
|
|
func createTestingSchema(t *testing.T, dir string) string {
|
|
|
|