Skip to content

Commit cff8570

Browse files
committed
fix test
1 parent 745fc61 commit cff8570

File tree

5 files changed

+9
-32
lines changed

5 files changed

+9
-32
lines changed

template/cache_test.go

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package template
33
import (
44
"context"
55
"database/sql/driver"
6-
"errors"
7-
"fmt"
86
"os"
97
"testing"
108

@@ -33,7 +31,7 @@ func TestCacheRows(t *testing.T) {
3331
assert.NoError(t, err)
3432
defer conn.Close()
3533

36-
var cacheRows driver.Rows
34+
var cacheRows *CacheRows
3735
err = conn.Raw(func(driverConn any) error {
3836
conn := driverConn.(driver.Conn)
3937
stmt, err := conn.Prepare("SELECT id, name FROM users")
@@ -46,31 +44,10 @@ func TestCacheRows(t *testing.T) {
4644
if err != nil {
4745
return err
4846
}
49-
cacheRows = NewCachedRows(rows)
47+
cacheRows = NewCacheRows(rows)
5048
defer cacheRows.Close()
5149

52-
dest := make([]driver.Value, 2)
53-
if err := cacheRows.Next(dest); err != nil {
54-
return err
55-
}
56-
57-
id, ok := dest[0].(int64)
58-
if !ok {
59-
return fmt.Errorf("dest[0] is not int, got=%T", dest[0])
60-
}
61-
if id != 1 {
62-
return errors.New("id != 1")
63-
}
64-
65-
name, ok := dest[1].([]byte)
66-
if !ok {
67-
return fmt.Errorf("dest[1] is not string, got=%T", dest[1])
68-
}
69-
if string(name) != "Alice" {
70-
return errors.New("name != Alice")
71-
}
72-
73-
return nil
50+
return cacheRows.createCache()
7451
})
7552
if err != nil {
7653
t.Error(err)

template/driver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func (r *CacheRows) Clone() *CacheRows {
153153
}
154154
}
155155

156-
func NewCachedRows(inner driver.Rows) *CacheRows {
156+
func NewCacheRows(inner driver.Rows) *CacheRows {
157157
return &CacheRows{inner: inner}
158158
}
159159

template/driver.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func (r *CacheRows) Clone() *CacheRows {
152152
}
153153
}
154154

155-
func NewCachedRows(inner driver.Rows) *CacheRows {
155+
func NewCacheRows(inner driver.Rows) *CacheRows {
156156
return &CacheRows{inner: inner}
157157
}
158158

template/stmt.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,15 @@ func replaceFn(ctx context.Context, key string) (*CacheRows, error) {
185185
if err != nil {
186186
return nil, err
187187
}
188-
res = NewCachedRows(rows)
188+
res = NewCacheRows(rows)
189189
} else {
190190
stmt := ctx.Value(stmtKey{}).(*CustomCacheStatement)
191191
args := ctx.Value(argsKey{}).([]driver.Value)
192192
rows, err := stmt.inner.Query(args)
193193
if err != nil {
194194
return nil, err
195195
}
196-
res = NewCachedRows(rows)
196+
res = NewCacheRows(rows)
197197
}
198198

199199
if err := res.createCache(); err != nil {

template/stmt.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,15 @@ func replaceFn(ctx context.Context, key string) (*CacheRows, error) {
185185
if err != nil {
186186
return nil, err
187187
}
188-
res = NewCachedRows(rows)
188+
res = NewCacheRows(rows)
189189
} else {
190190
stmt := ctx.Value(stmtKey{}).(*CustomCacheStatement)
191191
args := ctx.Value(argsKey{}).([]driver.Value)
192192
rows, err := stmt.inner.Query(args)
193193
if err != nil {
194194
return nil, err
195195
}
196-
res = NewCachedRows(rows)
196+
res = NewCacheRows(rows)
197197
}
198198

199199
if err := res.createCache(); err != nil {

0 commit comments

Comments
 (0)