Run postgres tests with pgx driver
This commit is contained in:
parent
7af9072b8d
commit
e95a2385ee
4 changed files with 508 additions and 16 deletions
|
|
@ -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