summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/lib/pq/conn_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/lib/pq/conn_test.go')
-rw-r--r--vendor/github.com/lib/pq/conn_test.go74
1 files changed, 32 insertions, 42 deletions
diff --git a/vendor/github.com/lib/pq/conn_test.go b/vendor/github.com/lib/pq/conn_test.go
index d3c01f343..030a798c9 100644
--- a/vendor/github.com/lib/pq/conn_test.go
+++ b/vendor/github.com/lib/pq/conn_test.go
@@ -935,12 +935,14 @@ func TestParseErrorInExtendedQuery(t *testing.T) {
db := openTestConn(t)
defer db.Close()
- rows, err := db.Query("PARSE_ERROR $1", 1)
- if err == nil {
- t.Fatal("expected error")
+ _, err := db.Query("PARSE_ERROR $1", 1)
+ pqErr, _ := err.(*Error)
+ // Expecting a syntax error.
+ if err == nil || pqErr == nil || pqErr.Code != "42601" {
+ t.Fatalf("expected syntax error, got %s", err)
}
- rows, err = db.Query("SELECT 1")
+ rows, err := db.Query("SELECT 1")
if err != nil {
t.Fatal(err)
}
@@ -1205,16 +1207,11 @@ func TestParseComplete(t *testing.T) {
tpc("SELECT foo", "", 0, true) // invalid row count
}
-func TestExecerInterface(t *testing.T) {
- // Gin up a straw man private struct just for the type check
- cn := &conn{c: nil}
- var cni interface{} = cn
-
- _, ok := cni.(driver.Execer)
- if !ok {
- t.Fatal("Driver doesn't implement Execer")
- }
-}
+// Test interface conformance.
+var (
+ _ driver.Execer = (*conn)(nil)
+ _ driver.Queryer = (*conn)(nil)
+)
func TestNullAfterNonNull(t *testing.T) {
db := openTestConn(t)
@@ -1392,36 +1389,29 @@ func TestParseOpts(t *testing.T) {
}
func TestRuntimeParameters(t *testing.T) {
- type RuntimeTestResult int
- const (
- ResultUnknown RuntimeTestResult = iota
- ResultSuccess
- ResultError // other error
- )
-
tests := []struct {
- conninfo string
- param string
- expected string
- expectedOutcome RuntimeTestResult
+ conninfo string
+ param string
+ expected string
+ success bool
}{
// invalid parameter
- {"DOESNOTEXIST=foo", "", "", ResultError},
+ {"DOESNOTEXIST=foo", "", "", false},
// we can only work with a specific value for these two
- {"client_encoding=SQL_ASCII", "", "", ResultError},
- {"datestyle='ISO, YDM'", "", "", ResultError},
+ {"client_encoding=SQL_ASCII", "", "", false},
+ {"datestyle='ISO, YDM'", "", "", false},
// "options" should work exactly as it does in libpq
- {"options='-c search_path=pqgotest'", "search_path", "pqgotest", ResultSuccess},
+ {"options='-c search_path=pqgotest'", "search_path", "pqgotest", true},
// pq should override client_encoding in this case
- {"options='-c client_encoding=SQL_ASCII'", "client_encoding", "UTF8", ResultSuccess},
+ {"options='-c client_encoding=SQL_ASCII'", "client_encoding", "UTF8", true},
// allow client_encoding to be set explicitly
- {"client_encoding=UTF8", "client_encoding", "UTF8", ResultSuccess},
+ {"client_encoding=UTF8", "client_encoding", "UTF8", true},
// test a runtime parameter not supported by libpq
- {"work_mem='139kB'", "work_mem", "139kB", ResultSuccess},
+ {"work_mem='139kB'", "work_mem", "139kB", true},
// test fallback_application_name
- {"application_name=foo fallback_application_name=bar", "application_name", "foo", ResultSuccess},
- {"application_name='' fallback_application_name=bar", "application_name", "", ResultSuccess},
- {"fallback_application_name=bar", "application_name", "bar", ResultSuccess},
+ {"application_name=foo fallback_application_name=bar", "application_name", "foo", true},
+ {"application_name='' fallback_application_name=bar", "application_name", "", true},
+ {"fallback_application_name=bar", "application_name", "bar", true},
}
for _, test := range tests {
@@ -1436,23 +1426,23 @@ func TestRuntimeParameters(t *testing.T) {
continue
}
- tryGetParameterValue := func() (value string, outcome RuntimeTestResult) {
+ tryGetParameterValue := func() (value string, success bool) {
defer db.Close()
row := db.QueryRow("SELECT current_setting($1)", test.param)
err = row.Scan(&value)
if err != nil {
- return "", ResultError
+ return "", false
}
- return value, ResultSuccess
+ return value, true
}
- value, outcome := tryGetParameterValue()
- if outcome != test.expectedOutcome && outcome == ResultError {
+ value, success := tryGetParameterValue()
+ if success != test.success && !test.success {
t.Fatalf("%v: unexpected error: %v", test.conninfo, err)
}
- if outcome != test.expectedOutcome {
+ if success != test.success {
t.Fatalf("unexpected outcome %v (was expecting %v) for conninfo \"%s\"",
- outcome, test.expectedOutcome, test.conninfo)
+ success, test.success, test.conninfo)
}
if value != test.expected {
t.Fatalf("bad value for %s: got %s, want %s with conninfo \"%s\"",