forked from Masterminds/squirrel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
statement_test.go
46 lines (37 loc) · 1.12 KB
/
statement_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
package squirrel
import (
"database/sql"
"testing"
"github.com/lann/builder"
"github.com/stretchr/testify/assert"
)
func TestStatementBuilder(t *testing.T) {
db := &DBStub{}
sb := StatementBuilder.RunWith(db)
sb.Select("test").Exec()
assert.Equal(t, "SELECT test", db.LastExecSql)
}
func TestStatementBuilderPlaceholderFormat(t *testing.T) {
db := &DBStub{}
sb := StatementBuilder.RunWith(db).PlaceholderFormat(Dollar)
sb.Select("test").Where("x = ?").Exec()
assert.Equal(t, "SELECT test WHERE x = $1", db.LastExecSql)
}
func TestRunWithDB(t *testing.T) {
db := &sql.DB{}
assert.NotPanics(t, func() {
builder.GetStruct(Select().RunWith(db))
builder.GetStruct(Insert("t").RunWith(db))
builder.GetStruct(Update("t").RunWith(db))
builder.GetStruct(Delete("t").RunWith(db))
}, "RunWith(*sql.DB) should not panic")
}
func TestRunWithTx(t *testing.T) {
tx := &sql.Tx{}
assert.NotPanics(t, func() {
builder.GetStruct(Select().RunWith(tx))
builder.GetStruct(Insert("t").RunWith(tx))
builder.GetStruct(Update("t").RunWith(tx))
builder.GetStruct(Delete("t").RunWith(tx))
}, "RunWith(*sql.Tx) should not panic")
}