Add errcheck and fix unchecked errors

This commit is contained in:
Adrian Macneil 2015-11-27 14:27:44 -08:00
parent 913234a60d
commit c6aba53e51
7 changed files with 40 additions and 13 deletions

View file

@ -4,6 +4,7 @@ import (
"database/sql"
"github.com/adrianmacneil/dbmate/driver/postgres"
"github.com/stretchr/testify/require"
"io"
"net/url"
"os"
"testing"
@ -24,6 +25,12 @@ func testURL(t *testing.T) *url.URL {
return u
}
func mustClose(c io.Closer) {
if err := c.Close(); err != nil {
panic(err)
}
}
func TestCreateDropDatabase(t *testing.T) {
d := postgres.Driver{}
u := testURL(t)
@ -40,7 +47,7 @@ func TestCreateDropDatabase(t *testing.T) {
func() {
db, err := sql.Open("postgres", u.String())
require.Nil(t, err)
defer db.Close()
defer mustClose(db)
err = db.Ping()
require.Nil(t, err)
@ -54,7 +61,7 @@ func TestCreateDropDatabase(t *testing.T) {
func() {
db, err := sql.Open("postgres", u.String())
require.Nil(t, err)
defer db.Close()
defer mustClose(db)
err = db.Ping()
require.NotNil(t, err)