forked from Masterminds/squirrel
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdelete_ctx_test.go
41 lines (28 loc) · 847 Bytes
/
delete_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 TestDeleteBuilderContextRunners(t *testing.T) {
db := &DBStub{}
b := Delete("test").Where("x = ?", 1).RunWith(db)
expectedSql := "DELETE FROM test WHERE x = ?"
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 TestDeleteBuilderContextNoRunner(t *testing.T) {
b := Delete("test").Where("x != ?", 0).Suffix("RETURNING x")
_, 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)
}