forked from Masterminds/squirrel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
insert_ctx_test.go
41 lines (28 loc) · 807 Bytes
/
insert_ctx_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
// +build go1.8
package squirrel
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestInsertBuilderContextRunners(t *testing.T) {
db := &DBStub{}
b := Insert("test").Values(1).RunWith(db)
expectedSql := "INSERT INTO test VALUES (?)"
b.ExecContext(ctx)
assert.Equal(t, expectedSql, db.LastExecSql)
b.QueryContext(ctx)
assert.Equal(t, expectedSql, db.LastQuerySql)
b.QueryRowContext(ctx)
assert.Equal(t, expectedSql, db.LastQueryRowSql)
err := b.ScanContext(ctx)
assert.NoError(t, err)
}
func TestInsertBuilderContextNoRunner(t *testing.T) {
b := Insert("test").Values(1)
_, err := b.ExecContext(ctx)
assert.Equal(t, RunnerNotSet, err)
_, err = b.QueryContext(ctx)
assert.Equal(t, RunnerNotSet, err)
err = b.ScanContext(ctx)
assert.Equal(t, RunnerNotSet, err)
}