forked from golang-migrate/migrate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ql_test.go
63 lines (55 loc) · 1.19 KB
/
ql_test.go
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
package ql
import (
"database/sql"
"fmt"
"path/filepath"
"testing"
"github.com/golang-migrate/migrate/v4"
dt "github.com/golang-migrate/migrate/v4/database/testing"
_ "github.com/golang-migrate/migrate/v4/source/file"
_ "modernc.org/ql/driver"
)
func Test(t *testing.T) {
dir := t.TempDir()
t.Logf("DB path : %s\n", filepath.Join(dir, "ql.db"))
p := &Ql{}
addr := fmt.Sprintf("ql://%s", filepath.Join(dir, "ql.db"))
d, err := p.Open(addr)
if err != nil {
t.Fatal(err)
}
db, err := sql.Open("ql", filepath.Join(dir, "ql.db"))
if err != nil {
return
}
defer func() {
if err := db.Close(); err != nil {
return
}
}()
dt.Test(t, d, []byte("CREATE TABLE t (Qty int, Name string);"))
}
func TestMigrate(t *testing.T) {
dir := t.TempDir()
t.Logf("DB path : %s\n", filepath.Join(dir, "ql.db"))
db, err := sql.Open("ql", filepath.Join(dir, "ql.db"))
if err != nil {
return
}
defer func() {
if err := db.Close(); err != nil {
return
}
}()
driver, err := WithInstance(db, &Config{})
if err != nil {
t.Fatal(err)
}
m, err := migrate.NewWithDatabaseInstance(
"file://./examples/migrations",
"ql", driver)
if err != nil {
t.Fatal(err)
}
dt.TestMigrate(t, m)
}