vitess.io/vitess@v0.16.2/go/sqltypes/event_token_test.go (about) 1 /* 2 Copyright 2019 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 sqltypes 18 19 import ( 20 "testing" 21 22 "google.golang.org/protobuf/proto" 23 24 querypb "vitess.io/vitess/go/vt/proto/query" 25 ) 26 27 func TestEventTokenMinimum(t *testing.T) { 28 testcases := []struct { 29 ev1 *querypb.EventToken 30 ev2 *querypb.EventToken 31 expected *querypb.EventToken 32 }{{ 33 ev1: nil, 34 ev2: nil, 35 expected: nil, 36 }, { 37 ev1: &querypb.EventToken{ 38 Timestamp: 123, 39 }, 40 ev2: nil, 41 expected: nil, 42 }, { 43 ev1: nil, 44 ev2: &querypb.EventToken{ 45 Timestamp: 123, 46 }, 47 expected: nil, 48 }, { 49 ev1: &querypb.EventToken{ 50 Timestamp: 123, 51 }, 52 ev2: &querypb.EventToken{ 53 Timestamp: 456, 54 }, 55 expected: &querypb.EventToken{ 56 Timestamp: 123, 57 }, 58 }, { 59 ev1: &querypb.EventToken{ 60 Timestamp: 456, 61 }, 62 ev2: &querypb.EventToken{ 63 Timestamp: 123, 64 }, 65 expected: &querypb.EventToken{ 66 Timestamp: 123, 67 }, 68 }} 69 70 for _, tcase := range testcases { 71 got := EventTokenMinimum(tcase.ev1, tcase.ev2) 72 if tcase.expected == nil && got != nil { 73 t.Errorf("expected nil result for Minimum(%v, %v) but got: %v", tcase.ev1, tcase.ev2, got) 74 continue 75 } 76 if !proto.Equal(got, tcase.expected) { 77 t.Errorf("got %v but expected %v for Minimum(%v, %v)", got, tcase.expected, tcase.ev1, tcase.ev2) 78 } 79 } 80 }