github.com/matrixorigin/matrixone@v1.2.0/pkg/queryservice/client/query_client_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 client 16 17 import ( 18 "testing" 19 20 "github.com/matrixorigin/matrixone/pkg/common/moerr" 21 "github.com/matrixorigin/matrixone/pkg/common/morpc" 22 "github.com/matrixorigin/matrixone/pkg/pb/query" 23 "github.com/stretchr/testify/assert" 24 ) 25 26 func testCreateQueryClient(t *testing.T) QueryClient { 27 ct, err := NewQueryClient("", morpc.Config{}) 28 assert.NoError(t, err) 29 return ct 30 } 31 32 func TestNewCacheClient(t *testing.T) { 33 ct := testCreateQueryClient(t) 34 assert.NotNil(t, ct) 35 } 36 37 func TestUnwrapResponseError(t *testing.T) { 38 ct := testCreateQueryClient(t) 39 assert.NotNil(t, ct) 40 client, ok := ct.(*queryClient) 41 assert.True(t, ok) 42 resp1 := &query.Response{Error: nil} 43 resp2, err := client.unwrapResponseError(resp1) 44 assert.Nil(t, err) 45 assert.Equal(t, resp2, resp1) 46 47 e := moerr.NewInternalErrorNoCtx("test") 48 moe, err := e.MarshalBinary() 49 assert.NoError(t, err) 50 resp1 = &query.Response{Error: moe} 51 resp2, err = client.unwrapResponseError(resp1) 52 assert.Equal(t, "internal error: test", err.Error()) 53 assert.Nil(t, resp2) 54 }