From efb324070827bd1fe713b93f80c601551d246579 Mon Sep 17 00:00:00 2001 From: xengineering Date: Sun, 31 May 2026 21:20:48 +0200 Subject: Add migration execution This adds the execution of the embedded migrations and adds a suitable unit test. --- database_test.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'database_test.go') diff --git a/database_test.go b/database_test.go index fce0c02..b412af0 100644 --- a/database_test.go +++ b/database_test.go @@ -3,7 +3,6 @@ package main import ( "fmt" "os" - "path/filepath" "strings" "testing" ) @@ -24,8 +23,7 @@ func TestMigrationNumber(t *testing.T) { func TestMigrationContent(t *testing.T) { for i, migration := range migrations { - name := fmt.Sprintf(migrationFilePattern, i+1) - path := filepath.Join(migrationDir, name) + path := migrationPath(i) expectation := fmt.Sprintf("PRAGMA user_version = %d;", i+1) if !strings.HasPrefix(migration, expectation) { @@ -42,3 +40,17 @@ func TestMigrationContent(t *testing.T) { } } } + +func TestMigrations(t *testing.T) { + db, _ := emptyDB(t) + + for i := range migrations { + path := migrationPath(i) + t.Logf("Test execution of %s", path) + + err := Migrate(db, i) + if err != nil { + t.Fatalf("Failed to execute migration %s: %v", path, err) + } + } +} -- cgit v1.3.1