-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmigrate_test.go
71 lines (51 loc) · 1.41 KB
/
migrate_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
package main
import (
"testing"
)
func TestMigrationMapSortUp(t *testing.T) {
mm := &MigrationMap{}
// insert in any order
mm.Append(20120000, "test")
mm.Append(20128000, "test")
mm.Append(20129000, "test")
mm.Append(20127000, "test")
mm.Sort(true) // sort Upwards
sorted := []int64{20120000, 20127000, 20128000, 20129000}
validateMigrationMapIsSorted(t, mm, sorted)
}
func TestMigrationMapSortDown(t *testing.T) {
mm := &MigrationMap{}
// insert in any order
mm.Append(20120000, "test")
mm.Append(20128000, "test")
mm.Append(20129000, "test")
mm.Append(20127000, "test")
mm.Sort(false) // sort Downwards
sorted := []int64{20129000, 20128000, 20127000, 20120000}
validateMigrationMapIsSorted(t, mm, sorted)
}
func validateMigrationMapIsSorted(t *testing.T, mm *MigrationMap, sorted []int64) {
for i, m := range mm.Migrations {
if sorted[i] != m.Version {
t.Error("incorrect sorted version")
}
var next, prev int64
if i == 0 {
prev = -1
next = mm.Migrations[i+1].Version
} else if i == len(mm.Migrations)-1 {
prev = mm.Migrations[i-1].Version
next = -1
} else {
prev = mm.Migrations[i-1].Version
next = mm.Migrations[i+1].Version
}
if m.Next != next {
t.Errorf("mismatched Next. v: %v, got %v, wanted %v\n", m, m.Next, next)
}
if m.Previous != prev {
t.Errorf("mismatched Previous v: %v, got %v, wanted %v\n", m, m.Previous, prev)
}
}
t.Log(mm.Migrations)
}