1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
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,
)
}
}
}
|