|
| 1 | +package src |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + . "github.com/smartystreets/goconvey/convey" |
| 7 | +) |
| 8 | + |
| 9 | +func TestTransferToTypeByColumnType_Starrocks(t *testing.T) { |
| 10 | + type ColumnTypeStruct struct { |
| 11 | + columnTypeList []string |
| 12 | + nullable bool |
| 13 | + destColumnType string |
| 14 | + } |
| 15 | + var caseList = []ColumnTypeStruct{ |
| 16 | + { |
| 17 | + columnTypeList: []string{"uint64"}, |
| 18 | + nullable: false, |
| 19 | + destColumnType: "VARCHAR(20)", |
| 20 | + }, |
| 21 | + { |
| 22 | + columnTypeList: []string{"int64", "uint32"}, |
| 23 | + nullable: false, |
| 24 | + destColumnType: "BIGINT(20)", |
| 25 | + }, |
| 26 | + { |
| 27 | + columnTypeList: []string{"int32", "uint24", "int24", "uint16"}, |
| 28 | + nullable: false, |
| 29 | + destColumnType: "INT(11)", |
| 30 | + }, |
| 31 | + { |
| 32 | + columnTypeList: []string{"int16", "year(4)", "year(2)", "year", "uint8"}, |
| 33 | + nullable: false, |
| 34 | + destColumnType: "SMALLINT(6)", |
| 35 | + }, |
| 36 | + { |
| 37 | + columnTypeList: []string{"int8", "bool"}, |
| 38 | + nullable: false, |
| 39 | + destColumnType: "TINYINT(4)", |
| 40 | + }, |
| 41 | + { |
| 42 | + columnTypeList: []string{"float"}, |
| 43 | + nullable: false, |
| 44 | + destColumnType: "FLOAT", |
| 45 | + }, |
| 46 | + { |
| 47 | + columnTypeList: []string{"double", "real"}, |
| 48 | + nullable: false, |
| 49 | + destColumnType: "DOUBLE", |
| 50 | + }, |
| 51 | + { |
| 52 | + columnTypeList: []string{"decimal", "numeric"}, |
| 53 | + nullable: false, |
| 54 | + destColumnType: "DECIMAL", |
| 55 | + }, |
| 56 | + { |
| 57 | + columnTypeList: []string{"decimal(9,2)"}, |
| 58 | + nullable: false, |
| 59 | + destColumnType: "Decimal(9,2)", |
| 60 | + }, |
| 61 | + { |
| 62 | + columnTypeList: []string{"decimal(19,5)"}, |
| 63 | + nullable: false, |
| 64 | + destColumnType: "Decimal(19,5)", |
| 65 | + }, |
| 66 | + { |
| 67 | + columnTypeList: []string{"decimal(38,2)"}, |
| 68 | + nullable: false, |
| 69 | + destColumnType: "Decimal(38,2)", |
| 70 | + }, |
| 71 | + { |
| 72 | + columnTypeList: []string{"decimal(39,2)"}, |
| 73 | + nullable: false, |
| 74 | + destColumnType: "VARCHAR(78)", |
| 75 | + }, |
| 76 | + { |
| 77 | + columnTypeList: []string{"decimal(88,2)"}, |
| 78 | + nullable: false, |
| 79 | + destColumnType: "VARCHAR(255)", |
| 80 | + }, |
| 81 | + { |
| 82 | + columnTypeList: []string{"date", "Nullable(date)"}, |
| 83 | + nullable: false, |
| 84 | + destColumnType: "DATE", |
| 85 | + }, |
| 86 | + { |
| 87 | + columnTypeList: []string{"json"}, |
| 88 | + nullable: false, |
| 89 | + destColumnType: "JSON", |
| 90 | + }, |
| 91 | + { |
| 92 | + columnTypeList: []string{"time"}, |
| 93 | + nullable: false, |
| 94 | + destColumnType: "VARCHAR(10)", |
| 95 | + }, |
| 96 | + { |
| 97 | + columnTypeList: []string{"enum"}, |
| 98 | + nullable: false, |
| 99 | + destColumnType: "VARCHAR(255)", |
| 100 | + }, |
| 101 | + { |
| 102 | + columnTypeList: []string{"set"}, |
| 103 | + nullable: false, |
| 104 | + destColumnType: "VARCHAR(2048)", |
| 105 | + }, |
| 106 | + { |
| 107 | + columnTypeList: []string{"string", "longblob", "longtext"}, |
| 108 | + nullable: false, |
| 109 | + destColumnType: "VARCHAR(163841)", |
| 110 | + }, |
| 111 | + { |
| 112 | + columnTypeList: []string{"double(9,2)", "real(10,2)"}, |
| 113 | + nullable: false, |
| 114 | + destColumnType: "DOUBLE", |
| 115 | + }, |
| 116 | + { |
| 117 | + columnTypeList: []string{"float(9,2)"}, |
| 118 | + nullable: false, |
| 119 | + destColumnType: "FLOAT", |
| 120 | + }, |
| 121 | + { |
| 122 | + columnTypeList: []string{"bit"}, |
| 123 | + nullable: false, |
| 124 | + destColumnType: "BIGINT(20)", |
| 125 | + }, |
| 126 | + { |
| 127 | + columnTypeList: []string{"timestamp(6)", "datetime(3)"}, |
| 128 | + nullable: false, |
| 129 | + destColumnType: "DATETIME", |
| 130 | + }, |
| 131 | + { |
| 132 | + columnTypeList: []string{"time(6)", "time(1)"}, |
| 133 | + nullable: false, |
| 134 | + destColumnType: "VARCHAR(16)", |
| 135 | + }, |
| 136 | + { |
| 137 | + columnTypeList: []string{"enum('a','b')"}, |
| 138 | + nullable: false, |
| 139 | + destColumnType: "VARCHAR(255)", |
| 140 | + }, |
| 141 | + { |
| 142 | + columnTypeList: []string{"set('a','b')"}, |
| 143 | + nullable: false, |
| 144 | + destColumnType: "VARCHAR(2048)", |
| 145 | + }, |
| 146 | + { |
| 147 | + columnTypeList: []string{"char(1)"}, |
| 148 | + nullable: false, |
| 149 | + destColumnType: "CHAR(1)", |
| 150 | + }, |
| 151 | + { |
| 152 | + columnTypeList: []string{"char(255)"}, |
| 153 | + nullable: false, |
| 154 | + destColumnType: "CHAR(255)", |
| 155 | + }, |
| 156 | + { |
| 157 | + columnTypeList: []string{"varchar(500)"}, |
| 158 | + nullable: false, |
| 159 | + destColumnType: "VARCHAR(500)", |
| 160 | + }, |
| 161 | + |
| 162 | + { |
| 163 | + columnTypeList: []string{"Nullable(varchar(500))"}, |
| 164 | + nullable: false, |
| 165 | + destColumnType: "VARCHAR(500)", |
| 166 | + }, |
| 167 | + { |
| 168 | + columnTypeList: []string{"Nullable(int64)"}, |
| 169 | + nullable: true, |
| 170 | + destColumnType: "BIGINT(20) DEFAULT NULL", |
| 171 | + }, |
| 172 | + } |
| 173 | + |
| 174 | + c := &Conn{} |
| 175 | + for _, caseInfo := range caseList { |
| 176 | + for _, columnType := range caseInfo.columnTypeList { |
| 177 | + Convey(caseInfo.destColumnType, t, func() { |
| 178 | + toDestColumnType := c.TransferToTypeByColumnType_Starrocks(columnType, caseInfo.nullable) |
| 179 | + So(toDestColumnType, ShouldEqual, caseInfo.destColumnType) |
| 180 | + }) |
| 181 | + } |
| 182 | + } |
| 183 | +} |
0 commit comments