-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmigrate_sqlite_test.go
More file actions
82 lines (69 loc) · 1.99 KB
/
migrate_sqlite_test.go
File metadata and controls
82 lines (69 loc) · 1.99 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package migrate_test
import (
"context"
"database/sql"
"embed"
"testing"
_ "modernc.org/sqlite"
"github.com/ladzaretti/migrate"
"github.com/ladzaretti/migrate/migratetest"
)
var (
//go:embed testdata/sqlite/migrations
embedSQLiteFS embed.FS
embeddedSQLiteMigrations = migrate.EmbeddedMigrations{
FS: embedSQLiteFS,
Path: "testdata/sqlite/migrations",
}
)
// createSQLiteDB is a testing helper that creates an in-memory sqlite
// database connection.
func createSQLiteDB(_ context.Context, t *testing.T) *sql.DB {
t.Helper()
db, err := sql.Open("sqlite", ":memory:")
if err != nil {
t.Fatalf("Failed to open database: %v", err)
}
t.Cleanup(func() { _ = db.Close() })
return db
}
func TestMigrateWithSQLite(t *testing.T) {
rawMigrations := []string{
`CREATE TABLE
IF NOT EXISTS testing_migration_1 (
id INTEGER PRIMARY KEY,
another_id INTEGER,
something_else TEXT
);
`,
`CREATE TABLE
IF NOT EXISTS testing_migration_2 (
id INTEGER PRIMARY KEY,
another_id INTEGER,
something_else TEXT
);
`,
}
suite, err := newTestSuite(testSuiteConfig{
dbHelper: createSQLiteDB,
dialect: migrate.SQLiteDialect{},
embeddedMigrations: embeddedSQLiteMigrations,
rawMigrations: rawMigrations,
})
if err != nil {
t.Fatalf("create test suite: %v", err)
}
t.Run("TestDialect", func(t *testing.T) {
if err := migratetest.TestDialect(t.Context(), suite.dbHelper(t.Context(), t), migrate.SQLiteDialect{}); err != nil {
t.Fatalf("TestDialect: %v", err)
}
})
t.Run("ApplyStringMigrations", suite.applyStringMigrations)
t.Run("ApplyEmbeddedMigrations", suite.applyEmbeddedMigrations)
t.Run("ApplyWithTxDisabled", suite.applyWithTxDisabled)
t.Run("ApplyWithNoChecksumValidation", suite.applyWithNoChecksumValidation)
t.Run("ApplyWithFilter", suite.applyWithFilter)
t.Run("ReapplyAll", suite.reapplyAll)
t.Run("RollsBackOnSQLError", suite.rollsBackOnSQLError)
t.Run("RollsBackOnValidationError", suite.rollsBackOnValidationError)
}