-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcmd_check_test.go
More file actions
103 lines (99 loc) · 1.77 KB
/
Copy pathcmd_check_test.go
File metadata and controls
103 lines (99 loc) · 1.77 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package main
import (
"testing"
"github.com/google/go-cmp/cmp"
)
func TestCheckMigration(t *testing.T) {
tests := map[string]struct {
dir string
num int
diff string
}{
"success-create": {
"testdata/check/success",
10,
"",
},
"success-alter-add": {
"testdata/check/success",
20,
"",
},
"success-insert": {
"testdata/check/success",
30,
"",
},
"success-alter-drop": {
"testdata/check/success",
40,
"",
},
"success-nothing": {
"testdata/check/success",
50,
"",
},
"diff-table": {
"testdata/check/table",
10,
"unexpected \"table1\" table found",
},
"diff-schema": {
"testdata/check/schema",
20,
"" +
"create table \"table1\" differs:\n" +
"...\n" +
" `val` text NOT NULL DEFAULT '',\n" +
"+ `val2` int DEFAULT '0',\n" +
" PRIMARY KEY (`id`)\n" +
"...",
},
"diff-record": {
"testdata/check/record",
30,
"" +
"records in \"table1\" differs:\n" +
"+(2, 'bbb', 20)",
},
"diff-snapshot": {
"testdata/check/snapshot",
30,
"" +
"records in \"table1\" differs:\n" +
" (1, 'aaa', 10)\n" +
"-(2, 'bbb', 200)\n" +
"+(2, 'bbb', 20)\n" +
" (3, 'ccc', 30)",
},
"diff-column": {
"testdata/check/column",
40,
"" +
"records in \"table1\" differs:\n" +
"-(1, 'aaa', 10)\n" +
"-(2, 'bbb', 20)\n" +
"-(3, 'ccc', 30)\n" +
"+(1, '', 10)\n" +
"+(2, '', 20)\n" +
"+(3, '', 30)",
},
"diff-drop": {
"testdata/check/drop",
50,
"missing \"table1\" table",
},
}
for name, test := range tests {
t.Run(name, func(t *testing.T) {
diff, err := checkMigration(test.dir, test.num)
if err != nil {
t.Error(err)
}
if d := cmp.Diff(test.diff, diff); d != "" {
t.Error(d)
}
})
}
}