-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathddl_test.go
More file actions
71 lines (68 loc) · 1.86 KB
/
ddl_test.go
File metadata and controls
71 lines (68 loc) · 1.86 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
package nosql
import (
"testing"
)
func TestGenerateDDLFromDefination(t *testing.T) {
type args struct {
table Table
}
tests := []struct {
name string
args args
want string
}{
{
"simple ddl generate test",
args{Table{tableName: "User", columns: map[string]Column{"ObjectID": Column{columnName: "ObjectID", columnType: "VARCHAR", columnLength: 32}}}},
"CREATE TABLE IF NOT EXISTS User (ObjectID VARCHAR(32));",
},
{
"complex ddl generate test",
args{
Table{
"User4",
map[string]Column{
"ObjectID": Column{columnName: "ObjectID", columnType: "VARCHAR", columnLength: 32},
"UserName": Column{columnName: "UserName", columnType: "VARCHAR", columnLength: 32},
"Address": Column{columnName: "Address", columnType: "VARCHAR", columnLength: 128},
"Age": Column{columnName: "Age", columnType: "INTEGER", columnLength: 8},
},
},
},
"CREATE TABLE IF NOT EXISTS User4 (ObjectID VARCHAR(32),UserName VARCHAR(32),Address VARCHAR(128),Age INTEGER(8));",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := GenerateDDLFromDefination(tt.args.table); got != tt.want {
t.Errorf("GenerateDDLFromDefination() = %v, want %v", got, tt.want)
}
})
}
}
func TestGenerateAlterModifyDDL(t *testing.T) {
type args struct {
table Table
}
tests := []struct {
name string
args args
want string
}{
{
"simple test",
args{Table{"User3", map[string]Column{
"UserName": Column{"UserName", "VARCHAR", 32},
"Age": Column{"Age", "INTEGER", 2},
}}},
"ALTER TABLE User3 MODIFY UserName VARCHAR(32);ALTER TABLE User3 MODIFY Age INTEGER(2);",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := GenerateAlterModifyDDL(tt.args.table); got != tt.want {
t.Errorf("GenerateAlterModifyDDL() = %v, want %v", got, tt.want)
}
})
}
}