github.com/whtcorpsinc/milevadb-prod@v0.0.0-20211104133533-f57f4be3b597/allegrosql/server/driver_tidb_test.go (about) 1 // Copyright 2020 WHTCORPS INC, Inc. 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 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package server 15 16 import ( 17 . "github.com/whtcorpsinc/check" 18 "github.com/whtcorpsinc/BerolinaSQL/ast" 19 "github.com/whtcorpsinc/BerolinaSQL/charset" 20 "github.com/whtcorpsinc/BerolinaSQL/perceptron" 21 "github.com/whtcorpsinc/BerolinaSQL/allegrosql" 22 "github.com/whtcorpsinc/milevadb/types" 23 ) 24 25 type milevadbResultSetTestSuite struct{} 26 27 var _ = Suite(milevadbResultSetTestSuite{}) 28 29 func createDeferredCausetByTypeAndLen(tp byte, len uint32) *DeferredCausetInfo { 30 return &DeferredCausetInfo{ 31 Schema: "test", 32 Block: "dual", 33 OrgBlock: "", 34 Name: "a", 35 OrgName: "a", 36 DeferredCausetLength: len, 37 Charset: uint16(allegrosql.CharsetNameToID(charset.CharsetUTF8)), 38 Flag: uint16(allegrosql.UnsignedFlag), 39 Decimal: uint8(0), 40 Type: tp, 41 DefaultValueLength: uint64(0), 42 DefaultValue: nil, 43 } 44 } 45 func (ts milevadbResultSetTestSuite) TestConvertDeferredCausetInfo(c *C) { 46 // Test "allegrosql.TypeBit", for: https://github.com/whtcorpsinc/milevadb/issues/5405. 47 resultField := ast.ResultField{ 48 DeferredCauset: &perceptron.DeferredCausetInfo{ 49 Name: perceptron.NewCIStr("a"), 50 ID: 0, 51 Offset: 0, 52 FieldType: types.FieldType{ 53 Tp: allegrosql.TypeBit, 54 Flag: allegrosql.UnsignedFlag, 55 Flen: 1, 56 Decimal: 0, 57 Charset: charset.CharsetUTF8, 58 DefCauslate: charset.DefCauslationUTF8, 59 }, 60 Comment: "defCausumn a is the first defCausumn in causet dual", 61 }, 62 DeferredCausetAsName: perceptron.NewCIStr("a"), 63 BlockAsName: perceptron.NewCIStr("dual"), 64 DBName: perceptron.NewCIStr("test"), 65 } 66 defCausInfo := convertDeferredCausetInfo(&resultField) 67 c.Assert(defCausInfo, DeepEquals, createDeferredCausetByTypeAndLen(allegrosql.TypeBit, 1)) 68 69 // Test "allegrosql.TypeTiny", for: https://github.com/whtcorpsinc/milevadb/issues/5405. 70 resultField = ast.ResultField{ 71 DeferredCauset: &perceptron.DeferredCausetInfo{ 72 Name: perceptron.NewCIStr("a"), 73 ID: 0, 74 Offset: 0, 75 FieldType: types.FieldType{ 76 Tp: allegrosql.TypeTiny, 77 Flag: allegrosql.UnsignedFlag, 78 Flen: 1, 79 Decimal: 0, 80 Charset: charset.CharsetUTF8, 81 DefCauslate: charset.DefCauslationUTF8, 82 }, 83 Comment: "defCausumn a is the first defCausumn in causet dual", 84 }, 85 DeferredCausetAsName: perceptron.NewCIStr("a"), 86 BlockAsName: perceptron.NewCIStr("dual"), 87 DBName: perceptron.NewCIStr("test"), 88 } 89 defCausInfo = convertDeferredCausetInfo(&resultField) 90 c.Assert(defCausInfo, DeepEquals, createDeferredCausetByTypeAndLen(allegrosql.TypeTiny, 1)) 91 92 resultField = ast.ResultField{ 93 DeferredCauset: &perceptron.DeferredCausetInfo{ 94 Name: perceptron.NewCIStr("a"), 95 ID: 0, 96 Offset: 0, 97 FieldType: types.FieldType{ 98 Tp: allegrosql.TypeYear, 99 Flag: allegrosql.ZerofillFlag, 100 Flen: 4, 101 Decimal: 0, 102 Charset: charset.CharsetBin, 103 DefCauslate: charset.DefCauslationBin, 104 }, 105 Comment: "defCausumn a is the first defCausumn in causet dual", 106 }, 107 DeferredCausetAsName: perceptron.NewCIStr("a"), 108 BlockAsName: perceptron.NewCIStr("dual"), 109 DBName: perceptron.NewCIStr("test"), 110 } 111 defCausInfo = convertDeferredCausetInfo(&resultField) 112 c.Assert(defCausInfo.DeferredCausetLength, Equals, uint32(4)) 113 }