(testCase setDevSpaceRootTestCase, t *testing.T)
| 327 | } |
| 328 | |
| 329 | func testSetDevSpaceRoot(testCase setDevSpaceRootTestCase, t *testing.T) { |
| 330 | wdBackup, err := os.Getwd() |
| 331 | assert.NilError(t, err, "Error getting current working directory") |
| 332 | defer func() { |
| 333 | _ = os.Chdir(wdBackup) |
| 334 | for _, path := range []string{"devspace.yaml", "custom.yaml"} { |
| 335 | _ = os.Remove(path) |
| 336 | } |
| 337 | }() |
| 338 | for path, data := range testCase.files { |
| 339 | dataAsYaml, err := yaml.Marshal(data) |
| 340 | assert.NilError(t, err, "Error parsing data of file %s in testCase %s", path, testCase.name) |
| 341 | err = fsutil.WriteToFile([]byte(dataAsYaml), path) |
| 342 | assert.NilError(t, err, "Error writing file %s in testCase %s", path, testCase.name) |
| 343 | } |
| 344 | if testCase.startDir != "" { |
| 345 | _ = os.Mkdir(testCase.startDir, os.ModePerm) |
| 346 | _ = os.Chdir(testCase.startDir) |
| 347 | } |
| 348 | |
| 349 | loader := &configLoader{ |
| 350 | absConfigPath: testCase.configPath, |
| 351 | } |
| 352 | |
| 353 | exists, err := loader.SetDevSpaceRoot(log.Discard) |
| 354 | |
| 355 | if testCase.expectedErr == "" { |
| 356 | assert.NilError(t, err, "Error in testCase %s", testCase.name) |
| 357 | } else { |
| 358 | assert.Error(t, err, testCase.expectedErr, "Wrong or no error in testCase %s", testCase.name) |
| 359 | } |
| 360 | assert.Equal(t, exists, testCase.expectedExists, "Unexpected existence answer in testCase %s", testCase.name) |
| 361 | |
| 362 | wd, err := os.Getwd() |
| 363 | if runtime.GOOS == "darwin" { |
| 364 | wd = strings.ReplaceAll(wd, "/private", "") |
| 365 | } |
| 366 | assert.NilError(t, err, "Error getting wd in testCase %s", testCase.name) |
| 367 | assert.Equal(t, wd, testCase.expectedWorkDir, "Unexpected work dir in testCase %s", testCase.name) |
| 368 | |
| 369 | assert.Equal(t, loader.absConfigPath, testCase.expectedConfigPath, "Unexpected configPath in testCase %s", testCase.name) |
| 370 | } |
| 371 | |
| 372 | type getProfilesTestCase struct { |
| 373 | name string |
no test coverage detected