Skip to content

Commit

Permalink
examples: Add missing Close calls
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandear committed Feb 7, 2025
1 parent 9cf5dbc commit 6608af4
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions examples/authors/sqlite/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

func TestAuthors(t *testing.T) {
sdb, cleanup := sqltest.SQLite(t, []string{"schema.sql"})
defer sdb.Close()
defer cleanup()

ctx := context.Background()
Expand Down
1 change: 1 addition & 0 deletions examples/booktest/sqlite/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const (

func TestBooks(t *testing.T) {
db, cleanup := sqltest.SQLite(t, []string{"schema.sql"})
defer sdb.Close()

Check failure on line 21 in examples/booktest/sqlite/db_test.go

View workflow job for this annotation

GitHub Actions / test ubuntu-22.04 cgo=1

undefined: sdb

Check failure on line 21 in examples/booktest/sqlite/db_test.go

View workflow job for this annotation

GitHub Actions / test ubuntu-22.04 cgo=0

undefined: sdb

Check failure on line 21 in examples/booktest/sqlite/db_test.go

View workflow job for this annotation

GitHub Actions / test ubuntu-22.04 cgo=0

undefined: sdb
defer cleanup()

ctx := context.Background()
Expand Down
2 changes: 2 additions & 0 deletions examples/ondeck/sqlite/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ func TestPrepared(t *testing.T) {
t.Parallel()

sdb, cleanup := sqltest.SQLite(t, []string{"schema"})
defer sdb.Close()
defer cleanup()

q, err := Prepare(context.Background(), sdb)
Expand All @@ -163,6 +164,7 @@ func TestQueries(t *testing.T) {
t.Parallel()

sdb, cleanup := sqltest.SQLite(t, []string{"schema"})
defer sdb.Close()
defer cleanup()

runOnDeckQueries(t, New(sdb))
Expand Down
6 changes: 5 additions & 1 deletion internal/sqltest/sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ func SQLite(t *testing.T, migrations []string) (*sql.DB, func()) {
if err != nil {
t.Fatal(err)
}
return CreateSQLiteDatabase(t, source.Name(), migrations)
db, cleanup := CreateSQLiteDatabase(t, source.Name(), migrations)
return db, func() {
source.Close()
cleanup()
}
}

func CreateSQLiteDatabase(t *testing.T, path string, migrations []string) (*sql.DB, func()) {
Expand Down

0 comments on commit 6608af4

Please sign in to comment.