Permalink
Browse files

Close Rows in tests.

The sql.DB.Close() function only closes connections that are marked as
free. The sql.Rows.Close() function marks the Row's connection as free,
so it must be invoked to cleanly close the DB.
  • Loading branch information...
1 parent 00262e4 commit 8e3a73021c3fa24b087d315dfe8282335c50b349 @benburkert benburkert committed with Apr 7, 2012
Showing with 9 additions and 5 deletions.
  1. +9 −5 conn_test.go
View
@@ -76,6 +76,7 @@ func TestStatment(t *testing.T) {
if err != nil {
t.Fatal(err)
}
+ defer r.Close()
if !r.Next() {
t.Fatal("expected row")
@@ -93,19 +94,20 @@ func TestStatment(t *testing.T) {
// st1
- r, err = st1.Query()
+ r1, err := st1.Query()
if err != nil {
t.Fatal(err)
}
+ defer r1.Close()
- if !r.Next() {
+ if !r1.Next() {
if r.Err() != nil {
- t.Fatal(r.Err())
+ t.Fatal(r1.Err())
}
t.Fatal("expected row")
}
- err = r.Scan(&i)
+ err = r1.Scan(&i)
if err != nil {
t.Fatal(err)
}
@@ -291,6 +293,7 @@ func TestErrorOnQuery(t *testing.T) {
if err != nil {
t.Fatal(err)
}
+ defer r.Close()
if r.Next() {
t.Fatal("unexpected row, want error")
@@ -326,10 +329,11 @@ func TestBindError(t *testing.T) {
}
// Should not get error here
- _, err = db.Query("select * from test where i=$1", 1)
+ r, err := db.Query("select * from test where i=$1", 1)
if err != nil {
t.Fatal(err)
}
+ defer r.Close()
}
func TestParseEnviron(t *testing.T) {

0 comments on commit 8e3a730

Please sign in to comment.