(dir string, t *testing.T)
| 45 | } |
| 46 | |
| 47 | func testLoad(dir string, t *testing.T) { |
| 48 | wd, err := os.Getwd() |
| 49 | if err != nil { |
| 50 | t.Error(err) |
| 51 | } |
| 52 | |
| 53 | err = os.Chdir(filepath.Join(wd, "testdata", dir)) |
| 54 | if err != nil { |
| 55 | t.Error(err) |
| 56 | } |
| 57 | defer func() { |
| 58 | err := os.Chdir(wd) |
| 59 | if err != nil { |
| 60 | t.Error(err) |
| 61 | } |
| 62 | }() |
| 63 | |
| 64 | dockerComposePath := GetDockerComposePath() |
| 65 | dockerCompose, err := LoadDockerComposeProject(dockerComposePath) |
| 66 | if err != nil { |
| 67 | t.Errorf("Unexpected error occurred loading the docker-compose.yaml: %s", err.Error()) |
| 68 | } |
| 69 | loader := NewComposeManager(dockerCompose) |
| 70 | |
| 71 | actualError := loader.Load(log.Discard) |
| 72 | |
| 73 | if actualError != nil { |
| 74 | expectedError, err := os.ReadFile("error.txt") |
| 75 | if err != nil { |
| 76 | t.Errorf("Unexpected error occurred loading the docker-compose.yaml: %s", err.Error()) |
| 77 | } |
| 78 | |
| 79 | assert.Equal(t, string(expectedError), actualError.Error(), "Expected error:\n%s\nbut got:\n%s\n in testCase %s", string(expectedError), actualError.Error(), dir) |
| 80 | } |
| 81 | |
| 82 | for path, actualConfig := range loader.Configs() { |
| 83 | data, err := os.ReadFile(path) |
| 84 | if err != nil { |
| 85 | t.Errorf("Please create the expected DevSpace configuration by creating a %s in the testdata/%s folder", path, dir) |
| 86 | } |
| 87 | |
| 88 | expectedConfig := &latest.Config{} |
| 89 | err = yaml.Unmarshal(data, expectedConfig) |
| 90 | if err != nil { |
| 91 | t.Errorf("Error unmarshaling the expected configuration: %s", err.Error()) |
| 92 | } |
| 93 | |
| 94 | assert.Check( |
| 95 | t, |
| 96 | cmp.DeepEqual(expectedConfig, actualConfig), |
| 97 | "configs did not match in test case %s", |
| 98 | dir, |
| 99 | ) |
| 100 | } |
| 101 | |
| 102 | } |
no test coverage detected