Skip to content

Commit

Permalink
Fix failing builds (#719)
Browse files Browse the repository at this point in the history
Update expected error message in TestInfinityTimestamp
  • Loading branch information
nickuraltsev authored and maddyblue committed Mar 19, 2018
1 parent 88edab0 commit b200422
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions encode_test.go
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"database/sql"
"fmt"
"strings"
"regexp"
"testing"
"time"

Expand Down Expand Up @@ -304,24 +304,27 @@ func TestInfinityTimestamp(t *testing.T) {
var err error
var resultT time.Time

expectedErrorStrPrefix := `sql: Scan error on column index 0: unsupported`
expectedErrorStrRegexp := regexp.MustCompile(
`^sql: Scan error on column index 0(, name "timestamp(tz)?"|): unsupported`)

type testCases []struct {
Query string
Param string
ExpectedErrStrPrefix string
ExpectedVal interface{}
Query string
Param string
ExpectedErrorStrRegexp *regexp.Regexp
ExpectedVal interface{}
}
tc := testCases{
{"SELECT $1::timestamp", "-infinity", expectedErrorStrPrefix, "-infinity"},
{"SELECT $1::timestamptz", "-infinity", expectedErrorStrPrefix, "-infinity"},
{"SELECT $1::timestamp", "infinity", expectedErrorStrPrefix, "infinity"},
{"SELECT $1::timestamptz", "infinity", expectedErrorStrPrefix, "infinity"},
{"SELECT $1::timestamp", "-infinity", expectedErrorStrRegexp, "-infinity"},
{"SELECT $1::timestamptz", "-infinity", expectedErrorStrRegexp, "-infinity"},
{"SELECT $1::timestamp", "infinity", expectedErrorStrRegexp, "infinity"},
{"SELECT $1::timestamptz", "infinity", expectedErrorStrRegexp, "infinity"},
}
// try to assert []byte to time.Time
for _, q := range tc {
err = db.QueryRow(q.Query, q.Param).Scan(&resultT)
if !strings.HasPrefix(err.Error(), q.ExpectedErrStrPrefix) {
t.Errorf("Scanning -/+infinity, expected error to have prefix %q, got %q", q.ExpectedErrStrPrefix, err)
if !q.ExpectedErrorStrRegexp.MatchString(err.Error()) {
t.Errorf("Scanning -/+infinity, expected error to match regexp %q, got %q",
q.ExpectedErrorStrRegexp, err)
}
}
// yield []byte
Expand Down

0 comments on commit b200422

Please sign in to comment.