-
Notifications
You must be signed in to change notification settings - Fork 4
/
persistence_test.go
51 lines (44 loc) · 1.45 KB
/
persistence_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
package factory
import "testing"
func TestInsertSQL(t *testing.T) {
table := "test_table"
fields := []string{"test_field1", "test_field2", "test_field3"}
sql := insertSQL(table, fields)
if sql != `INSERT INTO test_table (test_field1,test_field2,test_field3) VALUES (?,?,?)` {
t.Errorf("insertSQL failed with sql=%s", sql)
}
}
func TestSelectSQL(t *testing.T) {
table := "test_table"
selectFields := []string{"test_field1", "test_field2", "test_field3"}
primaryFields := []string{"test_primary_field1"}
sql := selectSQL(table, selectFields, primaryFields)
if sql != `SELECT test_field1,test_field2,test_field3 FROM test_table WHERE test_primary_field1=?` {
t.Errorf("selectSQL failed with sql=%s", sql)
}
}
func TestDeleteSQL(t *testing.T) {
table := "test_table"
primaryFields := []string{"test_primary_field1"}
sql := deleteSQL(table, primaryFields)
if sql != `DELETE FROM test_table WHERE test_primary_field1=?` {
t.Errorf("deleteSQL failed with sql=%s", sql)
}
}
func TestWhereClause(t *testing.T) {
fields := []string{}
sql := whereClause(fields)
if sql != `` {
t.Errorf("whereClause failed with sql=%s", sql)
}
fields = []string{"test_field1"}
sql = whereClause(fields)
if sql != `WHERE test_field1=?` {
t.Errorf("whereClause failed with sql=%s", sql)
}
fields = []string{"test_field1", "test_field2"}
sql = whereClause(fields)
if sql != `WHERE test_field1=? AND test_field2=?` {
t.Errorf("whereClause failed with sql=%s", sql)
}
}