(testCase loadTestCase, t *testing.T)
| 59 | } |
| 60 | |
| 61 | func testLoad(testCase loadTestCase, t *testing.T) { |
| 62 | defer func() { |
| 63 | for _, path := range []string{".devspace/cache.yaml"} { |
| 64 | os.Remove(path) |
| 65 | } |
| 66 | }() |
| 67 | for path, data := range testCase.files { |
| 68 | dataAsYaml, err := yaml.Marshal(data) |
| 69 | assert.NilError(t, err, "Error parsing data of file %s in testCase %s", path, testCase.name) |
| 70 | err = fsutil.WriteToFile([]byte(dataAsYaml), path) |
| 71 | assert.NilError(t, err, "Error writing file %s in testCase %s", path, testCase.name) |
| 72 | } |
| 73 | |
| 74 | loader := NewCacheLoader() |
| 75 | |
| 76 | config, err := loader.Load(constants.DefaultConfigPath) |
| 77 | |
| 78 | if testCase.expectedErr == "" { |
| 79 | assert.NilError(t, err, "Error in testCase %s", testCase.name) |
| 80 | } else { |
| 81 | assert.Error(t, err, testCase.expectedErr, "Wrong or no error in testCase %s", testCase.name) |
| 82 | } |
| 83 | |
| 84 | configAsYaml, err := yaml.Marshal(config) |
| 85 | assert.NilError(t, err, "Error parsing config in testCase %s", testCase.name) |
| 86 | expectedAsYaml, err := yaml.Marshal(testCase.expectedConfig) |
| 87 | assert.NilError(t, err, "Error parsing exception to yaml in testCase %s", testCase.name) |
| 88 | assert.Equal(t, string(configAsYaml), string(expectedAsYaml), "Unexpected config in testCase %s", testCase.name) |
| 89 | } |
| 90 | |
| 91 | type saveTestCase struct { |
| 92 | name string |
no test coverage detected