MCPcopy
hub / github.com/grafana/grafana / runMigrationTests

Function runMigrationTests

apps/dashboard/pkg/migration/migrate_test.go:61–99  ·  view source on GitHub ↗

runMigrationTests runs migration tests with a unified approach

(t *testing.T, targetVersion int, outputDir string)

Source from the content-addressed store, hash-verified

59
60// runMigrationTests runs migration tests with a unified approach
61func 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
102func runSingleVersionMigrationTests(t *testing.T, outputDir string) {

Callers 1

TestMigrateFunction · 0.70

Calls 11

testMigrationUnifiedFunction · 0.85
loadDashboardFunction · 0.70
getSchemaVersionFunction · 0.70
ReadDirMethod · 0.65
NameMethod · 0.65
FatalfMethod · 0.65
IndexMethod · 0.65
RunMethod · 0.65
IsDirMethod · 0.45
JoinMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected