vitess.io/vitess@v0.16.2/go/mysql/constants_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 mysql 18 19 import ( 20 "errors" 21 "testing" 22 23 "github.com/stretchr/testify/assert" 24 ) 25 26 func TestIsConnErr(t *testing.T) { 27 testcases := []struct { 28 in error 29 want bool 30 }{{ 31 in: errors.New("t"), 32 want: false, 33 }, { 34 in: NewSQLError(5, "", ""), 35 want: false, 36 }, { 37 in: NewSQLError(CRServerGone, "", ""), 38 want: true, 39 }, { 40 in: NewSQLError(CRServerLost, "", ""), 41 want: true, 42 }, { 43 in: NewSQLError(ERQueryInterrupted, "", ""), 44 want: true, 45 }, { 46 in: NewSQLError(CRCantReadCharset, "", ""), 47 want: false, 48 }} 49 for _, tcase := range testcases { 50 got := IsConnErr(tcase.in) 51 assert.Equal(t, tcase.want, got, "IsConnErr(%#v): %v, want %v", tcase.in, got, tcase.want) 52 53 } 54 } 55 56 func TestIsConnLostDuringQuery(t *testing.T) { 57 testcases := []struct { 58 in error 59 want bool 60 }{{ 61 in: errors.New("t"), 62 want: false, 63 }, { 64 in: NewSQLError(5, "", ""), 65 want: false, 66 }, { 67 in: NewSQLError(CRServerGone, "", ""), 68 want: false, 69 }, { 70 in: NewSQLError(CRServerLost, "", ""), 71 want: true, 72 }, { 73 in: NewSQLError(ERQueryInterrupted, "", ""), 74 want: false, 75 }, { 76 in: NewSQLError(CRCantReadCharset, "", ""), 77 want: false, 78 }} 79 for _, tcase := range testcases { 80 got := IsConnLostDuringQuery(tcase.in) 81 assert.Equal(t, tcase.want, got, "IsConnLostDuringQuery(%#v): %v, want %v", tcase.in, got, tcase.want) 82 83 } 84 }