-
Notifications
You must be signed in to change notification settings - Fork 4
/
migration_test.go
56 lines (38 loc) · 1.18 KB
/
migration_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
package gloat
import (
"io/ioutil"
"testing"
"github.com/gsamokovarov/assert"
)
func TestMigrationReversible(t *testing.T) {
m := Migration{}
assert.False(t, m.Reversible())
m.DownSQL = []byte("DROP TABLE users;")
assert.True(t, m.Reversible())
}
func TestMigrationPersistable(t *testing.T) {
m := Migration{}
if m.Persistable() {
t.Fatalf("Expected %v to not be persistable", m)
}
m.Path = "migrations/0001_something"
assert.True(t, m.Persistable())
}
func TestMigrationFromPath(t *testing.T) {
expectedPath := "testdata/migrations/20170329154959_introduce_domain_model"
m, err := MigrationFromBytes(expectedPath, ioutil.ReadFile)
assert.Nil(t, err)
assert.Equal(t, 20170329154959, m.Version)
assert.Equal(t, expectedPath, m.Path)
}
func TestMigrationsExcept(t *testing.T) {
var migrations Migrations
expectedPath := "testdata/migrations/20170329154959_introduce_domain_model"
m, err := MigrationFromBytes(expectedPath, ioutil.ReadFile)
assert.Nil(t, err)
migrations = append(migrations, m)
exceptedMigrations := migrations.Except(nil)
assert.Nil(t, exceptedMigrations)
exceptedMigrations = migrations.Except(Migrations{m})
assert.Len(t, 0, exceptedMigrations)
}