Add migration that creates the Sonoma+ built-in label

This commit is contained in:
Martin Angers 2024-04-03 11:50:42 -04:00
parent d2fd3694b8
commit 81556aa43a
2 changed files with 19 additions and 10 deletions

View file

@ -22,7 +22,7 @@ func Up_20240403104633(tx *sql.Tx) error {
platform,
label_type,
label_membership_type
) VALUES (?, ?, ?, ?, ?)
) VALUES (?, ?, ?, ?, ?, ?)
`
const labelName = "macOS 14+ (Sonoma+)"

View file

@ -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+)")
}