Skipped multirange tests for postgres less than 14 version

pull/1412/head
Vitalii Solodilov 2022-11-29 12:34:26 +07:00 committed by Jack Christensen
parent 8e2de2fefa
commit 88b373f9ee
2 changed files with 52 additions and 14 deletions

View File

@ -911,6 +911,38 @@ func TestLoadRangeType(t *testing.T) {
require.NoError(t, err)
defer tx.Rollback(ctx)
_, err = tx.Exec(ctx, "create type examplefloatrange as range (subtype=float8, subtype_diff=float8mi)")
require.NoError(t, err)
// Register types
newRangeType, err := conn.LoadType(ctx, "examplefloatrange")
require.NoError(t, err)
conn.TypeMap().RegisterType(newRangeType)
conn.TypeMap().RegisterDefaultPgType(pgtype.Range[float64]{}, "examplefloatrange")
var inputRangeType = pgtype.Range[float64]{
Lower: 1.0,
Upper: 2.0,
LowerType: pgtype.Inclusive,
UpperType: pgtype.Inclusive,
Valid: true,
}
var outputRangeType pgtype.Range[float64]
err = tx.QueryRow(ctx, "SELECT $1::examplefloatrange", inputRangeType).Scan(&outputRangeType)
require.NoError(t, err)
require.Equal(t, inputRangeType, outputRangeType)
})
}
func TestLoadMultiRangeType(t *testing.T) {
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
pgxtest.SkipCockroachDB(t, conn, "Server does support range types")
pgxtest.SkipPostgreSQLVersionLessThan(t, conn, 14) // multirange data type was added in 14 postgresql
tx, err := conn.Begin(ctx)
require.NoError(t, err)
defer tx.Rollback(ctx)
_, err = tx.Exec(ctx, "create type examplefloatrange as range (subtype=float8, subtype_diff=float8mi, multirange_type_name=examplefloatmultirange)")
require.NoError(t, err)
@ -925,20 +957,6 @@ func TestLoadRangeType(t *testing.T) {
conn.TypeMap().RegisterType(newMultiRangeType)
conn.TypeMap().RegisterDefaultPgType(pgtype.Multirange[pgtype.Range[float64]]{}, "examplefloatmultirange")
// Test range type
var inputRangeType = pgtype.Range[float64]{
Lower: 1.0,
Upper: 2.0,
LowerType: pgtype.Inclusive,
UpperType: pgtype.Inclusive,
Valid: true,
}
var outputRangeType pgtype.Range[float64]
err = tx.QueryRow(ctx, "SELECT $1::examplefloatrange", inputRangeType).Scan(&outputRangeType)
require.NoError(t, err)
require.Equal(t, inputRangeType, outputRangeType)
// Test multi range type
var inputMultiRangeType = pgtype.Multirange[pgtype.Range[float64]]{
{
Lower: 1.0,

View File

@ -5,6 +5,8 @@ import (
"context"
"fmt"
"reflect"
"regexp"
"strconv"
"testing"
"github.com/jackc/pgx/v5"
@ -151,3 +153,21 @@ func SkipCockroachDB(t testing.TB, conn *pgx.Conn, msg string) {
t.Skip(msg)
}
}
func SkipPostgreSQLVersionLessThan(t testing.TB, conn *pgx.Conn, minVersion int64) {
serverVersionStr := conn.PgConn().ParameterStatus("server_version")
serverVersionStr = regexp.MustCompile(`^[0-9]+`).FindString(serverVersionStr)
// if not PostgreSQL do nothing
if serverVersionStr == "" {
return
}
serverVersion, err := strconv.ParseInt(serverVersionStr, 10, 64)
if err != nil {
t.Fatalf("postgres version parsed failed: %s", err)
}
if serverVersion < minVersion {
t.Skipf("Test requires PostgreSQL v%d+", minVersion)
}
}