-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdml_test.go
119 lines (108 loc) · 4.69 KB
/
dml_test.go
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
package sqlsmith
import (
"math/rand"
"testing"
)
var testSchema = [][5]string{
{"community", "comments", "BASE TABLE", "id", "int(11)"},
{"community", "comments", "BASE TABLE", "owner", "varchar(255)"},
{"community", "comments", "BASE TABLE", "repo", "varchar(255)"},
{"community", "comments", "BASE TABLE", "comment_id", "int(11)"},
{"community", "comments", "BASE TABLE", "comment_type", "varchar(128)"},
{"community", "comments", "BASE TABLE", "pull_number", "int(11)"},
{"community", "comments", "BASE TABLE", "body", "text"},
{"community", "comments", "BASE TABLE", "user", "varchar(255)"},
{"community", "comments", "BASE TABLE", "url", "varchar(1023)"},
{"community", "comments", "BASE TABLE", "association", "varchar(255)"},
{"community", "comments", "BASE TABLE", "relation", "varchar(255)"},
{"community", "comments", "BASE TABLE", "created_at", "timestamp"},
{"community", "comments", "BASE TABLE", "updated_at", "timestamp"},
{"community", "picks", "BASE TABLE", "id", "int(11)"},
{"community", "picks", "BASE TABLE", "season", "int(11)"},
{"community", "picks", "BASE TABLE", "task_id", "int(11)"},
{"community", "picks", "BASE TABLE", "teamID", "int(11)"},
{"community", "picks", "BASE TABLE", "user", "varchar(255)"},
{"community", "picks", "BASE TABLE", "pull_number", "int(11)"},
{"community", "picks", "BASE TABLE", "status", "varchar(128)"},
{"community", "picks", "BASE TABLE", "created_at", "timestamp"},
{"community", "picks", "BASE TABLE", "updated_at", "timestamp"},
{"community", "picks", "BASE TABLE", "closed_at", "timestamp"},
{"community", "pulls", "BASE TABLE", "id", "int(11)"},
{"community", "pulls", "BASE TABLE", "owner", "varchar(255)"},
{"community", "pulls", "BASE TABLE", "repo", "varchar(255)"},
{"community", "pulls", "BASE TABLE", "pull_number", "int(11)"},
{"community", "pulls", "BASE TABLE", "title", "text"},
{"community", "pulls", "BASE TABLE", "body", "text"},
{"community", "pulls", "BASE TABLE", "user", "varchar(255)"},
{"community", "pulls", "BASE TABLE", "association", "varchar(255)"},
{"community", "pulls", "BASE TABLE", "relation", "varchar(255)"},
{"community", "pulls", "BASE TABLE", "label", "text"},
{"community", "pulls", "BASE TABLE", "status", "varchar(128)"},
{"community", "pulls", "BASE TABLE", "created_at", "timestamp"},
{"community", "pulls", "BASE TABLE", "updated_at", "timestamp"},
{"community", "pulls", "BASE TABLE", "closed_at", "timestamp"},
{"community", "pulls", "BASE TABLE", "merged_at", "timestamp"},
{"community", "tasks", "BASE TABLE", "id", "int(11)"},
{"community", "tasks", "BASE TABLE", "season", "int(11)"},
{"community", "tasks", "BASE TABLE", "complete_user", "varchar(255)"},
{"community", "tasks", "BASE TABLE", "complete_team", "int(11)"},
{"community", "tasks", "BASE TABLE", "owner", "varchar(255)"},
{"community", "tasks", "BASE TABLE", "repo", "varchar(255)"},
{"community", "tasks", "BASE TABLE", "title", "varchar(2047)"},
{"community", "tasks", "BASE TABLE", "issue_number", "int(11)"},
{"community", "tasks", "BASE TABLE", "pull_number", "int(11)"},
{"community", "tasks", "BASE TABLE", "level", "varchar(255)"},
{"community", "tasks", "BASE TABLE", "min_score", "int(11)"},
{"community", "tasks", "BASE TABLE", "score", "int(11)"},
{"community", "tasks", "BASE TABLE", "status", "varchar(255)"},
{"community", "tasks", "BASE TABLE", "created_at", "timestamp"},
{"community", "tasks", "BASE TABLE", "expired", "varchar(255)"},
{"community", "teams", "BASE TABLE", "id", "int(11)"},
{"community", "teams", "BASE TABLE", "season", "int(11)"},
{"community", "teams", "BASE TABLE", "name", "varchar(255)"},
{"community", "teams", "BASE TABLE", "issue_url", "varchar(1023)"},
{"community", "users", "BASE TABLE", "id", "int(11)"},
{"community", "users", "BASE TABLE", "season", "int(11)"},
{"community", "users", "BASE TABLE", "user", "varchar(255)"},
{"community", "users", "BASE TABLE", "team_id", "int(11)"},
}
var testSchemaName = "community"
func TestSQLSmith_Select(t *testing.T) {
ss := New()
ss.LoadSchema(testSchema)
ss.SetDB(testSchemaName)
for i := 0; i < 500; i++ {
sql, err := ss.SelectStmt(1 + rand.Intn(5))
if err != nil {
t.Log(sql, err)
}
}
sql, _ := ss.SelectStmt(6)
t.Log(sql)
}
func TestSQLSmith_Update(t *testing.T) {
ss := New()
ss.LoadSchema(testSchema)
ss.SetDB(testSchemaName)
for i := 0; i < 1000; i++ {
sql, err := ss.UpdateStmt()
if err != nil {
t.Log(sql, err)
}
}
sql, _ := ss.UpdateStmt()
t.Log(sql)
}
func TestSQLSmith_Insert(t *testing.T) {
ss := New()
ss.LoadSchema(testSchema)
ss.SetDB(testSchemaName)
for i := 0; i < 1000; i++ {
sql, err := ss.InsertStmtAST()
if err != nil {
t.Log(sql, err)
}
}
sql, err := ss.InsertStmtAST()
t.Log(sql, err)
}