-
Notifications
You must be signed in to change notification settings - Fork 27
/
prepared_statement_test.go
56 lines (46 loc) · 1.3 KB
/
prepared_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
47
48
49
50
51
52
53
54
55
56
package godb
import (
"database/sql"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestGetQueryable(t *testing.T) {
Convey("Given a connection to a database", t, func() {
db := fixturesSetup(t)
defer db.Close()
sqlQuery := "SELECT * FROM dummies"
testCache := func(cache *StmtCache) {
Convey("getQueryable returns a wrapper if the cache is disabled", func() {
cache.Disable()
q, err := db.getQueryable(sqlQuery)
So(err, ShouldBeNil)
So(q, ShouldHaveSameTypeAs, &queryWrapper{})
})
Convey("getQueryable returns a prepared statement if the cache is enabled", func() {
cache.Enable()
q, err := db.getQueryable(sqlQuery)
So(err, ShouldBeNil)
So(q, ShouldHaveSameTypeAs, &sql.Stmt{})
Convey("getQueryable returns cached prepared statements", func() {
q2, err := db.getQueryable(sqlQuery)
So(err, ShouldBeNil)
So(q2, ShouldEqual, q)
})
Convey("getQueryable returns a new prepared statements after a clear cache", func() {
cache.Clear()
q2, err := db.getQueryable(sqlQuery)
So(err, ShouldBeNil)
So(q2, ShouldNotEqual, q)
})
})
}
Convey("Without Tx", func() {
testCache(db.StmtCacheDB())
})
Convey("With Tx", func() {
db.Begin()
testCache(db.StmtCacheTx())
db.Rollback()
})
})
}