@@ -15,81 +15,84 @@ const (
15
15
driverName = "engine_tests"
16
16
)
17
17
18
- func TestEngine_Query (t * testing.T ) {
19
- e := newEngine (t )
20
- gosql .Register (driverName , e )
21
- testQuery (t , e ,
18
+ func TestQueries (t * testing.T ) {
19
+ testQuery (t ,
22
20
"SELECT i FROM mytable;" ,
23
21
[][]interface {}{{int64 (1 )}, {int64 (2 )}, {int64 (3 )}},
24
22
)
25
23
26
- testQuery (t , e ,
24
+ testQuery (t ,
27
25
"SELECT i FROM mytable WHERE i = 2;" ,
28
26
[][]interface {}{{int64 (2 )}},
29
27
)
30
28
31
- testQuery (t , e ,
29
+ testQuery (t ,
32
30
"SELECT i FROM mytable ORDER BY i DESC;" ,
33
31
[][]interface {}{{int64 (3 )}, {int64 (2 )}, {int64 (1 )}},
34
32
)
35
33
36
- testQuery (t , e ,
34
+ testQuery (t ,
37
35
"SELECT i FROM mytable WHERE s = 'a' ORDER BY i DESC;" ,
38
36
[][]interface {}{{int64 (1 )}},
39
37
)
40
38
41
- testQuery (t , e ,
39
+ testQuery (t ,
42
40
"SELECT i FROM mytable WHERE s = 'a' ORDER BY i DESC LIMIT 1;" ,
43
41
[][]interface {}{{int64 (1 )}},
44
42
)
45
43
46
- testQuery (t , e ,
44
+ testQuery (t ,
47
45
"SELECT COUNT(*) FROM mytable;" ,
48
46
[][]interface {}{{int64 (3 )}},
49
47
)
50
48
51
- testQuery (t , e ,
49
+ testQuery (t ,
52
50
"SELECT COUNT(*) AS c FROM mytable;" ,
53
51
[][]interface {}{{int64 (3 )}},
54
52
)
55
53
}
56
54
57
- func testQuery (t * testing.T , e * sqle.Engine , q string , r [][]interface {}) {
58
- assert := require .New (t )
55
+ func testQuery (t * testing.T , q string , r [][]interface {}) {
56
+ t .Run (q , func (t * testing.T ) {
57
+ assert := require .New (t )
59
58
60
- db , err := gosql .Open (driverName , "" )
61
- assert .NoError (err )
62
- defer func () { assert .NoError (db .Close ()) }()
59
+ e := newEngine (t )
60
+ sqle .DefaultEngine = e
63
61
64
- res , err := db . Query ( q )
65
- assert .NoError (err )
66
- defer func () { assert .NoError (res .Close ()) }()
62
+ db , err := gosql . Open ( sqle . DriverName , "" )
63
+ assert .NoError (err )
64
+ defer func () { assert .NoError (db .Close ()) }()
67
65
68
- cols , err := res . Columns ( )
69
- assert .NoError (err )
70
- assert .Equal ( len ( r [ 0 ]), len ( cols ) )
66
+ res , err := db . Query ( q )
67
+ assert .NoError (err )
68
+ defer func () { assert .NoError ( res . Close ()) }( )
71
69
72
- vals := make ([]interface {}, len (cols ))
73
- valPtrs := make ([]interface {}, len (cols ))
74
- for i := 0 ; i < len (cols ); i ++ {
75
- valPtrs [i ] = & vals [i ]
76
- }
70
+ cols , err := res .Columns ()
71
+ assert .NoError (err )
72
+ assert .Equal (len (r [0 ]), len (cols ))
77
73
78
- i := 0
79
- for {
80
- if ! res . Next () {
81
- break
74
+ vals := make ([] interface {}, len ( cols ))
75
+ valPtrs := make ([] interface {}, len ( cols ))
76
+ for i := 0 ; i < len ( cols ); i ++ {
77
+ valPtrs [ i ] = & vals [ i ]
82
78
}
83
79
84
- err := res .Scan (valPtrs ... )
85
- assert .NoError (err )
80
+ i := 0
81
+ for {
82
+ if ! res .Next () {
83
+ break
84
+ }
85
+
86
+ err := res .Scan (valPtrs ... )
87
+ assert .NoError (err )
86
88
87
- assert .Equal (r [i ], vals )
88
- i ++
89
- }
89
+ assert .Equal (r [i ], vals )
90
+ i ++
91
+ }
90
92
91
- assert .NoError (res .Err ())
92
- assert .Equal (len (r ), i )
93
+ assert .NoError (res .Err ())
94
+ assert .Equal (len (r ), i )
95
+ })
93
96
}
94
97
95
98
func newEngine (t * testing.T ) * sqle.Engine {
0 commit comments