-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathtoddl_test.go
More file actions
403 lines (392 loc) · 18.2 KB
/
toddl_test.go
File metadata and controls
403 lines (392 loc) · 18.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package mysql
import (
"context"
"testing"
"github.com/GoogleCloudPlatform/spanner-migration-tool/common/constants"
"github.com/GoogleCloudPlatform/spanner-migration-tool/expressions_api"
"github.com/GoogleCloudPlatform/spanner-migration-tool/internal"
"github.com/GoogleCloudPlatform/spanner-migration-tool/mocks"
"github.com/GoogleCloudPlatform/spanner-migration-tool/schema"
"github.com/GoogleCloudPlatform/spanner-migration-tool/sources/common"
"github.com/GoogleCloudPlatform/spanner-migration-tool/spanner/ddl"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)
func TestToSpannerTypeInternal(t *testing.T) {
_, errCheck := toSpannerTypeInternal(schema.Type{"bool", []int64{1, 2, 3}, []int64{1, 2, 3}}, "STRING")
if errCheck == nil {
t.Errorf("Error in boolean to string conversion")
}
_, errCheck = toSpannerTypeInternal(schema.Type{"bool", []int64{1, 2, 3}, []int64{1, 2, 3}}, "INT64")
if errCheck == nil {
t.Errorf("Error in boolean to int64 conversion")
}
_, errCheck = toSpannerTypeInternal(schema.Type{"tinyint", []int64{1, 2, 3}, []int64{1, 2, 3}}, "STRING")
if errCheck == nil {
t.Errorf("Error in tinyint to string conversion")
}
_, errCheck = toSpannerTypeInternal(schema.Type{"tinyint", []int64{1, 2, 3}, []int64{1, 2, 3}}, "INT64")
if errCheck == nil {
t.Errorf("Error in tinyint to int64 conversion")
}
_, errCheck = toSpannerTypeInternal(schema.Type{"double", []int64{1, 2, 3}, []int64{1, 2, 3}}, "STRING")
if errCheck == nil {
t.Errorf("Error in double to string conversion")
}
_, errCheck = toSpannerTypeInternal(schema.Type{"float", []int64{1, 2, 3}, []int64{1, 2, 3}}, "STRING")
if errCheck == nil {
t.Errorf("Error in float to string conversion")
}
_, errCheck = toSpannerTypeInternal(schema.Type{"float", []int64{1, 2, 3}, []int64{1, 2, 3}}, "FLOAT64")
if errCheck == nil {
t.Errorf("Error in float to float64 conversion")
}
_, errCheck = toSpannerTypeInternal(schema.Type{"decimal", []int64{1, 2, 3}, []int64{1, 2, 3}}, "STRING")
if errCheck == nil {
t.Errorf("Error in decimal to string conversion")
}
_, errCheck = toSpannerTypeInternal(schema.Type{"bigint", []int64{1, 2, 3}, []int64{1, 2, 3}}, "STRING")
if errCheck == nil {
t.Errorf("Error in bigint to string conversion")
}
_, errCheck = toSpannerTypeInternal(schema.Type{"int", []int64{1, 2, 3}, []int64{1, 2, 3}}, "STRING")
if errCheck == nil {
t.Errorf("Error in int to string conversion")
}
_, errCheck = toSpannerTypeInternal(schema.Type{"bit", []int64{1, 2, 3}, []int64{1, 2, 3}}, "STRING")
if errCheck != nil {
t.Errorf("Error in bit to string conversion")
}
_, errCheck = toSpannerTypeInternal(schema.Type{"char", []int64{1, 2, 3}, []int64{1, 2, 3}}, "BYTES")
if errCheck != nil {
t.Errorf("Error in char to bytes conversion")
}
_, errCheck = toSpannerTypeInternal(schema.Type{"char", []int64{}, []int64{1, 2, 3}}, "BYTES")
if errCheck != nil {
t.Errorf("Error in char to bytes conversion")
}
_, errCheck = toSpannerTypeInternal(schema.Type{"char", []int64{}, []int64{1, 2, 3}}, "DEFAULT")
if errCheck != nil {
t.Errorf("Error in char to default conversion")
}
_, errCheck = toSpannerTypeInternal(schema.Type{"text", []int64{}, []int64{1, 2, 3}}, "BYTES")
if errCheck != nil {
t.Errorf("Error in text to bytes conversion")
}
_, errCheck = toSpannerTypeInternal(schema.Type{"json", []int64{}, []int64{1, 2, 3}}, "BYTES")
if errCheck != nil {
t.Errorf("Error in json to bytes conversion")
}
_, errCheck = toSpannerTypeInternal(schema.Type{"binary", []int64{1, 2, 3}, []int64{1, 2, 3}}, "STRING")
if errCheck != nil {
t.Errorf("Error in binary to string conversion")
}
_, errCheck = toSpannerTypeInternal(schema.Type{"binary", []int64{1, 2, 3}, []int64{1, 2, 3}}, "DEFAULT")
if errCheck != nil {
t.Errorf("Error in binary to default conversion")
}
spType, errCheck := toSpannerTypeInternal(schema.Type{"varbinary", []int64{10}, []int64{}}, "BYTES")
if errCheck != nil {
t.Errorf("Error in binary to default conversion")
}
assert.Equal(t, "BYTES", spType.Name)
assert.Equal(t, int64(10), spType.Len)
assert.Equal(t, false, spType.IsArray)
_, errCheck = toSpannerTypeInternal(schema.Type{"blob", []int64{1, 2, 3}, []int64{1, 2, 3}}, "STRING")
if errCheck != nil {
t.Errorf("Error in blob to string conversion")
}
_, errCheck = toSpannerTypeInternal(schema.Type{"date", []int64{1, 2, 3}, []int64{1, 2, 3}}, "STRING")
if errCheck == nil {
t.Errorf("Error in date to string conversion")
}
_, errCheck = toSpannerTypeInternal(schema.Type{"datetime", []int64{1, 2, 3}, []int64{1, 2, 3}}, "STRING")
if errCheck == nil {
t.Errorf("Error in datetime to string conversion")
}
_, errCheck = toSpannerTypeInternal(schema.Type{"timestamp", []int64{1, 2, 3}, []int64{1, 2, 3}}, "STRING")
if errCheck == nil {
t.Errorf("Error in timestamp to string conversion")
}
_, errCheck = toSpannerTypeInternal(schema.Type{"time", []int64{1, 2, 3}, []int64{1, 2, 3}}, "STRING")
if errCheck == nil {
t.Errorf("Error in time to string conversion")
}
_, errCheck = toSpannerTypeInternal(schema.Type{"DEFAULT", []int64{1, 2, 3}, []int64{1, 2, 3}}, "")
if errCheck == nil {
t.Errorf("Error in default conversion for unidentified source datatype")
}
}
// This is just a very basic smoke-test for toSpannerType.
func TestToSpannerType(t *testing.T) {
conv := internal.MakeConv()
conv.SetSchemaMode()
name := "test"
tableId := "t1"
srcSchema := schema.Table{
Name: name,
Id: tableId,
ColIds: []string{"c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "c10", "c17"},
ColDefs: map[string]schema.Column{
"c1": {Name: "a", Id: "c1", Type: schema.Type{Name: "int"}},
"c2": {Name: "b", Id: "c2", Type: schema.Type{Name: "double"}},
"c3": {Name: "c", Id: "c3", Type: schema.Type{Name: "tinyint", Mods: []int64{1}}},
"c4": {Name: "d", Id: "c4", Type: schema.Type{Name: "varchar", Mods: []int64{6}}},
"c5": {Name: "e", Id: "c5", Type: schema.Type{Name: "numeric"}},
"c6": {Name: "f", Id: "c6", Type: schema.Type{Name: "timestamp"}},
"c7": {Name: "g", Id: "c7", Type: schema.Type{Name: "json"}},
"c8": {Name: "h", Id: "c8", Type: schema.Type{Name: "date"}},
"c9": {Name: "i", Id: "c9", Type: schema.Type{Name: "timestamp"}},
"c10": {Name: "j", Id: "c10", Type: schema.Type{Name: "bit"}},
"c17": {Name: "k", Id: "c17", Type: schema.Type{Name: "float"}},
},
PrimaryKeys: []schema.Key{schema.Key{ColId: "c1"}},
ForeignKeys: []schema.ForeignKey{schema.ForeignKey{Name: "fk_test", ColIds: []string{"c4"}, ReferTableId: "t2", ReferColumnIds: []string{"c11"}},
schema.ForeignKey{Name: "fk_test2", ColIds: []string{"c1"}, ReferTableId: "t3", ReferColumnIds: []string{"c14"}}},
Indexes: []schema.Index{schema.Index{Name: "index1", Unique: true, Keys: []schema.Key{schema.Key{ColId: "c1", Desc: false}, schema.Key{ColId: "c4", Desc: true}}}},
}
conv.SrcSchema[tableId] = srcSchema
conv.SrcSchema["t2"] = schema.Table{
Name: "ref_table",
Id: "t2",
ColIds: []string{"c11", "c12", "c13"},
ColDefs: map[string]schema.Column{
"c11": {Name: "dref", Id: "c11", Type: schema.Type{Name: "varchar", Mods: []int64{6}}},
"c12": {Name: "b", Id: "c12", Type: schema.Type{Name: "float"}},
"c13": {Name: "c", Id: "c13", Type: schema.Type{Name: "bool"}},
},
PrimaryKeys: []schema.Key{{ColId: "c11"}},
}
conv.SrcSchema["t3"] = schema.Table{
Name: "ref_table2",
Id: "t3",
ColIds: []string{"c14", "c15", "c16"},
ColDefs: map[string]schema.Column{
"c14": {Name: "aref", Id: "c14", Type: schema.Type{Name: "int"}},
"c15": {Name: "b", Id: "c15", Type: schema.Type{Name: "float"}},
"c16": {Name: "c", Id: "c16", Type: schema.Type{Name: "bool"}},
},
PrimaryKeys: []schema.Key{{ColId: "c14"}},
}
conv.UsedNames = map[string]bool{"ref_table": true, "ref_table2": true}
mockAccessor := new(mocks.MockExpressionVerificationAccessor)
ctx := context.Background()
mockAccessor.On("VerifyExpressions", ctx, mock.Anything).Return(internal.VerifyExpressionsOutput{
ExpressionVerificationOutputList: []internal.ExpressionVerificationOutput{
{Result: true, Err: nil, ExpressionDetail: internal.ExpressionDetail{Expression: "(col1 > 0)", Type: "CHECK", Metadata: map[string]string{"tableId": "t1", "colId": "c1", "checkConstraintName": "check1"}, ExpressionId: "expr1"}},
},
})
schemaToSpanner := common.SchemaToSpannerImpl{
ExpressionVerificationAccessor: mockAccessor,
DdlV: &expressions_api.MockDDLVerifier{},
}
assert.Nil(t, schemaToSpanner.SchemaToSpannerDDL(conv, ToDdlImpl{}, internal.AdditionalSchemaAttributes{}))
actual := conv.SpSchema[tableId]
dropComments(&actual) // Don't test comment.
expected := ddl.CreateTable{
Name: name,
Id: tableId,
ColIds: []string{"c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "c10", "c17"},
ColDefs: map[string]ddl.ColumnDef{
"c1": ddl.ColumnDef{Name: "a", Id: "c1", T: ddl.Type{Name: ddl.Int64}},
"c2": ddl.ColumnDef{Name: "b", Id: "c2", T: ddl.Type{Name: ddl.Float64}},
"c3": ddl.ColumnDef{Name: "c", Id: "c3", T: ddl.Type{Name: ddl.Bool}},
"c4": ddl.ColumnDef{Name: "d", Id: "c4", T: ddl.Type{Name: ddl.String, Len: int64(6)}},
"c5": ddl.ColumnDef{Name: "e", Id: "c5", T: ddl.Type{Name: ddl.Numeric}},
"c6": ddl.ColumnDef{Name: "f", Id: "c6", T: ddl.Type{Name: ddl.Timestamp}},
"c7": ddl.ColumnDef{Name: "g", Id: "c7", T: ddl.Type{Name: ddl.JSON}},
"c8": ddl.ColumnDef{Name: "h", Id: "c8", T: ddl.Type{Name: ddl.Date}},
"c9": ddl.ColumnDef{Name: "i", Id: "c9", T: ddl.Type{Name: ddl.Timestamp}},
"c10": ddl.ColumnDef{Name: "j", Id: "c10", T: ddl.Type{Name: ddl.Bytes, Len: ddl.MaxLength}},
"c17": ddl.ColumnDef{Name: "k", Id: "c17", T: ddl.Type{Name: ddl.Float32}},
},
PrimaryKeys: []ddl.IndexKey{ddl.IndexKey{ColId: "c1"}},
ForeignKeys: []ddl.Foreignkey{ddl.Foreignkey{Name: "fk_test", ColIds: []string{"c4"}, ReferTableId: "t2", ReferColumnIds: []string{"c11"}},
ddl.Foreignkey{Name: "fk_test2", ColIds: []string{"c1"}, ReferTableId: "t3", ReferColumnIds: []string{"c14"}}},
Indexes: []ddl.CreateIndex{ddl.CreateIndex{Name: "index1", TableId: tableId, Unique: true, Keys: []ddl.IndexKey{ddl.IndexKey{ColId: "c1", Desc: false}, ddl.IndexKey{ColId: "c4", Desc: true}}}},
}
assert.Equal(t, expected, actual)
expectedIssues := map[string][]internal.SchemaIssue{
"c1": []internal.SchemaIssue{internal.Widened},
}
assert.Equal(t, expectedIssues, conv.SchemaIssues[tableId].ColumnLevelIssues)
commonInfoSchema := common.InfoSchemaImpl{}
tableList, _ := commonInfoSchema.GetIncludedSrcTablesFromConv(conv)
keys := make([]string, 0, len(tableList))
for k := range tableList {
keys = append(keys, k)
}
assert.Equal(t, len(conv.SrcSchema), len(tableList[keys[0]].TableDetails))
}
// This is just a very basic smoke-test for toPostgreSQLDialectType.
func TestToSpannerPostgreSQLDialectType(t *testing.T) {
conv := internal.MakeConv()
conv.SetSchemaMode()
conv.SpDialect = constants.DIALECT_POSTGRESQL
name := "test"
tableId := "t1"
srcSchema := schema.Table{
Name: name,
Id: tableId,
ColIds: []string{"c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "c10", "c17"},
ColDefs: map[string]schema.Column{
"c1": schema.Column{Name: "a", Id: "c1", Type: schema.Type{Name: "int"}},
"c2": schema.Column{Name: "b", Id: "c2", Type: schema.Type{Name: "double"}},
"c3": schema.Column{Name: "c", Id: "c3", Type: schema.Type{Name: "tinyint", Mods: []int64{1}}},
"c4": schema.Column{Name: "d", Id: "c4", Type: schema.Type{Name: "varchar", Mods: []int64{6}}},
"c5": schema.Column{Name: "e", Id: "c5", Type: schema.Type{Name: "numeric"}},
"c6": schema.Column{Name: "f", Id: "c6", Type: schema.Type{Name: "timestamp"}},
"c7": schema.Column{Name: "g", Id: "c7", Type: schema.Type{Name: "json"}},
"c8": schema.Column{Name: "h", Id: "c8", Type: schema.Type{Name: "date"}},
"c9": schema.Column{Name: "i", Id: "c9", Type: schema.Type{Name: "timestamp"}},
"c10": schema.Column{Name: "j", Id: "c10", Type: schema.Type{Name: "bit"}},
"c17": schema.Column{Name: "k", Id: "c17", Type: schema.Type{Name: "float"}},
},
PrimaryKeys: []schema.Key{schema.Key{ColId: "c1"}},
ForeignKeys: []schema.ForeignKey{schema.ForeignKey{Name: "fk_test", ColIds: []string{"c4"}, ReferTableId: "t2", ReferColumnIds: []string{"c11"}},
schema.ForeignKey{Name: "fk_test2", ColIds: []string{"c1"}, ReferTableId: "t3", ReferColumnIds: []string{"c14"}}},
Indexes: []schema.Index{schema.Index{Name: "index1", Unique: true, Keys: []schema.Key{schema.Key{ColId: "c1", Desc: false}, schema.Key{ColId: "c4", Desc: true}}}},
}
conv.SrcSchema[tableId] = srcSchema
conv.SrcSchema["t2"] = schema.Table{
Name: "ref_table",
Id: "t2",
ColIds: []string{"c11", "c12", "c13"},
ColDefs: map[string]schema.Column{
"c11": {Name: "dref", Id: "c11", Type: schema.Type{Name: "varchar", Mods: []int64{6}}},
"c12": {Name: "b", Id: "c12", Type: schema.Type{Name: "float"}},
"c13": {Name: "c", Id: "c13", Type: schema.Type{Name: "bool"}},
},
PrimaryKeys: []schema.Key{{ColId: "c11"}},
}
conv.SrcSchema["t3"] = schema.Table{
Name: "ref_table2",
Id: "t3",
ColIds: []string{"c14", "15", "c16"},
ColDefs: map[string]schema.Column{
"c14": {Name: "aref", Id: "c14", Type: schema.Type{Name: "int"}},
"c15": {Name: "b", Id: "c15", Type: schema.Type{Name: "float"}},
"c16": {Name: "c", Id: "c16", Type: schema.Type{Name: "bool"}},
},
PrimaryKeys: []schema.Key{{ColId: "c14"}},
}
conv.UsedNames = map[string]bool{"ref_table": true, "ref_table2": true}
mockAccessor := new(mocks.MockExpressionVerificationAccessor)
ctx := context.Background()
mockAccessor.On("VerifyExpressions", ctx, mock.Anything).Return(internal.VerifyExpressionsOutput{
ExpressionVerificationOutputList: []internal.ExpressionVerificationOutput{
{Result: true, Err: nil, ExpressionDetail: internal.ExpressionDetail{Expression: "(col1 > 0)", Type: "CHECK", Metadata: map[string]string{"tableId": "t1", "colId": "c1", "checkConstraintName": "check1"}, ExpressionId: "expr1"}},
},
})
schemaToSpanner := common.SchemaToSpannerImpl{
ExpressionVerificationAccessor: mockAccessor,
DdlV: &expressions_api.MockDDLVerifier{},
}
assert.Nil(t, schemaToSpanner.SchemaToSpannerDDL(conv, ToDdlImpl{}, internal.AdditionalSchemaAttributes{}))
actual := conv.SpSchema[tableId]
dropComments(&actual) // Don't test comment.
expected := ddl.CreateTable{
Name: name,
Id: tableId,
ColIds: []string{"c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "c10", "c17"},
ColDefs: map[string]ddl.ColumnDef{
"c1": ddl.ColumnDef{Name: "a", Id: "c1", T: ddl.Type{Name: ddl.Int64}},
"c2": ddl.ColumnDef{Name: "b", Id: "c2", T: ddl.Type{Name: ddl.Float64}},
"c3": ddl.ColumnDef{Name: "c", Id: "c3", T: ddl.Type{Name: ddl.Bool}},
"c4": ddl.ColumnDef{Name: "d", Id: "c4", T: ddl.Type{Name: ddl.String, Len: int64(6)}},
"c5": ddl.ColumnDef{Name: "e", Id: "c5", T: ddl.Type{Name: ddl.Numeric}},
"c6": ddl.ColumnDef{Name: "f", Id: "c6", T: ddl.Type{Name: ddl.Timestamp}},
"c7": ddl.ColumnDef{Name: "g", Id: "c7", T: ddl.Type{Name: ddl.JSON}},
"c8": ddl.ColumnDef{Name: "h", Id: "c8", T: ddl.Type{Name: ddl.Date}},
"c9": ddl.ColumnDef{Name: "i", Id: "c9", T: ddl.Type{Name: ddl.Timestamp}},
"c10": ddl.ColumnDef{Name: "j", Id: "c10", T: ddl.Type{Name: ddl.Bytes, Len: ddl.MaxLength}},
"c17": ddl.ColumnDef{Name: "k", Id: "c17", T: ddl.Type{Name: ddl.Float32}},
},
PrimaryKeys: []ddl.IndexKey{ddl.IndexKey{ColId: "c1"}},
ForeignKeys: []ddl.Foreignkey{ddl.Foreignkey{Name: "fk_test", ColIds: []string{"c4"}, ReferTableId: "t2", ReferColumnIds: []string{"c11"}},
ddl.Foreignkey{Name: "fk_test2", ColIds: []string{"c1"}, ReferTableId: "t3", ReferColumnIds: []string{"c14"}}},
Indexes: []ddl.CreateIndex{ddl.CreateIndex{Name: "index1", TableId: tableId, Unique: true, Keys: []ddl.IndexKey{ddl.IndexKey{ColId: "c1", Desc: false}, ddl.IndexKey{ColId: "c4", Desc: true}}}},
}
assert.Equal(t, expected, actual)
expectedIssues := map[string][]internal.SchemaIssue{
"c1": []internal.SchemaIssue{internal.Widened},
}
assert.Equal(t, expectedIssues, conv.SchemaIssues[tableId].ColumnLevelIssues)
}
func dropComments(t *ddl.CreateTable) {
t.Comment = ""
for _, c := range t.ColIds {
cd := t.ColDefs[c]
cd.Comment = ""
t.ColDefs[c] = cd
}
}
func Test_GetColumnAutoGen(t *testing.T) {
conv := internal.MakeConv()
conv.SrcSequences["s1"] = ddl.Sequence{
Name: "Sequence1",
Id: "s1",
SequenceKind: "BIT REVERSED POSITIVE",
SkipRangeMin: "1",
SkipRangeMax: "2",
StartWithCounter: "3",
}
conv.SpSequences["s1"] = ddl.Sequence{
Name: "Sequence1",
Id: "s1",
SequenceKind: "BIT REVERSED POSITIVE",
SkipRangeMin: "1",
SkipRangeMax: "2",
StartWithCounter: "3",
}
autoGenCol := ddl.AutoGenCol{
Name: "Sequence1",
GenerationType: constants.AUTO_INCREMENT,
}
tc := []struct {
conv *internal.Conv
srcSequence ddl.Sequence
autoGenCol ddl.AutoGenCol
expectedAutoGenCol ddl.AutoGenCol
colId string
tableId string
}{
{
conv: conv,
srcSequence: ddl.Sequence{
Name: "Sequence1",
Id: "s1",
SequenceKind: "Auto Increment",
SkipRangeMin: "1",
SkipRangeMax: "2",
StartWithCounter: "3",
},
autoGenCol: autoGenCol,
expectedAutoGenCol: ddl.AutoGenCol{
Name: "Sequence1",
GenerationType: constants.SEQUENCE,
},
colId: "c1",
tableId: "t1",
},
}
for _, tt := range tc {
var toddl = ToDdlImpl{}
autoGenCol, _ := toddl.GetColumnAutoGen(tt.conv, tt.autoGenCol, tt.colId, tt.tableId)
assert.Equal(t, &tt.expectedAutoGenCol, autoGenCol)
assert.Equal(t, len(tt.conv.SpSequences[tt.srcSequence.Id].ColumnsUsingSeq[tt.tableId]), 1)
}
}