runMigrationTests runs migration tests with a unified approach
(t *testing.T, targetVersion int, outputDir string)
| 59 | |
| 60 | // runMigrationTests runs migration tests with a unified approach |
| 61 | func runMigrationTests(t *testing.T, targetVersion int, outputDir string) { |
| 62 | files, err := os.ReadDir(INPUT_DIR) |
| 63 | require.NoError(t, err) |
| 64 | |
| 65 | for _, f := range files { |
| 66 | if f.IsDir() { |
| 67 | continue |
| 68 | } |
| 69 | |
| 70 | // Validate filename format |
| 71 | if !strings.HasPrefix(f.Name(), "v") || !strings.HasSuffix(f.Name(), ".json") { |
| 72 | t.Fatalf("input filename must use v{N}.{name}.json format, got: %s", f.Name()) |
| 73 | } |
| 74 | |
| 75 | versionStr := strings.TrimPrefix(f.Name(), "v") |
| 76 | dotIndex := strings.Index(versionStr, ".") |
| 77 | if dotIndex == -1 { |
| 78 | t.Fatalf("input filename must use v{N}.{name}.json format, got: %s", f.Name()) |
| 79 | } |
| 80 | |
| 81 | filenameTargetVersion, err := strconv.Atoi(versionStr[:dotIndex]) |
| 82 | require.NoError(t, err, "failed to parse version from filename: %s", f.Name()) |
| 83 | |
| 84 | // Load a fresh copy of the dashboard for this test (ensures no object sharing) |
| 85 | inputDash := loadDashboard(t, filepath.Join(INPUT_DIR, f.Name())) |
| 86 | inputVersion := getSchemaVersion(t, inputDash) |
| 87 | |
| 88 | // Validate naming convention: filename version should be the tested version, schemaVersion should be target - 1 |
| 89 | expectedSchemaVersion := filenameTargetVersion - 1 |
| 90 | require.Equal(t, expectedSchemaVersion, inputVersion, |
| 91 | "naming convention violation for %s: filename suggests target v%d, but schemaVersion is %d (should be %d)", |
| 92 | f.Name(), filenameTargetVersion, inputVersion, expectedSchemaVersion) |
| 93 | |
| 94 | testName := fmt.Sprintf("%s v%d to v%d", f.Name(), inputVersion, targetVersion) |
| 95 | t.Run(testName, func(t *testing.T) { |
| 96 | testMigrationUnified(t, inputDash, f.Name(), inputVersion, targetVersion, outputDir) |
| 97 | }) |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | // runSingleVersionMigrationTests runs single version migration tests |
| 102 | func runSingleVersionMigrationTests(t *testing.T, outputDir string) { |
no test coverage detected