Skip to content

Commit 92e8e91

Browse files
committed
fix tests
1 parent 8e385b4 commit 92e8e91

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

Diff for: examples/booktest/mysql/db_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@ func TestBooks(t *testing.T) {
155155
Title: "my book title",
156156
Yr: 2016,
157157
})
158-
for book := range rows.Iterate() {
158+
159+
// We need to collect the iterator elements to avoid panic when we make other db queries in the loop.
160+
for _, book := range slices.Collect(rows.Iterate()) {
159161
t.Logf("Book %d (%s): %s available: %s\n", book.BookID, book.BookType, book.Title, book.Available.Format(time.RFC822Z))
160162
author, err := dq.GetAuthor(ctx, book.AuthorID)
161163
if err != nil {

Diff for: examples/booktest/postgresql/db_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ func TestBooks(t *testing.T) {
144144
Title: "my book title",
145145
Year: 2016,
146146
})
147-
for book := range rows.Iterate() {
147+
148+
// We need to collect the iterator elements to avoid panic when we make other db queries in the loop.
149+
for _, book := range slices.Collect(rows.Iterate()) {
148150
t.Logf("Book %d (%s): %s available: %s\n", book.BookID, book.BookType, book.Title, book.Available.Time.Format(time.RFC822Z))
149151
author, err := dq.GetAuthor(ctx, book.AuthorID)
150152
if err != nil {

Diff for: examples/booktest/sqlite/db_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ func TestBooks(t *testing.T) {
143143
Title: "my book title",
144144
Yr: 2016,
145145
})
146-
for book := range rows.Iterate() {
146+
147+
// We need to collect the iterator elements to avoid panic when we make other db queries in the loop.
148+
for _, book := range slices.Collect(rows.Iterate()) {
147149
t.Logf("Book %d (%s): %s available: %s\n", book.BookID, book.BookType, book.Title, book.Available.Format(time.RFC822Z))
148150
author, err := dq.GetAuthor(ctx, book.AuthorID)
149151
if err != nil {

0 commit comments

Comments
 (0)