-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsquirrel_part_test.go
More file actions
70 lines (64 loc) · 1.42 KB
/
squirrel_part_test.go
File metadata and controls
70 lines (64 loc) · 1.42 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
package lore
import (
"fmt"
"testing"
"github.com/Masterminds/squirrel"
)
func TestNewSqlPart(t *testing.T) {
newSqlPart(squirrel.Eq{
_TEST_DB_FIELDNAME_FIELD: _TEST_MODEL_FIELD,
})
newSqlPart(map[string]interface{}{
_TEST_DB_FIELDNAME_FIELD: _TEST_MODEL_FIELD,
})
}
func TestSqlPartToSql(t *testing.T) {
// Test invalid input resilience.
sp := newSqlPart(10)
sql, args, err := sp.ToSql()
if err == nil {
t.Error("Expect non-nil err since invalid pred")
return
}
// Test squirrel interface.
sp = newSqlPart(squirrel.Eq{
_TEST_DB_FIELDNAME_FIELD: _TEST_MODEL_FIELD,
})
sql, args, err = sp.ToSql()
if sql != fmt.Sprintf("%s = ?", _TEST_DB_FIELDNAME_FIELD) {
t.Errorf("Invalid sql generated: %s", sql)
return
}
arg0, ok := args[0].(int64)
if !ok {
t.Error("Unexpected error casting to int64")
return
}
if arg0 != _TEST_MODEL_FIELD {
t.Errorf("Expected %d, got %d", _TEST_MODEL_FIELD, arg0)
return
}
// Test string.
sp = newSqlPart(
fmt.Sprintf("%s = ?", _TEST_DB_FIELDNAME_FIELD),
_TEST_MODEL_FIELD,
)
sql, args, err = sp.ToSql()
if err != nil {
t.Error(err)
return
}
if sql != fmt.Sprintf("%s = ?", _TEST_DB_FIELDNAME_FIELD) {
t.Errorf("Invalid sql generated: %s", sql)
return
}
arg0, ok = args[0].(int64)
if !ok {
t.Error("Unexpected error casting to int64")
return
}
if arg0 != _TEST_MODEL_FIELD {
t.Errorf("Expected %d, got %d", _TEST_MODEL_FIELD, arg0)
return
}
}