MCPcopy
hub / github.com/helm/helm / TestValidateValuesFile

Function TestValidateValuesFile

pkg/chart/v2/lint/rules/values_test.go:130–174  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

128}
129
130func TestValidateValuesFile(t *testing.T) {
131 tests := []struct {
132 name string
133 yaml string
134 overrides map[string]any
135 errorMessage string
136 }{
137 {
138 name: "value added",
139 yaml: "username: admin",
140 overrides: map[string]any{"password": "swordfish"},
141 },
142 {
143 name: "value not overridden",
144 yaml: "username: admin\npassword:",
145 overrides: map[string]any{"username": "anotherUser"},
146 errorMessage: "- at '/password': got null, want string",
147 },
148 {
149 name: "value overridden",
150 yaml: "username: admin\npassword:",
151 overrides: map[string]any{"username": "anotherUser", "password": "swordfish"},
152 },
153 }
154
155 for _, tt := range tests {
156 t.Run(tt.name, func(t *testing.T) {
157 tmpdir := ensure.TempFile(t, "values.yaml", []byte(tt.yaml))
158 createTestingSchema(t, tmpdir)
159
160 valfile := filepath.Join(tmpdir, "values.yaml")
161
162 err := validateValuesFile(valfile, tt.overrides, false)
163
164 switch {
165 case err != nil && tt.errorMessage == "":
166 t.Errorf("Failed validation with %s", err)
167 case err == nil && tt.errorMessage != "":
168 t.Error("expected values file to fail parsing")
169 case err != nil && tt.errorMessage != "":
170 assert.Contains(t, err.Error(), tt.errorMessage, "Failed with unexpected error")
171 }
172 })
173 }
174}
175
176func createTestingSchema(t *testing.T, dir string) string {
177 t.Helper()

Callers

nothing calls this directly

Calls 6

TempFileFunction · 0.92
ContainsMethod · 0.80
createTestingSchemaFunction · 0.70
validateValuesFileFunction · 0.70
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…