(t *testing.T, origDir, resultDir, goldenDir string)
| 175 | } |
| 176 | |
| 177 | func checkGoldenDir(t *testing.T, origDir, resultDir, goldenDir string) { |
| 178 | t.Helper() |
| 179 | golden := true |
| 180 | t.Cleanup(func() { |
| 181 | t.Helper() |
| 182 | if !golden { |
| 183 | t.Log("To regenerate golden files run `UPDATE_GOLDEN=1 script/test.sh`") |
| 184 | } |
| 185 | }) |
| 186 | updateGoldenDir(t, origDir, resultDir, goldenDir) |
| 187 | checked := map[string]bool{} |
| 188 | _, err := os.Stat(goldenDir) |
| 189 | if err == nil { |
| 190 | assertNilError(t, filepath.Walk(goldenDir, func(wantPath string, info fs.FileInfo, err error) error { |
| 191 | relPath := mustRel(t, goldenDir, wantPath) |
| 192 | if err != nil || info.IsDir() { |
| 193 | return err |
| 194 | } |
| 195 | if !assertEqualFiles(t, wantPath, filepath.Join(resultDir, relPath)) { |
| 196 | golden = false |
| 197 | } |
| 198 | checked[relPath] = true |
| 199 | return nil |
| 200 | })) |
| 201 | } |
| 202 | assertNilError(t, filepath.Walk(origDir, func(wantPath string, info fs.FileInfo, err error) error { |
| 203 | relPath := mustRel(t, origDir, wantPath) |
| 204 | if err != nil || info.IsDir() || checked[relPath] { |
| 205 | return err |
| 206 | } |
| 207 | if !assertEqualFiles(t, wantPath, filepath.Join(resultDir, relPath)) { |
| 208 | golden = false |
| 209 | } |
| 210 | checked[relPath] = true |
| 211 | return nil |
| 212 | })) |
| 213 | assertNilError(t, filepath.Walk(resultDir, func(resultPath string, info fs.FileInfo, err error) error { |
| 214 | relPath := mustRel(t, resultDir, resultPath) |
| 215 | if err != nil || info.IsDir() || checked[relPath] { |
| 216 | return err |
| 217 | } |
| 218 | golden = false |
| 219 | return fmt.Errorf("found unexpected file:\n%v", relPath) |
| 220 | })) |
| 221 | } |
| 222 | |
| 223 | func mustRel(t *testing.T, base, target string) string { |
| 224 | t.Helper() |
no test coverage detected
searching dependent graphs…