@@ -11,14 +11,14 @@ import (
1111)
1212
1313type mockSQLRunner struct {
14- sqlResponses map [string ]string
14+ sqlResponses map [string ]any
1515 gtidExecuted string
1616 gtidPurged string
1717}
1818
1919func newMockSQLRunner () * mockSQLRunner {
2020 return & mockSQLRunner {
21- sqlResponses : make (map [string ]string ),
21+ sqlResponses : make (map [string ]any ),
2222 gtidExecuted : "" ,
2323 gtidPurged : "" ,
2424 }
@@ -27,10 +27,10 @@ func newMockSQLRunner() *mockSQLRunner {
2727func (m * mockSQLRunner ) runSQL (ctx context.Context , sql string ) (SQLResult , error ) {
2828 if result , ok := m .sqlResponses [sql ]; ok {
2929 return SQLResult {
30- Rows : []map [string ]string {
30+ Rows : []map [string ]any {
3131 {
32- "sub" : result ,
33- "GTID_SUBTRACT " : result , // for comparePrimaryPurged
32+ "sub" : result ,
33+ "is_subset " : result , // for comparePrimaryPurged
3434 },
3535 },
3636 }, nil
@@ -66,7 +66,6 @@ func TestCompareGTIDs_Equal(t *testing.T) {
6666 mock .setGTIDSubtractResponse ("b:1-3" , "a:1-5" , "" )
6767
6868 result , err := compareGTIDs (ctx , mock , "a:1-5" , "b:1-3" )
69-
7069 if err != nil {
7170 t .Fatalf ("unexpected error: %v" , err )
7271 }
@@ -84,7 +83,6 @@ func TestCompareGTIDs_AContainsB(t *testing.T) {
8483 mock .setGTIDSubtractResponse ("a:1-5" , "a:1-10" , "" )
8584
8685 result , err := compareGTIDs (ctx , mock , "a:1-10" , "a:1-5" )
87-
8886 if err != nil {
8987 t .Fatalf ("unexpected error: %v" , err )
9088 }
@@ -102,7 +100,6 @@ func TestCompareGTIDs_BContainsA(t *testing.T) {
102100 mock .setGTIDSubtractResponse ("a:1-10" , "a:1-5" , "a:6-10" )
103101
104102 result , err := compareGTIDs (ctx , mock , "a:1-5" , "a:1-10" )
105-
106103 if err != nil {
107104 t .Fatalf ("unexpected error: %v" , err )
108105 }
@@ -122,7 +119,6 @@ func TestCompareGTIDs_Disjoint(t *testing.T) {
122119 mock .setGTIDSubtractIntersectionResponse ("a:1-5" , "b:1-5" , "" )
123120
124121 result , err := compareGTIDs (ctx , mock , "a:1-5" , "b:1-5" )
125-
126122 if err != nil {
127123 t .Fatalf ("unexpected error: %v" , err )
128124 }
@@ -142,7 +138,6 @@ func TestCompareGTIDs_Intersects(t *testing.T) {
142138 mock .setGTIDSubtractIntersectionResponse ("a:1-10" , "a:6-15" , "a:6-10" )
143139
144140 result , err := compareGTIDs (ctx , mock , "a:1-10" , "a:6-15" )
145-
146141 if err != nil {
147142 t .Fatalf ("unexpected error: %v" , err )
148143 }
@@ -156,7 +151,6 @@ func TestCompareGTIDs_BothEmpty(t *testing.T) {
156151 mock := newMockSQLRunner ()
157152
158153 result , err := compareGTIDs (ctx , mock , "" , "" )
159-
160154 if err != nil {
161155 t .Fatalf ("unexpected error: %v" , err )
162156 }
@@ -170,7 +164,6 @@ func TestCompareGTIDs_AEmpty(t *testing.T) {
170164 mock := newMockSQLRunner ()
171165
172166 result , err := compareGTIDs (ctx , mock , "" , "b:1-5" )
173-
174167 if err != nil {
175168 t .Fatalf ("unexpected error: %v" , err )
176169 }
@@ -184,7 +177,6 @@ func TestCompareGTIDs_BEmpty(t *testing.T) {
184177 mock := newMockSQLRunner ()
185178
186179 result , err := compareGTIDs (ctx , mock , "a:1-5" , "" )
187-
188180 if err != nil {
189181 t .Fatalf ("unexpected error: %v" , err )
190182 }
@@ -207,7 +199,6 @@ func TestCheckReplicaState_New(t *testing.T) {
207199 replica := newMockSQLRunnerWithGTIDs ("" , "" )
208200
209201 result , err := checkReplicaState (ctx , primary , replica )
210-
211202 if err != nil {
212203 t .Fatalf ("unexpected error: %v" , err )
213204 }
@@ -226,7 +217,6 @@ func TestCheckReplicaState_Identical(t *testing.T) {
226217 primary .setGTIDSubtractResponse ("a:1-10" , "a:1-10" , "" )
227218
228219 result , err := checkReplicaState (ctx , primary , replica )
229-
230220 if err != nil {
231221 t .Fatalf ("unexpected error: %v" , err )
232222 }
@@ -245,7 +235,6 @@ func TestCheckReplicaState_Recoverable_NoPurged(t *testing.T) {
245235 primary .setGTIDSubtractResponse ("a:1-5" , "a:1-10" , "" )
246236
247237 result , err := checkReplicaState (ctx , primary , replica )
248-
249238 if err != nil {
250239 t .Fatalf ("unexpected error: %v" , err )
251240 }
@@ -264,10 +253,9 @@ func TestCheckReplicaState_Recoverable_WithPurgedButOK(t *testing.T) {
264253 primary .setGTIDSubtractResponse ("a:1-5" , "a:1-10" , "" )
265254
266255 // comparePrimaryPurged check - purged is subset of replica executed
267- primary .sqlResponses ["SELECT GTID_SUBTRACT('a:1-3', 'a:1-5') = ''" ] = "0"
256+ primary .sqlResponses ["SELECT GTID_SUBTRACT('a:1-3', 'a:1-5') = '' AS is_subset " ] = float64 ( 1.0 )
268257
269258 result , err := checkReplicaState (ctx , primary , replica )
270-
271259 if err != nil {
272260 t .Fatalf ("unexpected error: %v" , err )
273261 }
@@ -286,10 +274,9 @@ func TestCheckReplicaState_Irrecoverable(t *testing.T) {
286274 primary .setGTIDSubtractResponse ("a:1-5" , "a:1-10" , "" )
287275
288276 // comparePrimaryPurged check fails - purged has more than replica executed
289- primary .sqlResponses ["SELECT GTID_SUBTRACT('a:1-8', 'a:1-5') = ''" ] = "1"
277+ primary .sqlResponses ["SELECT GTID_SUBTRACT('a:1-8', 'a:1-5') = '' AS is_subset " ] = float64 ( 0.0 )
290278
291279 result , err := checkReplicaState (ctx , primary , replica )
292-
293280 if err != nil {
294281 t .Fatalf ("unexpected error: %v" , err )
295282 }
@@ -309,7 +296,6 @@ func TestCheckReplicaState_Diverged_Intersects(t *testing.T) {
309296 primary .setGTIDSubtractIntersectionResponse ("a:1-10" , "a:5-15" , "a:5-10" )
310297
311298 result , err := checkReplicaState (ctx , primary , replica )
312-
313299 if err != nil {
314300 t .Fatalf ("unexpected error: %v" , err )
315301 }
@@ -329,7 +315,6 @@ func TestCheckReplicaState_Diverged_Disjoint(t *testing.T) {
329315 primary .setGTIDSubtractIntersectionResponse ("a:1-5" , "b:1-5" , "" )
330316
331317 result , err := checkReplicaState (ctx , primary , replica )
332-
333318 if err != nil {
334319 t .Fatalf ("unexpected error: %v" , err )
335320 }
@@ -348,7 +333,6 @@ func TestCheckReplicaState_Diverged_Contained(t *testing.T) {
348333 primary .setGTIDSubtractResponse ("a:1-10" , "a:1-5" , "a:6-10" )
349334
350335 result , err := checkReplicaState (ctx , primary , replica )
351-
352336 if err != nil {
353337 t .Fatalf ("unexpected error: %v" , err )
354338 }
0 commit comments