Skip to content

Commit 6608af4

Browse files
committed
examples: Add missing Close calls
1 parent 9cf5dbc commit 6608af4

File tree

4 files changed

+9
-1
lines changed

4 files changed

+9
-1
lines changed

examples/authors/sqlite/db_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

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

1718
ctx := context.Background()

examples/booktest/sqlite/db_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const (
1818

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

2324
ctx := context.Background()

examples/ondeck/sqlite/db_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ func TestPrepared(t *testing.T) {
149149
t.Parallel()
150150

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

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

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

168170
runOnDeckQueries(t, New(sdb))

internal/sqltest/sqlite.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ func SQLite(t *testing.T, migrations []string) (*sql.DB, func()) {
1616
if err != nil {
1717
t.Fatal(err)
1818
}
19-
return CreateSQLiteDatabase(t, source.Name(), migrations)
19+
db, cleanup := CreateSQLiteDatabase(t, source.Name(), migrations)
20+
return db, func() {
21+
source.Close()
22+
cleanup()
23+
}
2024
}
2125

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

0 commit comments

Comments
 (0)