Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
viewsharp committed Oct 19, 2024
1 parent 8e385b4 commit f18de44
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
5 changes: 4 additions & 1 deletion examples/booktest/mysql/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package booktest
import (
"context"
"database/sql"
"slices"
"testing"
"time"

Expand Down Expand Up @@ -155,7 +156,9 @@ func TestBooks(t *testing.T) {
Title: "my book title",
Yr: 2016,
})
for book := range rows.Iterate() {

// We need to collect the iterator elements to avoid panic when we make other db queries in the loop.
for _, book := range slices.Collect(rows.Iterate()) {
t.Logf("Book %d (%s): %s available: %s\n", book.BookID, book.BookType, book.Title, book.Available.Format(time.RFC822Z))
author, err := dq.GetAuthor(ctx, book.AuthorID)
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion examples/booktest/postgresql/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package booktest

import (
"context"
"slices"
"testing"
"time"

Expand Down Expand Up @@ -144,7 +145,9 @@ func TestBooks(t *testing.T) {
Title: "my book title",
Year: 2016,
})
for book := range rows.Iterate() {

// We need to collect the iterator elements to avoid panic when we make other db queries in the loop.
for _, book := range slices.Collect(rows.Iterate()) {
t.Logf("Book %d (%s): %s available: %s\n", book.BookID, book.BookType, book.Title, book.Available.Time.Format(time.RFC822Z))
author, err := dq.GetAuthor(ctx, book.AuthorID)
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion examples/booktest/sqlite/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package booktest

import (
"context"
"slices"
"testing"
"time"

Expand Down Expand Up @@ -143,7 +144,9 @@ func TestBooks(t *testing.T) {
Title: "my book title",
Yr: 2016,
})
for book := range rows.Iterate() {

// We need to collect the iterator elements to avoid panic when we make other db queries in the loop.
for _, book := range slices.Collect(rows.Iterate()) {
t.Logf("Book %d (%s): %s available: %s\n", book.BookID, book.BookType, book.Title, book.Available.Format(time.RFC822Z))
author, err := dq.GetAuthor(ctx, book.AuthorID)
if err != nil {
Expand Down

0 comments on commit f18de44

Please sign in to comment.