package main import ( "fmt" "os" "path/filepath" "strings" "testing" ) func TestMigrationNumber(t *testing.T) { n := len(migrations) entries, err := os.ReadDir(migrationDir) if err != nil { t.Fatalf("Failed to determine number of migration files: %v", err) } expectation := len(entries) if n != expectation { t.Fatalf("Expected %d migration files but got %d.", expectation, n) } } func TestMigrationContent(t *testing.T) { for i, migration := range migrations { name := fmt.Sprintf(migrationFilePattern, i+1) path := filepath.Join(migrationDir, name) expectation := fmt.Sprintf("PRAGMA user_version = %d;", i+1) if !strings.HasPrefix(migration, expectation) { t.Fatalf("Expected '%s' at start of '%s'.", expectation, path) } n := strings.Count(migration, `user_version`) if n != 1 { t.Fatalf( "'user_version' was mentioned more than once in %s. "+ "This is likely not intended.", path, ) } } }