-
Notifications
You must be signed in to change notification settings - Fork 3
/
load_test.go
85 lines (65 loc) · 1.66 KB
/
load_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
75
76
77
78
79
80
81
82
83
84
85
package dbump_test
import (
"embed"
"testing"
"github.com/cristalhq/dbump"
)
func TestDiskLoader(t *testing.T) {
loader := dbump.NewDiskLoader("./testdata")
migs, err := loader.Load()
failIfErr(t, err)
want := testdataMigrations
mustEqual(t, len(migs), len(want))
for i := range migs {
mustEqual(t, migs[i], want[i])
}
}
func TestDiskLoaderSubdir(t *testing.T) {
loader := dbump.NewDiskLoader("./testdata/subdir")
migs, err := loader.Load()
failIfErr(t, err)
want := testdataMigrations
mustEqual(t, len(migs), len(want))
for i := range migs {
mustEqual(t, migs[i], want[i])
}
}
//go:embed testdata
var testdata embed.FS
func TestEmbedLoader(t *testing.T) {
loader := dbump.NewFileSysLoader(testdata, "testdata")
migs, err := loader.Load()
failIfErr(t, err)
want := testdataMigrations
mustEqual(t, len(migs), len(want))
for i := range migs {
mustEqual(t, migs[i], want[i])
}
}
func TestEmbedLoaderSubdir(t *testing.T) {
loader := dbump.NewFileSysLoader(testdata, "testdata/subdir")
migs, err := loader.Load()
failIfErr(t, err)
want := testdataMigrations
mustEqual(t, len(migs), len(want))
for i := range migs {
mustEqual(t, migs[i], want[i])
}
}
func TestSliceLoader(t *testing.T) {
size := len(testdataMigrations)
loader := dbump.NewSliceLoader(testdataMigrations[:size-1])
loader.AddMigration(testdataMigrations[size-1])
migs, err := loader.Load()
failIfErr(t, err)
want := testdataMigrations
mustEqual(t, len(migs), len(want))
for i := range migs {
mustEqual(t, migs[i], want[i])
}
}
func TestBadFormat(t *testing.T) {
loader := dbump.NewFileSysLoader(testdata, "testdata/bad")
_, err := loader.Load()
failIfOk(t, err)
}