Skip test on too old PostgreSQL

pull/962/head
Jack Christensen 2021-03-13 07:18:26 -06:00
parent e93da6c744
commit 00704ce8b7
3 changed files with 36 additions and 0 deletions

1
go.mod
View File

@ -3,6 +3,7 @@ module github.com/jackc/pgx/v4
go 1.12
require (
github.com/Masterminds/semver/v3 v3.1.1 // indirect
github.com/cockroachdb/apd v1.1.0
github.com/go-kit/kit v0.10.0
github.com/gofrs/uuid v3.2.0+incompatible

2
go.sum
View File

@ -3,6 +3,8 @@ cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
github.com/Masterminds/semver/v3 v3.1.1 h1:hLg3sBzpNErnxhQtUy/mmLR2I9foDujNK030IGemrRc=
github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g=

View File

@ -12,6 +12,7 @@ import (
"testing"
"time"
"github.com/Masterminds/semver/v3"
"github.com/jackc/pgconn"
"github.com/jackc/pgx/v4"
"github.com/jackc/pgx/v4/stdlib"
@ -45,6 +46,37 @@ func skipCockroachDB(t testing.TB, db *sql.DB, msg string) {
require.NoError(t, err)
}
func skipPostgreSQLVersion(t testing.TB, db *sql.DB, constraintStr, msg string) {
conn, err := db.Conn(context.Background())
require.NoError(t, err)
defer conn.Close()
err = conn.Raw(func(driverConn interface{}) error {
conn := driverConn.(*stdlib.Conn).Conn()
serverVersionStr := conn.PgConn().ParameterStatus("server_version")
// if not PostgreSQL do nothing
if serverVersionStr == "" {
return nil
}
serverVersion, err := semver.NewVersion(serverVersionStr)
if err != nil {
return err
}
c, err := semver.NewConstraint(constraintStr)
if err != nil {
return err
}
if c.Check(serverVersion) {
t.Skip(msg)
}
return nil
})
require.NoError(t, err)
}
func testWithAndWithoutPreferSimpleProtocol(t *testing.T, f func(t *testing.T, db *sql.DB)) {
t.Run("SimpleProto",
func(t *testing.T) {
@ -1051,6 +1083,7 @@ func TestRegisterConnConfig(t *testing.T) {
// https://github.com/jackc/pgx/issues/958
func TestConnQueryRowConstraintErrors(t *testing.T) {
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, db *sql.DB) {
skipPostgreSQLVersion(t, db, "< 11", "Test requires PG 11+")
skipCockroachDB(t, db, "Server does not support deferred constraint (https://github.com/cockroachdb/cockroach/issues/31632)")
_, err := db.Exec(`create temporary table defer_test (