Repository navigation
Expand file tree
/
Copy pathstore_errors_test.go
More file actions
70 lines (65 loc) · 2.13 KB
/
Copy pathstore_errors_test.go
File metadata and controls
70 lines (65 loc) · 2.13 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package pubengine
import (
"context"
"database/sql"
"database/sql/driver"
"errors"
"io"
"strings"
"testing"
"time"
)
type interruptedDriver struct{}
type interruptedConn struct{}
type interruptedRows struct {
sent bool
summary bool
}
func (interruptedDriver) Open(string) (driver.Conn, error) { return interruptedConn{}, nil }
func (interruptedConn) Prepare(string) (driver.Stmt, error) { return nil, errors.New("not supported") }
func (interruptedConn) Close() error { return nil }
func (interruptedConn) Begin() (driver.Tx, error) { return nil, errors.New("not supported") }
func (interruptedConn) QueryContext(_ context.Context, query string, _ []driver.NamedValue) (driver.Rows, error) {
return &interruptedRows{summary: strings.Contains(query, "SELECT slug,title,date,tags,summary,published,revision")}, nil
}
func (r *interruptedRows) Columns() []string {
if r.summary {
return []string{"slug", "title", "date", "tags", "summary", "published", "revision"}
}
return []string{"slug", "title", "date", "tags", "summary", "content", "published", "revision"}
}
func (*interruptedRows) Close() error { return nil }
func (r *interruptedRows) Next(values []driver.Value) error {
if r.sent {
return io.ErrUnexpectedEOF
}
r.sent = true
if r.summary {
copy(values, []driver.Value{"post", "Post", "2026-01-01", ",go,", "summary", int64(1), int64(1)})
return nil
}
copy(values, []driver.Value{"post", "Post", "2026-01-01", ",go,", "summary", "body", int64(1), int64(1)})
return nil
}
func init() { sql.Register("pubengine-interrupted-rows", interruptedDriver{}) }
func TestPostIterationErrorsAreNotCached(t *testing.T) {
db, err := sql.Open("pubengine-interrupted-rows", "")
if err != nil {
t.Fatal(err)
}
defer db.Close()
s := &Store{db: db}
if _, err := s.ListPosts(""); !errors.Is(err, io.ErrUnexpectedEOF) {
t.Fatal(err)
}
if _, err := s.ListAllPosts(); !errors.Is(err, io.ErrUnexpectedEOF) {
t.Fatal(err)
}
c := NewPostCache(s, time.Hour)
if _, err := c.ListPosts(""); !errors.Is(err, io.ErrUnexpectedEOF) {
t.Fatal(err)
}
if c.valid() {
t.Fatal("incomplete listing was cached")
}
}