github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/tests/mq_protocol_tests/cases/case_unsigned.go (about) 1 // Copyright 2020 PingCAP, 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 cases 15 16 import ( 17 "github.com/pingcap/tiflow/tests/mq_protocol_tests/framework" 18 ) 19 20 // UnsignedCase is base impl of test case for unsigned int type data 21 type UnsignedCase struct { 22 framework.Task 23 } 24 25 // NewUnsignedCase create a test case to check the correction of unsigned integer 26 func NewUnsignedCase(task framework.Task) *UnsignedCase { 27 return &UnsignedCase{ 28 Task: task, 29 } 30 } 31 32 // Name impl framework.Task interface 33 func (s *UnsignedCase) Name() string { 34 return "Unsigned" 35 } 36 37 // Run impl framework.Task interface 38 func (s *UnsignedCase) Run(ctx *framework.TaskContext) error { 39 createDBQuery := `create table test ( 40 id INT, 41 t_int INT UNSIGNED, 42 t_bigint BIGINT UNSIGNED, 43 t_bit BIT(64), 44 PRIMARY KEY (id) 45 ) 46 ` 47 _, err := ctx.Upstream.ExecContext(ctx.Ctx, createDBQuery) 48 if err != nil { 49 return err 50 } 51 52 _, err = ctx.Downstream.ExecContext(ctx.Ctx, "drop table if exists test") 53 if err != nil { 54 return err 55 } 56 57 _, err = ctx.Downstream.ExecContext(ctx.Ctx, createDBQuery) 58 if err != nil { 59 return err 60 } 61 62 // Get a handle of an existing table 63 table := ctx.SQLHelper().GetTable("test") 64 return table.Insert(map[string]interface{}{ 65 "id": 0, 66 "t_int": 0xFEEDBEEF, 67 "t_bigint": uint64(0xFEEDBEEFFEEDBEEF), 68 "t_bit": uint64(0xFFFFFFFFFFFFFFFA), 69 }).Send().Wait().Check() 70 }