From d1cff535d289772d4b6302c5733c3754aa4e9649 Mon Sep 17 00:00:00 2001 From: Ivan Ortega Alba Date: Wed, 6 Aug 2025 21:50:21 +0200 Subject: [PATCH] Schema V2: Snapshot testing for migrations should fail when output doesn't match (#109278) * Schema v2: Snapshot testing for migration fails when doesn't match * Update snapshot --- apps/dashboard/pkg/migration/migrate_test.go | 8 +++++--- .../output/v28.singlestat_and_variable_properties.json | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/apps/dashboard/pkg/migration/migrate_test.go b/apps/dashboard/pkg/migration/migrate_test.go index d2b0597b840..fbcfdd0f754 100644 --- a/apps/dashboard/pkg/migration/migrate_test.go +++ b/apps/dashboard/pkg/migration/migrate_test.go @@ -74,9 +74,11 @@ func testMigration(t *testing.T, dash map[string]interface{}, inputFileName stri outBytes, err := json.MarshalIndent(dash, "", " ") require.NoError(t, err, "failed to marshal migrated dashboard") - // Overwrite the output file with the new output - err = os.WriteFile(outPath, outBytes, 0644) - require.NoError(t, err, "failed to write output file", outPath) + if _, err := os.Stat(outPath); os.IsNotExist(err) { + err = os.WriteFile(outPath, outBytes, 0644) + require.NoError(t, err, "failed to write new output file", outPath) + return + } // We can ignore gosec G304 here since it's a test // nolint:gosec diff --git a/apps/dashboard/pkg/migration/testdata/output/v28.singlestat_and_variable_properties.json b/apps/dashboard/pkg/migration/testdata/output/v28.singlestat_and_variable_properties.json index a355e37c7f7..e3a659a383e 100644 --- a/apps/dashboard/pkg/migration/testdata/output/v28.singlestat_and_variable_properties.json +++ b/apps/dashboard/pkg/migration/testdata/output/v28.singlestat_and_variable_properties.json @@ -148,7 +148,7 @@ { "options": { "20": { - "color": null, + "color": "orange", "text": "test" } }, @@ -157,7 +157,7 @@ { "options": { "30": { - "color": null, + "color": "orange", "text": "test1" } },