-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathquery_test.go
More file actions
50 lines (42 loc) · 1.5 KB
/
Copy pathquery_test.go
File metadata and controls
50 lines (42 loc) · 1.5 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
package struct2sql_test
import (
"fmt"
"testing"
s2s "fallen.world/mingchoi/struct2sql"
)
func TestCreateTableQuery(t *testing.T) {
sqlTable := s2s.AnalyzeStruct(&Monster{})
expected := "CREATE TABLE monster (id int NOT NULL AUTO_INCREMENT, name varchar(255), level int, health double, boss bool, spawn datetime, birth date, mid int, PRIMARY KEY (id), FOREIGN KEY (mid) REFERENCES map(id));"
if s2s.CreateTableQuery(sqlTable) != expected {
fmt.Println(s2s.CreateTableQuery(sqlTable))
t.Error("Query for create table incorrect")
}
}
func TestInsertQuery(t *testing.T) {
model := Monster{}
expected := "INSERT INTO monster(name, level, health, boss, spawn, birth, mid) VALUES(?, ?, ?, ?, ?, ?, ?);"
if s2s.InsertQuery(model) != expected {
t.Error("Query for insert row incorrect")
}
}
func TestSelectQuery(t *testing.T) {
model := Monster{}
expected := "SELECT id, name, level, health, boss, spawn, birth, mid FROM monster WHERE id = 0;"
if s2s.SelectQuery(model, "id = 0") != expected {
t.Error("Query for insert row incorrect")
}
}
func TestUpdateQuery(t *testing.T) {
model := Monster{}
expected := "UPDATE monster SET name=?, level=?, health=?, boss=?, spawn=?, birth=?, mid=? WHERE id = 0;"
if s2s.UpdateQuery(model, "id = 0") != expected {
t.Error("Query for insert row incorrect")
}
}
func TestDeleteQuery(t *testing.T) {
model := Monster{}
expected := "DELETE FROM monster WHERE id = 0;"
if s2s.DeleteQuery(model, "id = 0") != expected {
t.Error("Query for insert row incorrect")
}
}