(t *testing.T)
| 128 | } |
| 129 | |
| 130 | func 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 | |
| 176 | func createTestingSchema(t *testing.T, dir string) string { |
| 177 | t.Helper() |
nothing calls this directly
no test coverage detected
searching dependent graphs…