Run postgres tests with pgx driver
This commit is contained in:
parent
7af9072b8d
commit
e95a2385ee
4 changed files with 508 additions and 16 deletions
|
|
@ -17,6 +17,8 @@ import (
|
|||
)
|
||||
|
||||
func TestAllTypesSelect(t *testing.T) {
|
||||
skipForPgxDriver(t) // pgx driver returns time with time zone as string
|
||||
|
||||
dest := []model.AllTypes{}
|
||||
|
||||
err := AllTypes.SELECT(AllTypes.AllColumns).Query(db, &dest)
|
||||
|
|
@ -27,6 +29,8 @@ func TestAllTypesSelect(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAllTypesViewSelect(t *testing.T) {
|
||||
skipForPgxDriver(t) // pgx driver returns time with time zone as string
|
||||
|
||||
type AllTypesView model.AllTypes
|
||||
|
||||
dest := []AllTypesView{}
|
||||
|
|
@ -39,6 +43,8 @@ func TestAllTypesViewSelect(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAllTypesInsertModel(t *testing.T) {
|
||||
skipForPgxDriver(t) // pgx driver does not handle well time with time zone
|
||||
|
||||
query := AllTypes.INSERT(AllTypes.AllColumns).
|
||||
MODEL(allTypesRow0).
|
||||
MODEL(&allTypesRow1).
|
||||
|
|
@ -54,6 +60,8 @@ func TestAllTypesInsertModel(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAllTypesInsertQuery(t *testing.T) {
|
||||
skipForPgxDriver(t) // pgx driver does not handle well time with time zone
|
||||
|
||||
query := AllTypes.INSERT(AllTypes.AllColumns).
|
||||
QUERY(
|
||||
AllTypes.
|
||||
|
|
@ -293,6 +301,8 @@ LIMIT $11;
|
|||
|
||||
func TestExpressionCast(t *testing.T) {
|
||||
|
||||
skipForPgxDriver(t) // for some reason, pgx driver, 150:char(12) returns as int value
|
||||
|
||||
query := AllTypes.SELECT(
|
||||
CAST(Int(150)).AS_CHAR(12).AS("char12"),
|
||||
CAST(String("TRUE")).AS_BOOL(),
|
||||
|
|
@ -338,6 +348,8 @@ func TestExpressionCast(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestStringOperators(t *testing.T) {
|
||||
skipForPgxDriver(t) // pgx driver returns text column as int value
|
||||
|
||||
query := AllTypes.SELECT(
|
||||
AllTypes.Text.EQ(AllTypes.Char),
|
||||
AllTypes.Text.EQ(String("Text")),
|
||||
|
|
@ -853,6 +865,7 @@ func TestInterval(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestSubQueryColumnReference(t *testing.T) {
|
||||
skipForPgxDriver(t) // pgx driver returns time with time zone as string value
|
||||
|
||||
type expected struct {
|
||||
sql string
|
||||
|
|
@ -1030,6 +1043,7 @@ FROM`
|
|||
}
|
||||
|
||||
func TestTimeLiterals(t *testing.T) {
|
||||
skipForPgxDriver(t) // pgx driver returns time with time zone as string
|
||||
|
||||
loc, err := time.LoadLocation("Europe/Berlin")
|
||||
require.NoError(t, err)
|
||||
|
|
|
|||
|
|
@ -3,17 +3,23 @@ package postgres
|
|||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"github.com/go-jet/jet/v2/postgres"
|
||||
"github.com/go-jet/jet/v2/tests/dbconfig"
|
||||
_ "github.com/lib/pq"
|
||||
"github.com/pkg/profile"
|
||||
"github.com/stretchr/testify/require"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v4/stdlib"
|
||||
|
||||
"github.com/go-jet/jet/v2/postgres"
|
||||
"github.com/go-jet/jet/v2/tests/dbconfig"
|
||||
_ "github.com/lib/pq"
|
||||
"github.com/pkg/profile"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
_ "github.com/jackc/pgx/v4/stdlib"
|
||||
)
|
||||
|
||||
var db *sql.DB
|
||||
|
|
@ -25,16 +31,23 @@ func TestMain(m *testing.M) {
|
|||
|
||||
setTestRoot()
|
||||
|
||||
var err error
|
||||
db, err = sql.Open("postgres", dbconfig.PostgresConnectString)
|
||||
if err != nil {
|
||||
panic("Failed to connect to test db")
|
||||
for _, driverName := range []string{"postgres", "pgx"} {
|
||||
func() {
|
||||
var err error
|
||||
db, err = sql.Open(driverName, dbconfig.PostgresConnectString)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
panic("Failed to connect to test db")
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
ret := m.Run()
|
||||
|
||||
if ret != 0 {
|
||||
os.Exit(ret)
|
||||
}
|
||||
}()
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
ret := m.Run()
|
||||
|
||||
os.Exit(ret)
|
||||
}
|
||||
|
||||
func setTestRoot() {
|
||||
|
|
@ -64,3 +77,10 @@ func requireLogged(t *testing.T, statement postgres.Statement) {
|
|||
require.Equal(t, loggedSQLArgs, args)
|
||||
require.Equal(t, loggedDebugSQL, statement.DebugSql())
|
||||
}
|
||||
|
||||
func skipForPgxDriver(t *testing.T) {
|
||||
switch db.Driver().(type) {
|
||||
case *stdlib.Driver:
|
||||
t.SkipNow()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue