-
-
Notifications
You must be signed in to change notification settings - Fork 243
/
migration_box_test.go
67 lines (56 loc) · 1.75 KB
/
migration_box_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
package pop
import (
"os"
"testing"
"github.com/gobuffalo/pop/v6/logging"
"github.com/stretchr/testify/require"
)
type logEntry struct {
lvl logging.Level
s string
args []interface{}
}
func setNewTestLogger() *[]logEntry {
var logs []logEntry
log = func(lvl logging.Level, s string, args ...interface{}) {
logs = append(logs, logEntry{lvl, s, args})
}
return &logs
}
func Test_MigrationBox(t *testing.T) {
if PDB == nil {
t.Skip("skipping integration tests")
}
t.Run("finds testdata", func(t *testing.T) {
r := require.New(t)
b, err := NewMigrationBox(os.DirFS("testdata/migrations/multiple"), PDB)
r.NoError(err)
r.Equal(4, len(b.UpMigrations.Migrations))
r.Equal("mysql", b.UpMigrations.Migrations[0].DBType)
r.Equal("postgres", b.UpMigrations.Migrations[1].DBType)
r.Equal("sqlite3", b.UpMigrations.Migrations[2].DBType)
r.Equal("all", b.UpMigrations.Migrations[3].DBType)
})
t.Run("ignores clutter files", func(t *testing.T) {
logs := setNewTestLogger()
r := require.New(t)
b, err := NewMigrationBox(os.DirFS("testdata/migrations/cluttered"), PDB)
r.NoError(err)
r.Equal(1, len(b.UpMigrations.Migrations))
r.Equal(1, len(*logs))
r.Equal(logging.Warn, (*logs)[0].lvl)
r.Contains((*logs)[0].s, "ignoring file")
r.Equal([]interface{}{"clutter.txt"}, (*logs)[0].args)
})
t.Run("ignores unsupported files", func(t *testing.T) {
logs := setNewTestLogger()
r := require.New(t)
b, err := NewMigrationBox(os.DirFS("testdata/migrations/unsupported_dialect"), PDB)
r.NoError(err)
r.Equal(0, len(b.UpMigrations.Migrations))
r.Equal(1, len(*logs))
r.Equal(logging.Warn, (*logs)[0].lvl)
r.Contains((*logs)[0].s, "ignoring migration")
r.Equal([]interface{}{"unsupported dialect unsupported"}, (*logs)[0].args)
})
}