From 81556aa43a5393330b2e2c9abeabdb4ddf35395f Mon Sep 17 00:00:00 2001 From: Martin Angers Date: Wed, 3 Apr 2024 11:50:42 -0400 Subject: [PATCH] Add migration that creates the Sonoma+ built-in label --- ...403104633_CreateMacOSSonomaBuiltinLabel.go | 2 +- ...4633_CreateMacOSSonomaBuiltinLabel_test.go | 27 ++++++++++++------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/server/datastore/mysql/migrations/tables/20240403104633_CreateMacOSSonomaBuiltinLabel.go b/server/datastore/mysql/migrations/tables/20240403104633_CreateMacOSSonomaBuiltinLabel.go index 5a38646f8c..9b2826c250 100644 --- a/server/datastore/mysql/migrations/tables/20240403104633_CreateMacOSSonomaBuiltinLabel.go +++ b/server/datastore/mysql/migrations/tables/20240403104633_CreateMacOSSonomaBuiltinLabel.go @@ -22,7 +22,7 @@ func Up_20240403104633(tx *sql.Tx) error { platform, label_type, label_membership_type - ) VALUES (?, ?, ?, ?, ?) + ) VALUES (?, ?, ?, ?, ?, ?) ` const labelName = "macOS 14+ (Sonoma+)" diff --git a/server/datastore/mysql/migrations/tables/20240403104633_CreateMacOSSonomaBuiltinLabel_test.go b/server/datastore/mysql/migrations/tables/20240403104633_CreateMacOSSonomaBuiltinLabel_test.go index 478a22327a..212b8c1cca 100644 --- a/server/datastore/mysql/migrations/tables/20240403104633_CreateMacOSSonomaBuiltinLabel_test.go +++ b/server/datastore/mysql/migrations/tables/20240403104633_CreateMacOSSonomaBuiltinLabel_test.go @@ -1,20 +1,29 @@ package tables -import "testing" +import ( + "testing" + + "github.com/stretchr/testify/require" +) func TestUp_20240403104633(t *testing.T) { db := applyUpToPrev(t) - // - // Insert data to test the migration - // - // ... + execNoErr(t, db, "INSERT INTO labels (name, query, platform) VALUES (?,?,?)", "NOT macOS 14+ (Sonoma+)", "SELECT 1", "windows") // Apply current migration. + // + // The case where the name already exists could not be tested because + // applying the next migration fails drastically when the migration returns + // an error (it calls log.Fatal) and the test cannot continue after the + // error, but it has been tested manually. applyNext(t, db) - // - // Check data, insert new entries, e.g. to verify migration is safe. - // - // ... + var names []string + err := db.Select(&names, `SELECT name FROM labels`) + require.NoError(t, err) + + require.GreaterOrEqual(t, len(names), 2) + require.Contains(t, names, "macOS 14+ (Sonoma+)") + require.Contains(t, names, "NOT macOS 14+ (Sonoma+)") }