vitess.io/vitess@v0.16.2/go/mysql/filepos_gtid_test.go (about) 1 /* 2 Copyright 2020 The Vitess Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package mysql 18 19 import ( 20 "testing" 21 ) 22 23 func Test_filePosGTID_String(t *testing.T) { 24 type fields struct { 25 file string 26 pos int 27 } 28 tests := []struct { 29 name string 30 fields fields 31 want string 32 }{ 33 { 34 "formats gtid correctly", 35 fields{file: "mysql-bin.166031", pos: 192394}, 36 "mysql-bin.166031:192394", 37 }, 38 } 39 for _, tt := range tests { 40 t.Run(tt.name, func(t *testing.T) { 41 gtid := filePosGTID{ 42 file: tt.fields.file, 43 pos: tt.fields.pos, 44 } 45 if got := gtid.String(); got != tt.want { 46 t.Errorf("filePosGTID.String() = %v, want %v", got, tt.want) 47 } 48 }) 49 } 50 } 51 52 func Test_filePosGTID_ContainsGTID(t *testing.T) { 53 type fields struct { 54 file string 55 pos int 56 } 57 type args struct { 58 other GTID 59 } 60 tests := []struct { 61 name string 62 fields fields 63 args args 64 want bool 65 }{ 66 { 67 "returns true when the position is equal", 68 fields{file: "testfile", pos: 1234}, 69 args{other: filePosGTID{file: "testfile", pos: 1234}}, 70 true, 71 }, 72 { 73 "returns true when the position is less than equal", 74 fields{file: "testfile", pos: 1234}, 75 args{other: filePosGTID{file: "testfile", pos: 1233}}, 76 true, 77 }, 78 { 79 "returns false when the position is less than equal", 80 fields{file: "testfile", pos: 1234}, 81 args{other: filePosGTID{file: "testfile", pos: 1235}}, 82 false, 83 }, 84 { 85 "it uses integer value for comparison (it is not lexicographical order)", 86 fields{file: "testfile", pos: 99761227}, 87 args{other: filePosGTID{file: "testfile", pos: 103939867}}, 88 false, 89 }, 90 } 91 for _, tt := range tests { 92 t.Run(tt.name, func(t *testing.T) { 93 gtid := filePosGTID{ 94 file: tt.fields.file, 95 pos: tt.fields.pos, 96 } 97 if got := gtid.ContainsGTID(tt.args.other); got != tt.want { 98 t.Errorf("filePosGTID.ContainsGTID() = %v, want %v", got, tt.want) 99 } 100 }) 101 } 102 }