forked from Masterminds/squirrel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
squirrel_ctx_test.go
55 lines (44 loc) · 1.25 KB
/
squirrel_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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// +build go1.8
package squirrel
import (
"context"
"database/sql"
"testing"
"github.com/stretchr/testify/assert"
)
func (s *DBStub) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error) {
s.LastPrepareSql = query
s.PrepareCount++
return nil, nil
}
func (s *DBStub) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) {
s.LastExecSql = query
s.LastExecArgs = args
return nil, nil
}
func (s *DBStub) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) {
s.LastQuerySql = query
s.LastQueryArgs = args
return nil, nil
}
func (s *DBStub) QueryRowContext(ctx context.Context, query string, args ...interface{}) RowScanner {
s.LastQueryRowSql = query
s.LastQueryRowArgs = args
return &Row{RowScanner: &RowStub{}}
}
var ctx = context.Background()
func TestExecContextWith(t *testing.T) {
db := &DBStub{}
ExecContextWith(ctx, db, sqlizer)
assert.Equal(t, sqlStr, db.LastExecSql)
}
func TestQueryContextWith(t *testing.T) {
db := &DBStub{}
QueryContextWith(ctx, db, sqlizer)
assert.Equal(t, sqlStr, db.LastQuerySql)
}
func TestQueryRowContextWith(t *testing.T) {
db := &DBStub{}
QueryRowContextWith(ctx, db, sqlizer)
assert.Equal(t, sqlStr, db.LastQueryRowSql)
}