2
0

Initial pass at fixing pgtype tests

Many still failing, but at least it compiles now.
This commit is contained in:
Jack Christensen
2019-04-12 16:58:42 -05:00
parent 0ac82007fb
commit fcbd9e93fa
6 changed files with 33 additions and 25 deletions
+16 -12
View File
@@ -34,12 +34,7 @@ func MustConnectDatabaseSQL(t testing.TB, driverName string) *sql.DB {
}
func MustConnectPgx(t testing.TB) *pgx.Conn {
config, err := pgx.ParseConnectionString(os.Getenv("PGX_TEST_DATABASE"))
if err != nil {
t.Fatal(err)
}
conn, err := pgx.Connect(config)
conn, err := pgx.Connect(context.Background(), os.Getenv("PGX_TEST_DATABASE"))
if err != nil {
t.Fatal(err)
}
@@ -56,6 +51,15 @@ func MustClose(t testing.TB, conn interface {
}
}
func MustCloseContext(t testing.TB, conn interface {
Close(context.Context) error
}) {
err := conn.Close(context.Background())
if err != nil {
t.Fatal(err)
}
}
type forceTextEncoder struct {
e pgtype.TextEncoder
}
@@ -102,7 +106,7 @@ func TestSuccessfulTranscodeEqFunc(t testing.TB, pgTypeName string, values []int
func TestPgxSuccessfulTranscodeEqFunc(t testing.TB, pgTypeName string, values []interface{}, eqFunc func(a, b interface{}) bool) {
conn := MustConnectPgx(t)
defer MustClose(t, conn)
defer MustCloseContext(t, conn)
ps, err := conn.Prepare("test", fmt.Sprintf("select $1::%s", pgTypeName))
if err != nil {
@@ -133,7 +137,7 @@ func TestPgxSuccessfulTranscodeEqFunc(t testing.TB, pgTypeName string, values []
}
result := reflect.New(reflect.TypeOf(derefV))
err := conn.QueryRow("test", ForceEncoder(v, fc.formatCode)).Scan(result.Interface())
err := conn.QueryRow(context.Background(), "test", ForceEncoder(v, fc.formatCode)).Scan(result.Interface())
if err != nil {
t.Errorf("%v %d: %v", fc.name, i, err)
}
@@ -147,7 +151,7 @@ func TestPgxSuccessfulTranscodeEqFunc(t testing.TB, pgTypeName string, values []
func TestPgxSimpleProtocolSuccessfulTranscodeEqFunc(t testing.TB, pgTypeName string, values []interface{}, eqFunc func(a, b interface{}) bool) {
conn := MustConnectPgx(t)
defer MustClose(t, conn)
defer MustCloseContext(t, conn)
for i, v := range values {
// Derefence value if it is a pointer
@@ -158,7 +162,7 @@ func TestPgxSimpleProtocolSuccessfulTranscodeEqFunc(t testing.TB, pgTypeName str
}
result := reflect.New(reflect.TypeOf(derefV))
err := conn.QueryRowEx(
err := conn.QueryRow(
context.Background(),
fmt.Sprintf("select ($1)::%s", pgTypeName),
&pgx.QueryExOptions{SimpleProtocol: true},
@@ -223,7 +227,7 @@ func TestSuccessfulNormalizeEqFunc(t testing.TB, tests []NormalizeTest, eqFunc f
func TestPgxSuccessfulNormalizeEqFunc(t testing.TB, tests []NormalizeTest, eqFunc func(a, b interface{}) bool) {
conn := MustConnectPgx(t)
defer MustClose(t, conn)
defer MustCloseContext(t, conn)
formats := []struct {
name string
@@ -254,7 +258,7 @@ func TestPgxSuccessfulNormalizeEqFunc(t testing.TB, tests []NormalizeTest, eqFun
}
result := reflect.New(reflect.TypeOf(derefV))
err = conn.QueryRow(psName).Scan(result.Interface())
err = conn.QueryRow(context.Background(), psName).Scan(result.Interface())
if err != nil {
t.Errorf("%v %d: %v", fc.name, i, err)
}