| 214 | } |
| 215 | |
| 216 | func testLoad(testCase *loadTestCase, t *testing.T) { |
| 217 | defer func() { |
| 218 | for _, path := range []string{".devspace/generated.yaml", "devspace.yaml", "custom.yaml"} { |
| 219 | os.Remove(path) |
| 220 | } |
| 221 | }() |
| 222 | for path, data := range testCase.files { |
| 223 | dataAsYaml, err := yaml.Marshal(data) |
| 224 | assert.NilError(t, err, "Error parsing data of file %s in testCase %s", path, testCase.name) |
| 225 | err = fsutil.WriteToFile([]byte(dataAsYaml), path) |
| 226 | assert.NilError(t, err, "Error writing file %s in testCase %s", path, testCase.name) |
| 227 | } |
| 228 | |
| 229 | loader := &configLoader{ |
| 230 | absConfigPath: testCase.configPath, |
| 231 | } |
| 232 | |
| 233 | var config config2.Config |
| 234 | var err error |
| 235 | config, err = loader.Load(context.TODO(), nil, &testCase.options, log.Discard) |
| 236 | if testCase.expectedErr == "" { |
| 237 | assert.NilError(t, err, "Error in testCase %s", testCase.name) |
| 238 | } else { |
| 239 | assert.Error(t, err, testCase.expectedErr, "Wrong or no error in testCase %s", testCase.name) |
| 240 | } |
| 241 | |
| 242 | configAsYaml, err := yaml.Marshal(config.Config()) |
| 243 | assert.NilError(t, err, "Error parsing config in testCase %s", testCase.name) |
| 244 | expectedAsYaml, err := yaml.Marshal(testCase.expectedConfig) |
| 245 | assert.NilError(t, err, "Error parsing exception to yaml in testCase %s", testCase.name) |
| 246 | assert.Equal(t, string(configAsYaml), string(expectedAsYaml), "Unexpected config in testCase %s", testCase.name) |
| 247 | } |
| 248 | |
| 249 | type setDevSpaceRootTestCase struct { |
| 250 | name string |