-
Notifications
You must be signed in to change notification settings - Fork 72
/
inline_verifier_test.go
119 lines (101 loc) · 3.44 KB
/
inline_verifier_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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package ghostferry
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestCompareDecompressedDataNoDifference(t *testing.T) {
source := map[uint64]map[string][]byte{
31: {"name": []byte("Leszek")},
}
target := map[uint64]map[string][]byte{
31: {"name": []byte("Leszek")},
}
result := compareDecompressedData(source, target)
assert.Equal(t, map[uint64]InlineVerifierMismatches{}, result)
}
func TestCompareDecompressedDataContentDifference(t *testing.T) {
source := map[uint64]map[string][]byte{
1: {"name": []byte("Leszek")},
}
target := map[uint64]map[string][]byte{
1: {"name": []byte("Steve")},
}
result := compareDecompressedData(source, target)
assert.Equal(t, map[uint64]InlineVerifierMismatches{
1: {
Pk: 1,
MismatchType: MismatchColumnValueDifference,
MismatchColumn: "name",
SourceChecksum: "e356a972989f87a1531252cfa2152797",
TargetChecksum: "81b8a1b77068d06e1c8190825253066f",
},
}, result)
}
func TestCompareDecompressedDataMissingTarget(t *testing.T) {
source := map[uint64]map[string][]byte{
1: {"name": []byte("Leszek")},
}
target := map[uint64]map[string][]byte{}
result := compareDecompressedData(source, target)
assert.Equal(t, map[uint64]InlineVerifierMismatches{1: {Pk: 1, MismatchType: MismatchRowMissingOnTarget}}, result)
}
func TestCompareDecompressedDataMissingSource(t *testing.T) {
source := map[uint64]map[string][]byte{}
target := map[uint64]map[string][]byte{
3: {"name": []byte("Leszek")},
}
result := compareDecompressedData(source, target)
assert.Equal(t, map[uint64]InlineVerifierMismatches{3: {Pk: 3, MismatchType: MismatchRowMissingOnSource}}, result)
}
func TestFormatMismatch(t *testing.T) {
mismatches := map[string]map[string][]InlineVerifierMismatches{
"default": {
"users": {
InlineVerifierMismatches{
Pk: 1,
MismatchType: MismatchRowMissingOnSource,
},
},
},
}
message, tables := formatMismatches(mismatches)
assert.Equal(t, string("cutover verification failed for: default.users [PKs: 1 (type: row missing on source) ] "), message)
assert.Equal(t, []string{string("default.users")}, tables)
}
func TestFormatMismatches(t *testing.T) {
mismatches := map[string]map[string][]InlineVerifierMismatches{
"default": {
"users": {
InlineVerifierMismatches{
Pk: 1,
MismatchType: MismatchRowMissingOnSource,
},
InlineVerifierMismatches{
Pk: 5,
MismatchType: MismatchRowMissingOnTarget,
},
},
"posts": {
InlineVerifierMismatches{
Pk: 9,
MismatchType: MismatchColumnValueDifference,
MismatchColumn: string("title"),
SourceChecksum: "boo",
TargetChecksum: "aaa",
},
},
"attachments": {
InlineVerifierMismatches{
Pk: 7,
MismatchType: MismatchColumnValueDifference,
MismatchColumn: string("name"),
SourceChecksum: "boo",
TargetChecksum: "aaa",
},
},
},
}
message, tables := formatMismatches(mismatches)
assert.Equal(t, string("cutover verification failed for: default.attachments [PKs: 7 (type: column value difference, source: boo, target: aaa, column: name) ] default.posts [PKs: 9 (type: column value difference, source: boo, target: aaa, column: title) ] default.users [PKs: 1 (type: row missing on source) 5 (type: row missing on target) ] "), message)
assert.Equal(t, []string{string("default.attachments"), string("default.posts"), string("default.users")}, tables)
}