-
Notifications
You must be signed in to change notification settings - Fork 198
Expand file tree
/
Copy pathqrep_test.go
More file actions
110 lines (106 loc) · 4.01 KB
/
Copy pathqrep_test.go
File metadata and controls
110 lines (106 loc) · 4.01 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
104
105
106
107
108
109
110
package connmysql
import (
"testing"
"github.com/PeerDB-io/peerdb/flow/generated/protos"
"github.com/PeerDB-io/peerdb/flow/shared"
"github.com/PeerDB-io/peerdb/flow/shared/types"
)
func TestBuildSelectedColumns(t *testing.T) {
testCases := []struct {
name string
expectedSelectedColumns string
cols []*protos.FieldDescription
exclude []string
isBinlogMetadataSupported bool
mirrorVersion uint32
}{
{
name: "no excluded columns, binlog metadata supported",
cols: []*protos.FieldDescription{
{Name: "id", Type: string(types.QValueKindInt32)},
{Name: "name", Type: string(types.QValueKindString)},
{Name: "status", Type: string(types.QValueKindEnum)},
},
exclude: []string{},
isBinlogMetadataSupported: true,
mirrorVersion: shared.InternalVersion_MySQLConvertEnumsToInts,
expectedSelectedColumns: "*",
},
{
name: "one excluded column, binlog metadata supported",
cols: []*protos.FieldDescription{
{Name: "id", Type: string(types.QValueKindInt32)},
{Name: "name", Type: string(types.QValueKindString)},
},
exclude: []string{"name"},
isBinlogMetadataSupported: true,
mirrorVersion: shared.InternalVersion_MySQLConvertEnumsToInts,
expectedSelectedColumns: "`id`",
},
{
name: "one enum column, binlog metadata not supported, new version",
cols: []*protos.FieldDescription{
{Name: "id", Type: string(types.QValueKindInt32)},
{Name: "status", Type: string(types.QValueKindEnum)},
},
exclude: []string{},
isBinlogMetadataSupported: false,
mirrorVersion: shared.InternalVersion_MySQLConvertEnumsToInts,
expectedSelectedColumns: "`id`, CAST(`status` AS UNSIGNED) AS `status`",
},
{
name: "one enum column, binlog metadata not supported, old version",
cols: []*protos.FieldDescription{
{Name: "id", Type: string(types.QValueKindInt32)},
{Name: "status", Type: string(types.QValueKindEnum)},
},
exclude: []string{},
isBinlogMetadataSupported: false,
mirrorVersion: shared.InternalVersion_MySQLConvertEnumsToInts - 1,
expectedSelectedColumns: "*",
},
{
name: "one enum column, binlog metadata not supported, version zero",
cols: []*protos.FieldDescription{
{Name: "id", Type: string(types.QValueKindInt32)},
{Name: "status", Type: string(types.QValueKindEnum)},
},
exclude: []string{},
isBinlogMetadataSupported: false,
mirrorVersion: 0,
expectedSelectedColumns: "*",
},
{
name: "one enum column, one excluded non enum column, binlog metadata supported",
cols: []*protos.FieldDescription{
{Name: "id", Type: string(types.QValueKindInt32)},
{Name: "status", Type: string(types.QValueKindEnum)},
{Name: "created_at", Type: string(types.QValueKindTimestamp)},
},
exclude: []string{"created_at"},
isBinlogMetadataSupported: true,
mirrorVersion: shared.InternalVersion_MySQLConvertEnumsToInts,
expectedSelectedColumns: "`id`, `status`",
},
{
name: "enum with exclude, binlog metadata not supported, old version",
cols: []*protos.FieldDescription{
{Name: "id", Type: string(types.QValueKindInt32)},
{Name: "status", Type: string(types.QValueKindEnum)},
{Name: "created_at", Type: string(types.QValueKindTimestamp)},
},
exclude: []string{"created_at"},
isBinlogMetadataSupported: false,
mirrorVersion: shared.InternalVersion_MySQLConvertEnumsToInts - 1,
expectedSelectedColumns: "`id`, `status`",
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
selectedColumns := buildSelectedColumns(tc.cols, tc.exclude, tc.isBinlogMetadataSupported, tc.mirrorVersion)
if selectedColumns != tc.expectedSelectedColumns {
t.Errorf("expected selected columns to be %s, but got %s", tc.expectedSelectedColumns, selectedColumns)
}
})
}
}