-
Notifications
You must be signed in to change notification settings - Fork 4
/
executor_test.go
74 lines (53 loc) · 1.55 KB
/
executor_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
64
65
66
67
68
69
70
71
72
73
74
package gloat
import (
"io/ioutil"
"path/filepath"
"testing"
"github.com/gsamokovarov/assert"
)
func TestSQLExecutor_Up(t *testing.T) {
td := filepath.Join(dbSrc, "20170329154959_introduce_domain_model")
exe := NewSQLExecutor(db)
migration, err := MigrationFromBytes(td, ioutil.ReadFile)
assert.Nil(t, err)
cleanState(func() {
err := exe.Up(migration, new(testingStore))
assert.Nil(t, err)
_, err = db.Exec(`SELECT id FROM users LIMIT 1`)
assert.Nil(t, err)
})
}
func TestSQLExecutor_Up_Broken(t *testing.T) {
td := filepath.Join(dbSrc, "20180920181906_migration_with_an_error")
exe := NewSQLExecutor(db)
migration, err := MigrationFromBytes(td, ioutil.ReadFile)
assert.Nil(t, err)
cleanState(func() {
err := exe.Up(migration, new(testingStore))
assert.Error(t, err)
})
}
func TestSQLExecutor_Down(t *testing.T) {
td := filepath.Join(dbSrc, "20170329154959_introduce_domain_model")
exe := NewSQLExecutor(db)
migration, err := MigrationFromBytes(td, ioutil.ReadFile)
assert.Nil(t, err)
cleanState(func() {
exe.Up(migration, new(testingStore))
assert.Nil(t, err)
err = exe.Down(migration, new(testingStore))
assert.Nil(t, err)
_, err := db.Exec(`SELECT id FROM users LIMIT 1`)
assert.NotNil(t, err)
})
}
func TestSQLExecutor_Down_Broken(t *testing.T) {
td := filepath.Join(dbSrc, "20180920181906_migration_with_an_error")
exe := NewSQLExecutor(db)
migration, err := MigrationFromBytes(td, ioutil.ReadFile)
assert.Nil(t, err)
cleanState(func() {
err := exe.Down(migration, new(testingStore))
assert.Error(t, err)
})
}