github.com/matrixorigin/matrixone@v1.2.0/pkg/proxy/error_test.go (about) 1 // Copyright 2021 - 2023 Matrix Origin 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package proxy 16 17 import ( 18 "testing" 19 20 "github.com/matrixorigin/matrixone/pkg/common/moerr" 21 "github.com/stretchr/testify/require" 22 ) 23 24 func TestErrorCode_String(t *testing.T) { 25 c := codeNone 26 require.NotEqual(t, "", c.String()) 27 c = codeAuthFailed 28 require.NotEqual(t, "", c.String()) 29 c = codeClientDisconnect 30 require.NotEqual(t, "", c.String()) 31 c = codeServerDisconnect 32 require.NotEqual(t, "", c.String()) 33 } 34 35 func TestErrorCode_WithCode(t *testing.T) { 36 c := withCode(nil, codeNone) 37 require.Nil(t, c) 38 c = withCode(moerr.NewInternalErrorNoCtx("error1"), codeNone) 39 require.Equal(t, "internal error: error1", c.Error()) 40 c = withCode(moerr.NewInternalErrorNoCtx("error2"), codeAuthFailed) 41 require.Equal(t, "Auth failed: internal error: error2", c.Error()) 42 c = withCode(moerr.NewInternalErrorNoCtx("error3"), codeClientDisconnect) 43 require.Equal(t, "Client disconnect: internal error: error3", c.Error()) 44 c = withCode(moerr.NewInternalErrorNoCtx("error4"), codeServerDisconnect) 45 require.Equal(t, "Server disconnect: internal error: error4", c.Error()) 46 } 47 48 func TestRetryableError(t *testing.T) { 49 e := newConnectErr(nil) 50 require.True(t, isRetryableErr(e)) 51 52 e = newConnectErr(moerr.NewInternalErrorNoCtx("e")) 53 require.Equal(t, e.Error(), "internal error: e") 54 }