9
9
"strings"
10
10
"testing"
11
11
12
- test "github.com/openark/golib/tests "
12
+ "github.com/stretchr/testify/require "
13
13
14
14
"github.com/github/gh-ost/go/base"
15
15
"github.com/github/gh-ost/go/binlog"
@@ -21,33 +21,33 @@ func TestApplierGenerateSqlModeQuery(t *testing.T) {
21
21
applier := NewApplier (migrationContext )
22
22
23
23
{
24
- test .S (t ).ExpectEquals (
25
- applier .generateSqlModeQuery (),
24
+ require .Equal (t ,
26
25
`sql_mode = CONCAT(@@session.sql_mode, ',NO_AUTO_VALUE_ON_ZERO,STRICT_ALL_TABLES')` ,
26
+ applier .generateSqlModeQuery (),
27
27
)
28
28
}
29
29
{
30
30
migrationContext .SkipStrictMode = true
31
31
migrationContext .AllowZeroInDate = false
32
- test .S (t ).ExpectEquals (
33
- applier .generateSqlModeQuery (),
32
+ require .Equal (t ,
34
33
`sql_mode = CONCAT(@@session.sql_mode, ',NO_AUTO_VALUE_ON_ZERO')` ,
34
+ applier .generateSqlModeQuery (),
35
35
)
36
36
}
37
37
{
38
38
migrationContext .SkipStrictMode = false
39
39
migrationContext .AllowZeroInDate = true
40
- test .S (t ).ExpectEquals (
41
- applier .generateSqlModeQuery (),
40
+ require .Equal (t ,
42
41
`sql_mode = REPLACE(REPLACE(CONCAT(@@session.sql_mode, ',NO_AUTO_VALUE_ON_ZERO,STRICT_ALL_TABLES'), 'NO_ZERO_IN_DATE', ''), 'NO_ZERO_DATE', '')` ,
42
+ applier .generateSqlModeQuery (),
43
43
)
44
44
}
45
45
{
46
46
migrationContext .SkipStrictMode = true
47
47
migrationContext .AllowZeroInDate = true
48
- test .S (t ).ExpectEquals (
49
- applier .generateSqlModeQuery (),
48
+ require .Equal (t ,
50
49
`sql_mode = REPLACE(REPLACE(CONCAT(@@session.sql_mode, ',NO_AUTO_VALUE_ON_ZERO'), 'NO_ZERO_IN_DATE', ''), 'NO_ZERO_DATE', '')` ,
50
+ applier .generateSqlModeQuery (),
51
51
)
52
52
}
53
53
}
@@ -72,8 +72,8 @@ func TestApplierUpdateModifiesUniqueKeyColumns(t *testing.T) {
72
72
NewColumnValues : columnValues ,
73
73
WhereColumnValues : columnValues ,
74
74
})
75
- test . S ( t ). ExpectEquals ( modifiedColumn , "" )
76
- test . S ( t ). ExpectFalse ( isModified )
75
+ require . Equal ( t , "" , modifiedColumn )
76
+ require . False ( t , isModified )
77
77
})
78
78
79
79
t .Run ("modified" , func (t * testing.T ) {
@@ -83,8 +83,8 @@ func TestApplierUpdateModifiesUniqueKeyColumns(t *testing.T) {
83
83
NewColumnValues : sql .ToColumnValues ([]interface {}{123456 , 24 }),
84
84
WhereColumnValues : columnValues ,
85
85
})
86
- test . S ( t ). ExpectEquals ( modifiedColumn , "item_id" )
87
- test . S ( t ). ExpectTrue ( isModified )
86
+ require . Equal ( t , "item_id" , modifiedColumn )
87
+ require . True ( t , isModified )
88
88
})
89
89
}
90
90
@@ -112,17 +112,17 @@ func TestApplierBuildDMLEventQuery(t *testing.T) {
112
112
}
113
113
114
114
res := applier .buildDMLEventQuery (binlogEvent )
115
- test . S ( t ). ExpectEquals ( len ( res ) , 1 )
116
- test . S ( t ). ExpectNil ( res [0 ].err )
117
- test . S ( t ). ExpectEquals ( strings . TrimSpace ( res [ 0 ]. query ) , `delete /* gh-ost ` + "`test`.`_test_gho`" + ` */
115
+ require . Len ( t , res , 1 )
116
+ require . NoError ( t , res [0 ].err )
117
+ require . Equal ( t , `delete /* gh-ost ` + "`test`.`_test_gho`" + ` */
118
118
from
119
119
` + "`test`.`_test_gho`" + `
120
120
where
121
121
((` + "`id`" + ` = ?) and (` + "`item_id`" + ` = ?))` ,
122
- )
123
- test . S ( t ). ExpectEquals ( len ( res [0 ].args ) , 2 )
124
- test . S ( t ). ExpectEquals ( res [0 ].args [0 ], 123456 )
125
- test . S ( t ). ExpectEquals ( res [0 ].args [1 ], 42 )
122
+ strings . TrimSpace ( res [ 0 ]. query ) )
123
+ require . Len ( t , res [0 ].args , 2 )
124
+ require . Equal ( t , 123456 , res [0 ].args [0 ])
125
+ require . Equal ( t , 42 , res [0 ].args [1 ])
126
126
})
127
127
128
128
t .Run ("insert" , func (t * testing.T ) {
@@ -132,18 +132,19 @@ func TestApplierBuildDMLEventQuery(t *testing.T) {
132
132
NewColumnValues : columnValues ,
133
133
}
134
134
res := applier .buildDMLEventQuery (binlogEvent )
135
- test . S ( t ). ExpectEquals ( len ( res ) , 1 )
136
- test . S ( t ). ExpectNil ( res [0 ].err )
137
- test . S ( t ). ExpectEquals ( strings . TrimSpace ( res [ 0 ]. query ) ,
135
+ require . Len ( t , res , 1 )
136
+ require . NoError ( t , res [0 ].err )
137
+ require . Equal ( t ,
138
138
`replace /* gh-ost ` + "`test`.`_test_gho`" + ` */
139
139
into
140
140
` + "`test`.`_test_gho`" + `
141
141
` + "(`id`, `item_id`)" + `
142
142
values
143
- (?, ?)` )
144
- test .S (t ).ExpectEquals (len (res [0 ].args ), 2 )
145
- test .S (t ).ExpectEquals (res [0 ].args [0 ], 123456 )
146
- test .S (t ).ExpectEquals (res [0 ].args [1 ], 42 )
143
+ (?, ?)` ,
144
+ strings .TrimSpace (res [0 ].query ))
145
+ require .Len (t , res [0 ].args , 2 )
146
+ require .Equal (t , 123456 , res [0 ].args [0 ])
147
+ require .Equal (t , 42 , res [0 ].args [1 ])
147
148
})
148
149
149
150
t .Run ("update" , func (t * testing.T ) {
@@ -154,20 +155,21 @@ func TestApplierBuildDMLEventQuery(t *testing.T) {
154
155
WhereColumnValues : columnValues ,
155
156
}
156
157
res := applier .buildDMLEventQuery (binlogEvent )
157
- test . S ( t ). ExpectEquals ( len ( res ) , 1 )
158
- test . S ( t ). ExpectNil ( res [0 ].err )
159
- test . S ( t ). ExpectEquals ( strings . TrimSpace ( res [ 0 ]. query ) ,
158
+ require . Len ( t , res , 1 )
159
+ require . NoError ( t , res [0 ].err )
160
+ require . Equal ( t ,
160
161
`update /* gh-ost ` + "`test`.`_test_gho`" + ` */
161
162
` + "`test`.`_test_gho`" + `
162
163
set
163
164
` + "`id`" + `=?, ` + "`item_id`" + `=?
164
165
where
165
- ((` + "`id`" + ` = ?) and (` + "`item_id`" + ` = ?))` )
166
- test .S (t ).ExpectEquals (len (res [0 ].args ), 4 )
167
- test .S (t ).ExpectEquals (res [0 ].args [0 ], 123456 )
168
- test .S (t ).ExpectEquals (res [0 ].args [1 ], 42 )
169
- test .S (t ).ExpectEquals (res [0 ].args [2 ], 123456 )
170
- test .S (t ).ExpectEquals (res [0 ].args [3 ], 42 )
166
+ ((` + "`id`" + ` = ?) and (` + "`item_id`" + ` = ?))` ,
167
+ strings .TrimSpace (res [0 ].query ))
168
+ require .Len (t , res [0 ].args , 4 )
169
+ require .Equal (t , 123456 , res [0 ].args [0 ])
170
+ require .Equal (t , 42 , res [0 ].args [1 ])
171
+ require .Equal (t , 123456 , res [0 ].args [2 ])
172
+ require .Equal (t , 42 , res [0 ].args [3 ])
171
173
})
172
174
}
173
175
@@ -180,6 +182,6 @@ func TestApplierInstantDDL(t *testing.T) {
180
182
181
183
t .Run ("instantDDLstmt" , func (t * testing.T ) {
182
184
stmt := applier .generateInstantDDLQuery ()
183
- test . S ( t ). ExpectEquals ( stmt , "ALTER /* gh-ost */ TABLE `test`.`mytable` ADD INDEX (foo), ALGORITHM=INSTANT" )
185
+ require . Equal ( t , "ALTER /* gh-ost */ TABLE `test`.`mytable` ADD INDEX (foo), ALGORITHM=INSTANT" , stmt )
184
186
})
185
187
}
0 commit comments