Use environment variables for test configuration

pull/483/head
Jack Christensen 2018-12-30 21:52:33 -06:00
parent 67a15e6f7f
commit c672c0d595
22 changed files with 245 additions and 253 deletions

1
.gitignore vendored
View File

@ -21,5 +21,4 @@ _testmain.go
*.exe *.exe
conn_config_test.go
.envrc .envrc

View File

@ -17,9 +17,9 @@ env:
- PGX_TEST_MD5_PASSWORD_CONN_STRING=postgres://pgx_md5:secret@127.0.0.1/pgx_test - PGX_TEST_MD5_PASSWORD_CONN_STRING=postgres://pgx_md5:secret@127.0.0.1/pgx_test
- PGX_TEST_PLAIN_PASSWORD_CONN_STRING=postgres://pgx_pw:secret@127.0.0.1/pgx_test - PGX_TEST_PLAIN_PASSWORD_CONN_STRING=postgres://pgx_pw:secret@127.0.0.1/pgx_test
matrix: matrix:
- CRATEVERSION=2.1 - CRATEVERSION=2.1 PGX_TEST_CRATEDB_CONN_STRING="host=127.0.0.1 port=6543 user=pgx database=pgx_test"
- PGVERSION=10 - PGVERSION=10 PGX_TEST_REPLICATION_CONN_STRING="host=127.0.0.1 port=6543 user=pgx_replication password=secret database=pgx_test"
- PGVERSION=9.6 - PGVERSION=9.6 PGX_TEST_REPLICATION_CONN_STRING="host=127.0.0.1 port=6543 user=pgx_replication password=secret database=pgx_test"
- PGVERSION=9.5 - PGVERSION=9.5
- PGVERSION=9.4 - PGVERSION=9.4
- PGVERSION=9.3 - PGVERSION=9.3

View File

@ -75,6 +75,8 @@ environment that can test all of them can be cumbersome. In particular,
Windows cannot test Unix domain socket connections. Because of this pgx will Windows cannot test Unix domain socket connections. Because of this pgx will
skip tests for connection types that are not configured. skip tests for connection types that are not configured.
pgx uses environment variables to configure the test database connections. Consider using [direnv](https://github.com/direnv/direnv) to simplify this.
### Normal Test Environment ### Normal Test Environment
To setup the normal test environment, first install these dependencies: To setup the normal test environment, first install these dependencies:
@ -102,12 +104,14 @@ Connect to database pgx_test and run:
create extension hstore; create extension hstore;
create domain uint64 as numeric(20,0); create domain uint64 as numeric(20,0);
Next open conn_config_test.go.example and make a copy without the Run the tests with environment variable PGX_TEST_DATABASE set to your test database.
.example. If your PostgreSQL server is accepting connections on 127.0.0.1,
then you are done. PGX_TEXT_DATABASE="host=/var/run/postgresql database=pgx_test" go test ./...
### Connection and Authentication Test Environment ### Connection and Authentication Test Environment
Additional tests are available for specific connection types (e.g. TCP, Unix domain sockets, no password, plain password, MD5 password, etc).
Complete the normal test environment setup and also do the following. Complete the normal test environment setup and also do the following.
Run the following SQL: Run the following SQL:
@ -129,6 +133,14 @@ If you are developing on Windows with TCP connections:
host pgx_test pgx_pw 127.0.0.1/32 password host pgx_test pgx_pw 127.0.0.1/32 password
host pgx_test pgx_md5 127.0.0.1/32 md5 host pgx_test pgx_md5 127.0.0.1/32 md5
Each different test connection type uses a different connection string in an environment variable.
export PGX_TEST_UNIX_SOCKET_CONN_STRING="host=/var/run/postgresql database=pgx_test"
export PGX_TEST_TCP_CONN_STRING="host=127.0.0.1 user=pgx_md5 password=secret database=pgx_test"
export PGX_TEST_TLS_CONN_STRING="host=127.0.0.1 user=pgx_md5 password=secret database=pgx_test sslmode=require"
export PGX_TEST_MD5_PASSWORD_CONN_STRING="host=127.0.0.1 user=pgx_md5 password=secret database=pgx_test"
export PGX_TEST_PLAIN_PASSWORD_CONN_STRING="host=127.0.0.1 user=pgx_pw password=secret database=pgx_test"
### Replication Test Environment ### Replication Test Environment
Add a replication user: Add a replication user:
@ -145,7 +157,9 @@ Change the following settings in your postgresql.conf:
max_wal_senders=5 max_wal_senders=5
max_replication_slots=5 max_replication_slots=5
Set `replicationConnConfig` appropriately in `conn_config_test.go`. Set the replication environment variable.
export PGX_TEST_REPLICATION_CONN_STRING="host=127.0.0.1 user=pgx_replication password=secret database=pgx_test"
## Version Policy ## Version Policy

View File

@ -2,6 +2,7 @@ package pgx_test
import ( import (
"context" "context"
"os"
"testing" "testing"
"github.com/jackc/pgx" "github.com/jackc/pgx"
@ -11,7 +12,7 @@ import (
func TestConnBeginBatch(t *testing.T) { func TestConnBeginBatch(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
sql := `create temporary table ledger( sql := `create temporary table ledger(
@ -152,7 +153,7 @@ func TestConnBeginBatch(t *testing.T) {
func TestConnBeginBatchWithPreparedStatement(t *testing.T) { func TestConnBeginBatchWithPreparedStatement(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
_, err := conn.Prepare("ps1", "select n from generate_series(0,$1::int) n") _, err := conn.Prepare("ps1", "select n from generate_series(0,$1::int) n")
@ -208,7 +209,7 @@ func TestConnBeginBatchWithPreparedStatement(t *testing.T) {
func TestConnBeginBatchContextCancelBeforeExecResults(t *testing.T) { func TestConnBeginBatchContextCancelBeforeExecResults(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
sql := `create temporary table ledger( sql := `create temporary table ledger(
id serial primary key, id serial primary key,
@ -251,7 +252,7 @@ func TestConnBeginBatchContextCancelBeforeExecResults(t *testing.T) {
func TestConnBeginBatchContextCancelBeforeQueryResults(t *testing.T) { func TestConnBeginBatchContextCancelBeforeQueryResults(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
batch := conn.BeginBatch() batch := conn.BeginBatch()
batch.Queue("select pg_sleep(2)", batch.Queue("select pg_sleep(2)",
@ -287,7 +288,7 @@ func TestConnBeginBatchContextCancelBeforeQueryResults(t *testing.T) {
func TestConnBeginBatchContextCancelBeforeFinish(t *testing.T) { func TestConnBeginBatchContextCancelBeforeFinish(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
batch := conn.BeginBatch() batch := conn.BeginBatch()
batch.Queue("select pg_sleep(2)", batch.Queue("select pg_sleep(2)",
@ -323,7 +324,7 @@ func TestConnBeginBatchContextCancelBeforeFinish(t *testing.T) {
func TestConnBeginBatchCloseRowsPartiallyRead(t *testing.T) { func TestConnBeginBatchCloseRowsPartiallyRead(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
batch := conn.BeginBatch() batch := conn.BeginBatch()
@ -394,7 +395,7 @@ func TestConnBeginBatchCloseRowsPartiallyRead(t *testing.T) {
func TestConnBeginBatchQueryError(t *testing.T) { func TestConnBeginBatchQueryError(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
batch := conn.BeginBatch() batch := conn.BeginBatch()
@ -446,7 +447,7 @@ func TestConnBeginBatchQueryError(t *testing.T) {
func TestConnBeginBatchQuerySyntaxError(t *testing.T) { func TestConnBeginBatchQuerySyntaxError(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
batch := conn.BeginBatch() batch := conn.BeginBatch()
@ -480,7 +481,7 @@ func TestConnBeginBatchQuerySyntaxError(t *testing.T) {
func TestConnBeginBatchQueryRowInsert(t *testing.T) { func TestConnBeginBatchQueryRowInsert(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
sql := `create temporary table ledger( sql := `create temporary table ledger(
@ -529,7 +530,7 @@ func TestConnBeginBatchQueryRowInsert(t *testing.T) {
func TestConnBeginBatchQueryPartialReadInsert(t *testing.T) { func TestConnBeginBatchQueryPartialReadInsert(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
sql := `create temporary table ledger( sql := `create temporary table ledger(
@ -578,7 +579,7 @@ func TestConnBeginBatchQueryPartialReadInsert(t *testing.T) {
func TestTxBeginBatch(t *testing.T) { func TestTxBeginBatch(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
sql := `create temporary table ledger1( sql := `create temporary table ledger1(
@ -663,7 +664,7 @@ func TestTxBeginBatch(t *testing.T) {
func TestTxBeginBatchRollback(t *testing.T) { func TestTxBeginBatchRollback(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
sql := `create temporary table ledger1( sql := `create temporary table ledger1(

View File

@ -1,11 +1,12 @@
package pgx_test package pgx_test
import ( import (
"os"
"testing" "testing"
) )
func BenchmarkPgtypeInt4ParseBinary(b *testing.B) { func BenchmarkPgtypeInt4ParseBinary(b *testing.B) {
conn := mustConnect(b, *defaultConnConfig) conn := mustConnectString(b, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(b, conn) defer closeConn(b, conn)
_, err := conn.Prepare("selectBinary", "select n::int4 from generate_series(1, 100) n") _, err := conn.Prepare("selectBinary", "select n::int4 from generate_series(1, 100) n")
@ -36,7 +37,7 @@ func BenchmarkPgtypeInt4ParseBinary(b *testing.B) {
} }
func BenchmarkPgtypeInt4EncodeBinary(b *testing.B) { func BenchmarkPgtypeInt4EncodeBinary(b *testing.B) {
conn := mustConnect(b, *defaultConnConfig) conn := mustConnectString(b, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(b, conn) defer closeConn(b, conn)
_, err := conn.Prepare("encodeBinary", "select $1::int4, $2::int4, $3::int4, $4::int4, $5::int4, $6::int4, $7::int4") _, err := conn.Prepare("encodeBinary", "select $1::int4, $2::int4, $3::int4, $4::int4, $5::int4, $6::int4, $7::int4")

View File

@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"context" "context"
"fmt" "fmt"
"os"
"strings" "strings"
"testing" "testing"
"time" "time"
@ -13,7 +14,7 @@ import (
) )
func BenchmarkConnPool(b *testing.B) { func BenchmarkConnPool(b *testing.B) {
config := pgx.ConnPoolConfig{ConnConfig: *defaultConnConfig, MaxConnections: 5} config := pgx.ConnPoolConfig{ConnConfig: mustParseConfig(b, os.Getenv("PGX_TEST_DATABASE")), MaxConnections: 5}
pool, err := pgx.NewConnPool(config) pool, err := pgx.NewConnPool(config)
if err != nil { if err != nil {
b.Fatalf("Unable to create connection pool: %v", err) b.Fatalf("Unable to create connection pool: %v", err)
@ -31,7 +32,7 @@ func BenchmarkConnPool(b *testing.B) {
} }
func BenchmarkConnPoolQueryRow(b *testing.B) { func BenchmarkConnPoolQueryRow(b *testing.B) {
config := pgx.ConnPoolConfig{ConnConfig: *defaultConnConfig, MaxConnections: 5} config := pgx.ConnPoolConfig{ConnConfig: mustParseConfig(b, os.Getenv("PGX_TEST_DATABASE")), MaxConnections: 5}
pool, err := pgx.NewConnPool(config) pool, err := pgx.NewConnPool(config)
if err != nil { if err != nil {
b.Fatalf("Unable to create connection pool: %v", err) b.Fatalf("Unable to create connection pool: %v", err)
@ -52,7 +53,7 @@ func BenchmarkConnPoolQueryRow(b *testing.B) {
} }
func BenchmarkPointerPointerWithNullValues(b *testing.B) { func BenchmarkPointerPointerWithNullValues(b *testing.B) {
conn := mustConnect(b, *defaultConnConfig) conn := mustConnect(b, mustParseConfig(b, os.Getenv("PGX_TEST_DATABASE")))
defer closeConn(b, conn) defer closeConn(b, conn)
_, err := conn.Prepare("selectNulls", "select 1::int4, 'johnsmith', null::text, null::text, null::text, null::date, null::timestamptz") _, err := conn.Prepare("selectNulls", "select 1::int4, 'johnsmith', null::text, null::text, null::text, null::date, null::timestamptz")
@ -112,7 +113,7 @@ func BenchmarkPointerPointerWithNullValues(b *testing.B) {
} }
func BenchmarkPointerPointerWithPresentValues(b *testing.B) { func BenchmarkPointerPointerWithPresentValues(b *testing.B) {
conn := mustConnect(b, *defaultConnConfig) conn := mustConnect(b, mustParseConfig(b, os.Getenv("PGX_TEST_DATABASE")))
defer closeConn(b, conn) defer closeConn(b, conn)
_, err := conn.Prepare("selectNulls", "select 1::int4, 'johnsmith', 'johnsmith@example.com', 'John Smith', 'male', '1970-01-01'::date, '2015-01-01 00:00:00'::timestamptz") _, err := conn.Prepare("selectNulls", "select 1::int4, 'johnsmith', 'johnsmith@example.com', 'John Smith', 'male', '1970-01-01'::date, '2015-01-01 00:00:00'::timestamptz")
@ -172,7 +173,7 @@ func BenchmarkPointerPointerWithPresentValues(b *testing.B) {
} }
func BenchmarkSelectWithoutLogging(b *testing.B) { func BenchmarkSelectWithoutLogging(b *testing.B) {
conn := mustConnect(b, *defaultConnConfig) conn := mustConnect(b, mustParseConfig(b, os.Getenv("PGX_TEST_DATABASE")))
defer closeConn(b, conn) defer closeConn(b, conn)
benchmarkSelectWithLog(b, conn) benchmarkSelectWithLog(b, conn)
@ -183,7 +184,7 @@ type discardLogger struct{}
func (dl discardLogger) Log(level pgx.LogLevel, msg string, data map[string]interface{}) {} func (dl discardLogger) Log(level pgx.LogLevel, msg string, data map[string]interface{}) {}
func BenchmarkSelectWithLoggingTraceDiscard(b *testing.B) { func BenchmarkSelectWithLoggingTraceDiscard(b *testing.B) {
conn := mustConnect(b, *defaultConnConfig) conn := mustConnect(b, mustParseConfig(b, os.Getenv("PGX_TEST_DATABASE")))
defer closeConn(b, conn) defer closeConn(b, conn)
var logger discardLogger var logger discardLogger
@ -194,7 +195,7 @@ func BenchmarkSelectWithLoggingTraceDiscard(b *testing.B) {
} }
func BenchmarkSelectWithLoggingDebugWithDiscard(b *testing.B) { func BenchmarkSelectWithLoggingDebugWithDiscard(b *testing.B) {
conn := mustConnect(b, *defaultConnConfig) conn := mustConnect(b, mustParseConfig(b, os.Getenv("PGX_TEST_DATABASE")))
defer closeConn(b, conn) defer closeConn(b, conn)
var logger discardLogger var logger discardLogger
@ -205,7 +206,7 @@ func BenchmarkSelectWithLoggingDebugWithDiscard(b *testing.B) {
} }
func BenchmarkSelectWithLoggingInfoWithDiscard(b *testing.B) { func BenchmarkSelectWithLoggingInfoWithDiscard(b *testing.B) {
conn := mustConnect(b, *defaultConnConfig) conn := mustConnect(b, mustParseConfig(b, os.Getenv("PGX_TEST_DATABASE")))
defer closeConn(b, conn) defer closeConn(b, conn)
var logger discardLogger var logger discardLogger
@ -216,7 +217,7 @@ func BenchmarkSelectWithLoggingInfoWithDiscard(b *testing.B) {
} }
func BenchmarkSelectWithLoggingErrorWithDiscard(b *testing.B) { func BenchmarkSelectWithLoggingErrorWithDiscard(b *testing.B) {
conn := mustConnect(b, *defaultConnConfig) conn := mustConnect(b, mustParseConfig(b, os.Getenv("PGX_TEST_DATABASE")))
defer closeConn(b, conn) defer closeConn(b, conn)
var logger discardLogger var logger discardLogger
@ -373,7 +374,7 @@ func newBenchmarkWriteTableCopyFromSrc(count int) pgx.CopyFromSource {
} }
func benchmarkWriteNRowsViaInsert(b *testing.B, n int) { func benchmarkWriteNRowsViaInsert(b *testing.B, n int) {
conn := mustConnect(b, *defaultConnConfig) conn := mustConnect(b, mustParseConfig(b, os.Getenv("PGX_TEST_DATABASE")))
defer closeConn(b, conn) defer closeConn(b, conn)
mustExec(b, conn, benchmarkWriteTableCreateSQL) mustExec(b, conn, benchmarkWriteTableCreateSQL)
@ -484,7 +485,7 @@ func multiInsert(conn *pgx.Conn, tableName string, columnNames []string, rowSrc
} }
func benchmarkWriteNRowsViaMultiInsert(b *testing.B, n int) { func benchmarkWriteNRowsViaMultiInsert(b *testing.B, n int) {
conn := mustConnect(b, *defaultConnConfig) conn := mustConnect(b, mustParseConfig(b, os.Getenv("PGX_TEST_DATABASE")))
defer closeConn(b, conn) defer closeConn(b, conn)
mustExec(b, conn, benchmarkWriteTableCreateSQL) mustExec(b, conn, benchmarkWriteTableCreateSQL)
@ -520,7 +521,7 @@ func benchmarkWriteNRowsViaMultiInsert(b *testing.B, n int) {
} }
func benchmarkWriteNRowsViaCopy(b *testing.B, n int) { func benchmarkWriteNRowsViaCopy(b *testing.B, n int) {
conn := mustConnect(b, *defaultConnConfig) conn := mustConnect(b, mustParseConfig(b, os.Getenv("PGX_TEST_DATABASE")))
defer closeConn(b, conn) defer closeConn(b, conn)
mustExec(b, conn, benchmarkWriteTableCreateSQL) mustExec(b, conn, benchmarkWriteTableCreateSQL)
@ -612,7 +613,7 @@ func BenchmarkWrite10000RowsViaCopy(b *testing.B) {
} }
func BenchmarkMultipleQueriesNonBatch(b *testing.B) { func BenchmarkMultipleQueriesNonBatch(b *testing.B) {
config := pgx.ConnPoolConfig{ConnConfig: *defaultConnConfig, MaxConnections: 5} config := pgx.ConnPoolConfig{ConnConfig: mustParseConfig(b, os.Getenv("PGX_TEST_DATABASE")), MaxConnections: 5}
pool, err := pgx.NewConnPool(config) pool, err := pgx.NewConnPool(config)
if err != nil { if err != nil {
b.Fatalf("Unable to create connection pool: %v", err) b.Fatalf("Unable to create connection pool: %v", err)
@ -647,7 +648,7 @@ func BenchmarkMultipleQueriesNonBatch(b *testing.B) {
} }
func BenchmarkMultipleQueriesBatch(b *testing.B) { func BenchmarkMultipleQueriesBatch(b *testing.B) {
config := pgx.ConnPoolConfig{ConnConfig: *defaultConnConfig, MaxConnections: 5} config := pgx.ConnPoolConfig{ConnConfig: mustParseConfig(b, os.Getenv("PGX_TEST_DATABASE")), MaxConnections: 5}
pool, err := pgx.NewConnPool(config) pool, err := pgx.NewConnPool(config)
if err != nil { if err != nil {
b.Fatalf("Unable to create connection pool: %v", err) b.Fatalf("Unable to create connection pool: %v", err)

View File

@ -1,20 +0,0 @@
package pgx_test
import (
// "crypto/tls"
// "crypto/x509"
// "fmt"
// "go/build"
// "io/ioutil"
// "path"
"github.com/jackc/pgx"
)
var defaultConnConfig *pgx.ConnConfig = &pgx.ConnConfig{Host: "127.0.0.1", User: "pgx_md5", Password: "secret", Database: "pgx_test"}
// To skip tests for specific connection / authentication types set that connection param to nil
var replicationConnConfig *pgx.ConnConfig = nil
var cratedbConnConfig *pgx.ConnConfig = nil
// var replicationConnConfig *pgx.ConnConfig = &pgx.ConnConfig{Host: "127.0.0.1", User: "pgx_replication", Password: "secret", Database: "pgx_test"}

View File

@ -1,29 +0,0 @@
package pgx_test
import (
"crypto/tls"
"github.com/jackc/pgx"
"os"
"strconv"
)
var defaultConnConfig = &pgx.ConnConfig{Host: "127.0.0.1", User: "pgx_md5", Password: "secret", Database: "pgx_test"}
var replicationConnConfig *pgx.ConnConfig = nil
var cratedbConnConfig *pgx.ConnConfig = nil
func init() {
pgVersion := os.Getenv("PGVERSION")
if len(pgVersion) > 0 {
v, err := strconv.ParseFloat(pgVersion, 64)
if err == nil && v >= 9.6 {
replicationConnConfig = &pgx.ConnConfig{Host: "127.0.0.1", User: "pgx_replication", Password: "secret", Database: "pgx_test"}
}
}
crateVersion := os.Getenv("CRATEVERSION")
if crateVersion != "" {
cratedbConnConfig = &pgx.ConnConfig{Host: "127.0.0.1", Port: 6543, User: "pgx", Password: "", Database: "pgx_test"}
}
}

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"fmt" "fmt"
"net" "net"
"os"
"sync" "sync"
"testing" "testing"
"time" "time"
@ -14,7 +15,7 @@ import (
) )
func createConnPool(t *testing.T, maxConnections int) *pgx.ConnPool { func createConnPool(t *testing.T, maxConnections int) *pgx.ConnPool {
config := pgx.ConnPoolConfig{ConnConfig: *defaultConnConfig, MaxConnections: maxConnections} config := pgx.ConnPoolConfig{ConnConfig: mustParseConfig(t, os.Getenv("PGX_TEST_DATABASE")), MaxConnections: maxConnections}
pool, err := pgx.NewConnPool(config) pool, err := pgx.NewConnPool(config)
if err != nil { if err != nil {
t.Fatalf("Unable to create connection pool: %v", err) t.Fatalf("Unable to create connection pool: %v", err)
@ -54,7 +55,7 @@ func TestNewConnPool(t *testing.T) {
return nil return nil
} }
config := pgx.ConnPoolConfig{ConnConfig: *defaultConnConfig, MaxConnections: 2, AfterConnect: afterConnect} config := pgx.ConnPoolConfig{ConnConfig: mustParseConfig(t, os.Getenv("PGX_TEST_DATABASE")), MaxConnections: 2, AfterConnect: afterConnect}
pool, err := pgx.NewConnPool(config) pool, err := pgx.NewConnPool(config)
if err != nil { if err != nil {
t.Fatal("Unable to establish connection pool") t.Fatal("Unable to establish connection pool")
@ -73,7 +74,7 @@ func TestNewConnPool(t *testing.T) {
return errAfterConnect return errAfterConnect
} }
config = pgx.ConnPoolConfig{ConnConfig: *defaultConnConfig, MaxConnections: 2, AfterConnect: afterConnect} config = pgx.ConnPoolConfig{ConnConfig: mustParseConfig(t, os.Getenv("PGX_TEST_DATABASE")), MaxConnections: 2, AfterConnect: afterConnect}
pool, err = pgx.NewConnPool(config) pool, err = pgx.NewConnPool(config)
if err != errAfterConnect { if err != errAfterConnect {
t.Errorf("Expected errAfterConnect but received unexpected: %v", err) t.Errorf("Expected errAfterConnect but received unexpected: %v", err)
@ -83,7 +84,7 @@ func TestNewConnPool(t *testing.T) {
func TestNewConnPoolDefaultsTo5MaxConnections(t *testing.T) { func TestNewConnPoolDefaultsTo5MaxConnections(t *testing.T) {
t.Parallel() t.Parallel()
config := pgx.ConnPoolConfig{ConnConfig: *defaultConnConfig} config := pgx.ConnPoolConfig{ConnConfig: mustParseConfig(t, os.Getenv("PGX_TEST_DATABASE"))}
pool, err := pgx.NewConnPool(config) pool, err := pgx.NewConnPool(config)
if err != nil { if err != nil {
t.Fatal("Unable to establish connection pool") t.Fatal("Unable to establish connection pool")
@ -179,7 +180,7 @@ func TestPoolNonBlockingConnections(t *testing.T) {
maxConnections := 3 maxConnections := 3
config := pgx.ConnPoolConfig{ config := pgx.ConnPoolConfig{
ConnConfig: *defaultConnConfig, ConnConfig: mustParseConfig(t, os.Getenv("PGX_TEST_DATABASE")),
MaxConnections: maxConnections, MaxConnections: maxConnections,
} }
config.ConnConfig.Config.DialFunc = testDialer config.ConnConfig.Config.DialFunc = testDialer
@ -228,7 +229,7 @@ func TestAcquireTimeoutSanity(t *testing.T) {
t.Parallel() t.Parallel()
config := pgx.ConnPoolConfig{ config := pgx.ConnPoolConfig{
ConnConfig: *defaultConnConfig, ConnConfig: mustParseConfig(t, os.Getenv("PGX_TEST_DATABASE")),
MaxConnections: 1, MaxConnections: 1,
} }
@ -260,7 +261,7 @@ func TestPoolWithAcquireTimeoutSet(t *testing.T) {
connAllocTimeout := 2 * time.Second connAllocTimeout := 2 * time.Second
config := pgx.ConnPoolConfig{ config := pgx.ConnPoolConfig{
ConnConfig: *defaultConnConfig, ConnConfig: mustParseConfig(t, os.Getenv("PGX_TEST_DATABASE")),
MaxConnections: 1, MaxConnections: 1,
AcquireTimeout: connAllocTimeout, AcquireTimeout: connAllocTimeout,
} }

View File

@ -3,6 +3,7 @@ package pgx_test
import ( import (
"context" "context"
"fmt" "fmt"
"os"
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
@ -11,19 +12,20 @@ import (
"github.com/jackc/pgx" "github.com/jackc/pgx"
"github.com/jackc/pgx/pgtype" "github.com/jackc/pgx/pgtype"
"github.com/stretchr/testify/require"
) )
func TestCrateDBConnect(t *testing.T) { func TestCrateDBConnect(t *testing.T) {
t.Parallel() t.Parallel()
if cratedbConnConfig == nil { connString := os.Getenv("PGX_TEST_CRATEDB_CONN_STRING")
t.Skip("Skipping due to undefined cratedbConnConfig") if connString == "" {
t.Skipf("Skipping due to missing environment variable %v", "PGX_TEST_CRATEDB_CONN_STRING")
} }
conn, err := pgx.ConnectConfig(context.Background(), cratedbConnConfig) conn, err := pgx.Connect(context.Background(), connString)
if err != nil { require.Nil(t, err)
t.Fatalf("Unable to establish connection: %v", err) defer closeConn(t, conn)
}
var result int var result int
err = conn.QueryRow("select 1 +1").Scan(&result) err = conn.QueryRow("select 1 +1").Scan(&result)
@ -33,17 +35,14 @@ func TestCrateDBConnect(t *testing.T) {
if result != 2 { if result != 2 {
t.Errorf("bad result: %d", result) t.Errorf("bad result: %d", result)
} }
err = conn.Close()
if err != nil {
t.Fatal("Unable to close connection")
}
} }
func TestConnect(t *testing.T) { func TestConnect(t *testing.T) {
t.Parallel() t.Parallel()
conn, err := pgx.ConnectConfig(context.Background(), defaultConnConfig) config := mustParseConfig(t, os.Getenv("PGX_TEST_DATABASE"))
conn, err := pgx.ConnectConfig(context.Background(), &config)
if err != nil { if err != nil {
t.Fatalf("Unable to establish connection: %v", err) t.Fatalf("Unable to establish connection: %v", err)
} }
@ -61,8 +60,8 @@ func TestConnect(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("QueryRow Scan unexpectedly failed: %v", err) t.Fatalf("QueryRow Scan unexpectedly failed: %v", err)
} }
if currentDB != defaultConnConfig.Config.Database { if currentDB != config.Config.Database {
t.Errorf("Did not connect to specified database (%v)", defaultConnConfig.Config.Database) t.Errorf("Did not connect to specified database (%v)", config.Config.Database)
} }
var user string var user string
@ -70,8 +69,8 @@ func TestConnect(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("QueryRow Scan unexpectedly failed: %v", err) t.Fatalf("QueryRow Scan unexpectedly failed: %v", err)
} }
if user != defaultConnConfig.Config.User { if user != config.Config.User {
t.Errorf("Did not connect as specified user (%v)", defaultConnConfig.Config.User) t.Errorf("Did not connect as specified user (%v)", config.Config.User)
} }
err = conn.Close() err = conn.Close()
@ -83,7 +82,7 @@ func TestConnect(t *testing.T) {
func TestConnectWithPreferSimpleProtocol(t *testing.T) { func TestConnectWithPreferSimpleProtocol(t *testing.T) {
t.Parallel() t.Parallel()
connConfig := *defaultConnConfig connConfig := mustParseConfig(t, os.Getenv("PGX_TEST_DATABASE"))
connConfig.PreferSimpleProtocol = true connConfig.PreferSimpleProtocol = true
conn := mustConnect(t, connConfig) conn := mustConnect(t, connConfig)
@ -108,7 +107,7 @@ func TestConnectWithPreferSimpleProtocol(t *testing.T) {
func TestExec(t *testing.T) { func TestExec(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
if results := mustExec(t, conn, "create temporary table foo(id integer primary key);"); results != "CREATE TABLE" { if results := mustExec(t, conn, "create temporary table foo(id integer primary key);"); results != "CREATE TABLE" {
@ -143,7 +142,7 @@ func TestExec(t *testing.T) {
func TestExecFailure(t *testing.T) { func TestExecFailure(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
if _, err := conn.Exec("selct;"); err == nil { if _, err := conn.Exec("selct;"); err == nil {
@ -166,7 +165,7 @@ func TestExecFailure(t *testing.T) {
func TestExecFailureWithArguments(t *testing.T) { func TestExecFailureWithArguments(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
if _, err := conn.Exec("selct $1;", 1); err == nil { if _, err := conn.Exec("selct $1;", 1); err == nil {
@ -180,7 +179,7 @@ func TestExecFailureWithArguments(t *testing.T) {
func TestExecExContextWithoutCancelation(t *testing.T) { func TestExecExContextWithoutCancelation(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
ctx, cancelFunc := context.WithCancel(context.Background()) ctx, cancelFunc := context.WithCancel(context.Background())
@ -201,7 +200,7 @@ func TestExecExContextWithoutCancelation(t *testing.T) {
func TestExecExContextFailureWithoutCancelation(t *testing.T) { func TestExecExContextFailureWithoutCancelation(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
ctx, cancelFunc := context.WithCancel(context.Background()) ctx, cancelFunc := context.WithCancel(context.Background())
@ -227,7 +226,7 @@ func TestExecExContextFailureWithoutCancelation(t *testing.T) {
func TestExecExContextFailureWithoutCancelationWithArguments(t *testing.T) { func TestExecExContextFailureWithoutCancelationWithArguments(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
ctx, cancelFunc := context.WithCancel(context.Background()) ctx, cancelFunc := context.WithCancel(context.Background())
@ -244,7 +243,7 @@ func TestExecExContextFailureWithoutCancelationWithArguments(t *testing.T) {
func TestExecExContextCancelationCancelsQuery(t *testing.T) { func TestExecExContextCancelationCancelsQuery(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
ctx, cancelFunc := context.WithCancel(context.Background()) ctx, cancelFunc := context.WithCancel(context.Background())
@ -267,7 +266,7 @@ func TestExecExContextCancelationCancelsQuery(t *testing.T) {
func TestExecFailureCloseBefore(t *testing.T) { func TestExecFailureCloseBefore(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
closeConn(t, conn) closeConn(t, conn)
if _, err := conn.Exec("select 1"); err == nil { if _, err := conn.Exec("select 1"); err == nil {
@ -281,7 +280,7 @@ func TestExecFailureCloseBefore(t *testing.T) {
func TestExecExExtendedProtocol(t *testing.T) { func TestExecExExtendedProtocol(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
ctx, cancelFunc := context.WithCancel(context.Background()) ctx, cancelFunc := context.WithCancel(context.Background())
@ -314,7 +313,7 @@ func TestExecExExtendedProtocol(t *testing.T) {
func TestExecExSimpleProtocol(t *testing.T) { func TestExecExSimpleProtocol(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
ctx, cancelFunc := context.WithCancel(context.Background()) ctx, cancelFunc := context.WithCancel(context.Background())
@ -351,7 +350,7 @@ func TestExecExSimpleProtocol(t *testing.T) {
func TestConnExecExSuppliedCorrectParameterOIDs(t *testing.T) { func TestConnExecExSuppliedCorrectParameterOIDs(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
mustExec(t, conn, "create temporary table foo(name varchar primary key);") mustExec(t, conn, "create temporary table foo(name varchar primary key);")
@ -376,7 +375,7 @@ func TestConnExecExSuppliedCorrectParameterOIDs(t *testing.T) {
func TestConnExecExSuppliedIncorrectParameterOIDs(t *testing.T) { func TestConnExecExSuppliedIncorrectParameterOIDs(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
mustExec(t, conn, "create temporary table foo(name varchar primary key);") mustExec(t, conn, "create temporary table foo(name varchar primary key);")
@ -398,7 +397,7 @@ func TestConnExecExSuppliedIncorrectParameterOIDs(t *testing.T) {
func TestConnExecExIncorrectParameterOIDsAfterAnotherQuery(t *testing.T) { func TestConnExecExIncorrectParameterOIDsAfterAnotherQuery(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
mustExec(t, conn, "create temporary table foo(name varchar primary key);") mustExec(t, conn, "create temporary table foo(name varchar primary key);")
@ -429,7 +428,7 @@ func TestConnExecExIncorrectParameterOIDsAfterAnotherQuery(t *testing.T) {
func TestExecExFailureCloseBefore(t *testing.T) { func TestExecExFailureCloseBefore(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
closeConn(t, conn) closeConn(t, conn)
if _, err := conn.ExecEx(context.Background(), "select 1", nil); err == nil { if _, err := conn.ExecEx(context.Background(), "select 1", nil); err == nil {
@ -443,7 +442,7 @@ func TestExecExFailureCloseBefore(t *testing.T) {
func TestPrepare(t *testing.T) { func TestPrepare(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
_, err := conn.Prepare("test", "select $1::varchar") _, err := conn.Prepare("test", "select $1::varchar")
@ -495,7 +494,7 @@ func TestPrepare(t *testing.T) {
func TestPrepareBadSQLFailure(t *testing.T) { func TestPrepareBadSQLFailure(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
if _, err := conn.Prepare("badSQL", "select foo"); err == nil { if _, err := conn.Prepare("badSQL", "select foo"); err == nil {
@ -508,7 +507,7 @@ func TestPrepareBadSQLFailure(t *testing.T) {
func TestPrepareQueryManyParameters(t *testing.T) { func TestPrepareQueryManyParameters(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
tests := []struct { tests := []struct {
@ -578,7 +577,7 @@ func TestPrepareQueryManyParameters(t *testing.T) {
func TestPrepareIdempotency(t *testing.T) { func TestPrepareIdempotency(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
for i := 0; i < 2; i++ { for i := 0; i < 2; i++ {
@ -608,7 +607,7 @@ func TestPrepareIdempotency(t *testing.T) {
func TestPrepareEx(t *testing.T) { func TestPrepareEx(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
_, err := conn.PrepareEx(context.Background(), "test", "select $1", &pgx.PrepareExOptions{ParameterOIDs: []pgtype.OID{pgtype.TextOID}}) _, err := conn.PrepareEx(context.Background(), "test", "select $1", &pgx.PrepareExOptions{ParameterOIDs: []pgtype.OID{pgtype.TextOID}})
@ -636,14 +635,14 @@ func TestPrepareEx(t *testing.T) {
func TestListenNotify(t *testing.T) { func TestListenNotify(t *testing.T) {
t.Parallel() t.Parallel()
listener := mustConnect(t, *defaultConnConfig) listener := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, listener) defer closeConn(t, listener)
if err := listener.Listen("chat"); err != nil { if err := listener.Listen("chat"); err != nil {
t.Fatalf("Unable to start listening: %v", err) t.Fatalf("Unable to start listening: %v", err)
} }
notifier := mustConnect(t, *defaultConnConfig) notifier := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, notifier) defer closeConn(t, notifier)
mustExec(t, notifier, "notify chat") mustExec(t, notifier, "notify chat")
@ -700,14 +699,14 @@ func TestListenNotify(t *testing.T) {
func TestUnlistenSpecificChannel(t *testing.T) { func TestUnlistenSpecificChannel(t *testing.T) {
t.Parallel() t.Parallel()
listener := mustConnect(t, *defaultConnConfig) listener := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, listener) defer closeConn(t, listener)
if err := listener.Listen("unlisten_test"); err != nil { if err := listener.Listen("unlisten_test"); err != nil {
t.Fatalf("Unable to start listening: %v", err) t.Fatalf("Unable to start listening: %v", err)
} }
notifier := mustConnect(t, *defaultConnConfig) notifier := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, notifier) defer closeConn(t, notifier)
mustExec(t, notifier, "notify unlisten_test") mustExec(t, notifier, "notify unlisten_test")
@ -747,7 +746,7 @@ func TestListenNotifyWhileBusyIsSafe(t *testing.T) {
listenerDone := make(chan bool) listenerDone := make(chan bool)
go func() { go func() {
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
defer func() { defer func() {
listenerDone <- true listenerDone <- true
@ -790,7 +789,7 @@ func TestListenNotifyWhileBusyIsSafe(t *testing.T) {
}() }()
go func() { go func() {
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
for i := 0; i < 100000; i++ { for i := 0; i < 100000; i++ {
@ -805,7 +804,7 @@ func TestListenNotifyWhileBusyIsSafe(t *testing.T) {
func TestListenNotifySelfNotification(t *testing.T) { func TestListenNotifySelfNotification(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
if err := conn.Listen("self"); err != nil { if err := conn.Listen("self"); err != nil {
@ -848,7 +847,7 @@ func TestListenNotifySelfNotification(t *testing.T) {
func TestListenUnlistenSpecialCharacters(t *testing.T) { func TestListenUnlistenSpecialCharacters(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
chanName := "special characters !@#{$%^&*()}" chanName := "special characters !@#{$%^&*()}"
@ -864,7 +863,7 @@ func TestListenUnlistenSpecialCharacters(t *testing.T) {
func TestFatalRxError(t *testing.T) { func TestFatalRxError(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
var wg sync.WaitGroup var wg sync.WaitGroup
@ -881,10 +880,7 @@ func TestFatalRxError(t *testing.T) {
} }
}() }()
otherConn, err := pgx.ConnectConfig(context.Background(), defaultConnConfig) otherConn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
if err != nil {
t.Fatalf("Unable to establish connection: %v", err)
}
defer otherConn.Close() defer otherConn.Close()
if _, err := otherConn.Exec("select pg_terminate_backend($1)", conn.PID()); err != nil { if _, err := otherConn.Exec("select pg_terminate_backend($1)", conn.PID()); err != nil {
@ -904,16 +900,13 @@ func TestFatalTxError(t *testing.T) {
// Run timing sensitive test many times // Run timing sensitive test many times
for i := 0; i < 50; i++ { for i := 0; i < 50; i++ {
func() { func() {
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
otherConn, err := pgx.ConnectConfig(context.Background(), defaultConnConfig) otherConn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
if err != nil {
t.Fatalf("Unable to establish connection: %v", err)
}
defer otherConn.Close() defer otherConn.Close()
_, err = otherConn.Exec("select pg_terminate_backend($1)", conn.PID()) _, err := otherConn.Exec("select pg_terminate_backend($1)", conn.PID())
if err != nil { if err != nil {
t.Fatalf("Unable to kill backend PostgreSQL process: %v", err) t.Fatalf("Unable to kill backend PostgreSQL process: %v", err)
} }
@ -958,7 +951,7 @@ func TestCommandTag(t *testing.T) {
func TestInsertBoolArray(t *testing.T) { func TestInsertBoolArray(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
if results := mustExec(t, conn, "create temporary table foo(spice bool[]);"); results != "CREATE TABLE" { if results := mustExec(t, conn, "create temporary table foo(spice bool[]);"); results != "CREATE TABLE" {
@ -974,7 +967,7 @@ func TestInsertBoolArray(t *testing.T) {
func TestInsertTimestampArray(t *testing.T) { func TestInsertTimestampArray(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
if results := mustExec(t, conn, "create temporary table foo(spice timestamp[]);"); results != "CREATE TABLE" { if results := mustExec(t, conn, "create temporary table foo(spice timestamp[]);"); results != "CREATE TABLE" {
@ -990,7 +983,7 @@ func TestInsertTimestampArray(t *testing.T) {
func TestCatchSimultaneousConnectionQueries(t *testing.T) { func TestCatchSimultaneousConnectionQueries(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
rows1, err := conn.Query("select generate_series(1,$1)", 10) rows1, err := conn.Query("select generate_series(1,$1)", 10)
@ -1008,7 +1001,7 @@ func TestCatchSimultaneousConnectionQueries(t *testing.T) {
func TestCatchSimultaneousConnectionQueryAndExec(t *testing.T) { func TestCatchSimultaneousConnectionQueryAndExec(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
rows, err := conn.Query("select generate_series(1,$1)", 10) rows, err := conn.Query("select generate_series(1,$1)", 10)
@ -1040,7 +1033,7 @@ func (l *testLogger) Log(level pgx.LogLevel, msg string, data map[string]interfa
func TestSetLogger(t *testing.T) { func TestSetLogger(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
l1 := &testLogger{} l1 := &testLogger{}
@ -1075,7 +1068,7 @@ func TestSetLogger(t *testing.T) {
func TestSetLogLevel(t *testing.T) { func TestSetLogLevel(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
logger := &testLogger{} logger := &testLogger{}
@ -1152,7 +1145,7 @@ func TestConnOnNotice(t *testing.T) {
var msg string var msg string
connConfig := *defaultConnConfig connConfig := mustParseConfig(t, os.Getenv("PGX_TEST_DATABASE"))
connConfig.OnNotice = func(c *pgx.Conn, notice *pgx.Notice) { connConfig.OnNotice = func(c *pgx.Conn, notice *pgx.Notice) {
msg = notice.Message msg = notice.Message
} }
@ -1175,7 +1168,7 @@ end$$;`)
} }
func TestConnInitConnInfo(t *testing.T) { func TestConnInitConnInfo(t *testing.T) {
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
// spot check that the standard postgres type names aren't qualified // spot check that the standard postgres type names aren't qualified
@ -1203,7 +1196,7 @@ func TestConnInitConnInfo(t *testing.T) {
} }
func TestDomainType(t *testing.T) { func TestDomainType(t *testing.T) {
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
dt, ok := conn.ConnInfo.DataTypeForName("uint64") dt, ok := conn.ConnInfo.DataTypeForName("uint64")

View File

@ -18,7 +18,7 @@ import (
func TestConnCopyFromSmall(t *testing.T) { func TestConnCopyFromSmall(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
mustExec(t, conn, `create temporary table foo( mustExec(t, conn, `create temporary table foo(
@ -109,7 +109,7 @@ func TestConnCopyFromSmall(t *testing.T) {
func TestConnCopyFromLarge(t *testing.T) { func TestConnCopyFromLarge(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
mustExec(t, conn, `create temporary table foo( mustExec(t, conn, `create temporary table foo(
@ -202,7 +202,7 @@ func TestConnCopyFromLarge(t *testing.T) {
func TestConnCopyFromJSON(t *testing.T) { func TestConnCopyFromJSON(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
for _, typeName := range []string{"json", "jsonb"} { for _, typeName := range []string{"json", "jsonb"} {
@ -313,7 +313,7 @@ func (cfs *clientFailSource) Err() error {
func TestConnCopyFromFailServerSideMidway(t *testing.T) { func TestConnCopyFromFailServerSideMidway(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
mustExec(t, conn, `create temporary table foo( mustExec(t, conn, `create temporary table foo(
@ -424,7 +424,7 @@ func (fs *failSource) Err() error {
func TestConnCopyFromFailServerSideMidwayAbortsWithoutWaiting(t *testing.T) { func TestConnCopyFromFailServerSideMidwayAbortsWithoutWaiting(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
mustExec(t, conn, `create temporary table foo( mustExec(t, conn, `create temporary table foo(
@ -478,7 +478,7 @@ func TestConnCopyFromFailServerSideMidwayAbortsWithoutWaiting(t *testing.T) {
func TestConnCopyFromCopyFromSourceErrorMidway(t *testing.T) { func TestConnCopyFromCopyFromSourceErrorMidway(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
mustExec(t, conn, `create temporary table foo( mustExec(t, conn, `create temporary table foo(
@ -538,7 +538,7 @@ func (cfs *clientFinalErrSource) Err() error {
func TestConnCopyFromCopyFromSourceErrorEnd(t *testing.T) { func TestConnCopyFromCopyFromSourceErrorEnd(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
mustExec(t, conn, `create temporary table foo( mustExec(t, conn, `create temporary table foo(
@ -596,7 +596,7 @@ func (cfs *nextPanicSource) Err() error {
func TestConnCopyFromCopyFromSourceNextPanic(t *testing.T) { func TestConnCopyFromCopyFromSourceNextPanic(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
mustExec(t, conn, `create temporary table foo( mustExec(t, conn, `create temporary table foo(
@ -627,7 +627,7 @@ func TestConnCopyFromCopyFromSourceNextPanic(t *testing.T) {
func TestConnCopyFromReaderQueryError(t *testing.T) { func TestConnCopyFromReaderQueryError(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
inputReader := strings.NewReader("") inputReader := strings.NewReader("")
@ -652,7 +652,7 @@ func TestConnCopyFromReaderQueryError(t *testing.T) {
func TestConnCopyFromReaderNoTableError(t *testing.T) { func TestConnCopyFromReaderNoTableError(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
inputReader := strings.NewReader("") inputReader := strings.NewReader("")
@ -677,7 +677,7 @@ func TestConnCopyFromReaderNoTableError(t *testing.T) {
func TestConnCopyFromGzipReader(t *testing.T) { func TestConnCopyFromGzipReader(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
mustExec(t, conn, `create temporary table foo( mustExec(t, conn, `create temporary table foo(

View File

@ -2,6 +2,7 @@ package pgx_test
import ( import (
"bytes" "bytes"
"os"
"testing" "testing"
"github.com/jackc/pgx" "github.com/jackc/pgx"
@ -10,7 +11,7 @@ import (
func TestConnCopyToWriterSmall(t *testing.T) { func TestConnCopyToWriterSmall(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
mustExec(t, conn, `create temporary table foo( mustExec(t, conn, `create temporary table foo(
@ -50,7 +51,7 @@ func TestConnCopyToWriterSmall(t *testing.T) {
func TestConnCopyToWriterLarge(t *testing.T) { func TestConnCopyToWriterLarge(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
mustExec(t, conn, `create temporary table foo( mustExec(t, conn, `create temporary table foo(
@ -92,7 +93,7 @@ func TestConnCopyToWriterLarge(t *testing.T) {
func TestConnCopyToWriterQueryError(t *testing.T) { func TestConnCopyToWriterQueryError(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
outputWriter := bytes.NewBuffer(make([]byte, 0)) outputWriter := bytes.NewBuffer(make([]byte, 0))

View File

@ -3,6 +3,7 @@ package pgx_test
import ( import (
"context" "context"
"fmt" "fmt"
"os"
"regexp" "regexp"
"strconv" "strconv"
@ -73,7 +74,7 @@ func (src *Point) String() string {
} }
func Example_CustomType() { func Example_CustomType() {
conn, err := pgx.ConnectConfig(context.Background(), defaultConnConfig) conn, err := pgx.Connect(context.Background(), os.Getenv("PGX_TEST_DATABASE"))
if err != nil { if err != nil {
fmt.Printf("Unable to establish connection: %v", err) fmt.Printf("Unable to establish connection: %v", err)
return return

View File

@ -3,12 +3,13 @@ package pgx_test
import ( import (
"context" "context"
"fmt" "fmt"
"os"
"github.com/jackc/pgx" "github.com/jackc/pgx"
) )
func Example_JSON() { func Example_JSON() {
conn, err := pgx.ConnectConfig(context.Background(), defaultConnConfig) conn, err := pgx.Connect(context.Background(), os.Getenv("PGX_TEST_DATABASE"))
if err != nil { if err != nil {
fmt.Printf("Unable to establish connection: %v", err) fmt.Printf("Unable to establish connection: %v", err)
return return

View File

@ -5,8 +5,24 @@ import (
"testing" "testing"
"github.com/jackc/pgx" "github.com/jackc/pgx"
"github.com/jackc/pgx/pgconn"
"github.com/stretchr/testify/require"
) )
func mustConnectString(t testing.TB, connString string) *pgx.Conn {
conn, err := pgx.Connect(context.Background(), connString)
if err != nil {
t.Fatalf("Unable to establish connection: %v", err)
}
return conn
}
func mustParseConfig(t testing.TB, connString string) pgx.ConnConfig {
config, err := pgconn.ParseConfig(connString)
require.Nil(t, err)
return pgx.ConnConfig{Config: *config}
}
func mustConnect(t testing.TB, config pgx.ConnConfig) *pgx.Conn { func mustConnect(t testing.TB, config pgx.ConnConfig) *pgx.Conn {
conn, err := pgx.ConnectConfig(context.Background(), &config) conn, err := pgx.ConnectConfig(context.Background(), &config)
if err != nil { if err != nil {

View File

@ -3,6 +3,7 @@ package pgx_test
import ( import (
"context" "context"
"io" "io"
"os"
"testing" "testing"
"github.com/jackc/pgx" "github.com/jackc/pgx"
@ -11,7 +12,7 @@ import (
func TestLargeObjects(t *testing.T) { func TestLargeObjects(t *testing.T) {
t.Parallel() t.Parallel()
conn, err := pgx.ConnectConfig(context.Background(), defaultConnConfig) conn, err := pgx.Connect(context.Background(), os.Getenv("PGX_TEST_DATABASE"))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -124,7 +125,7 @@ func TestLargeObjects(t *testing.T) {
func TestLargeObjectsMultipleTransactions(t *testing.T) { func TestLargeObjectsMultipleTransactions(t *testing.T) {
t.Parallel() t.Parallel()
conn, err := pgx.ConnectConfig(context.Background(), defaultConnConfig) conn, err := pgx.Connect(context.Background(), os.Getenv("PGX_TEST_DATABASE"))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -5,6 +5,7 @@ import (
"context" "context"
"database/sql" "database/sql"
"fmt" "fmt"
"os"
"reflect" "reflect"
"strings" "strings"
"testing" "testing"
@ -14,14 +15,14 @@ import (
"github.com/jackc/pgx" "github.com/jackc/pgx"
"github.com/jackc/pgx/pgtype" "github.com/jackc/pgx/pgtype"
satori "github.com/jackc/pgx/pgtype/ext/satori-uuid" satori "github.com/jackc/pgx/pgtype/ext/satori-uuid"
"github.com/satori/go.uuid" uuid "github.com/satori/go.uuid"
"github.com/shopspring/decimal" "github.com/shopspring/decimal"
) )
func TestConnQueryScan(t *testing.T) { func TestConnQueryScan(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
var sum, rowCount int32 var sum, rowCount int32
@ -54,7 +55,7 @@ func TestConnQueryScan(t *testing.T) {
func TestConnQueryScanWithManyColumns(t *testing.T) { func TestConnQueryScanWithManyColumns(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
columnCount := 1000 columnCount := 1000
@ -106,7 +107,7 @@ func TestConnQueryScanWithManyColumns(t *testing.T) {
func TestConnQueryValues(t *testing.T) { func TestConnQueryValues(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
var rowCount int32 var rowCount int32
@ -160,7 +161,7 @@ func TestConnQueryValues(t *testing.T) {
func TestConnQueryValuesWithMultipleComplexColumnsOfSameType(t *testing.T) { func TestConnQueryValuesWithMultipleComplexColumnsOfSameType(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
expected0 := &pgtype.Int8Array{ expected0 := &pgtype.Int8Array{
@ -222,7 +223,7 @@ func TestConnQueryValuesWithMultipleComplexColumnsOfSameType(t *testing.T) {
func TestRowsScanDoesNotAllowScanningBinaryFormatValuesIntoString(t *testing.T) { func TestRowsScanDoesNotAllowScanningBinaryFormatValuesIntoString(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
var s string var s string
@ -239,7 +240,7 @@ func TestRowsScanDoesNotAllowScanningBinaryFormatValuesIntoString(t *testing.T)
func TestConnQueryCloseEarly(t *testing.T) { func TestConnQueryCloseEarly(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
// Immediately close query without reading any rows // Immediately close query without reading any rows
@ -276,7 +277,7 @@ func TestConnQueryCloseEarly(t *testing.T) {
func TestConnQueryCloseEarlyWithErrorOnWire(t *testing.T) { func TestConnQueryCloseEarlyWithErrorOnWire(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
rows, err := conn.Query("select 1/(10-n) from generate_series(1,10) n") rows, err := conn.Query("select 1/(10-n) from generate_series(1,10) n")
@ -295,7 +296,7 @@ func TestConnQueryCloseEarlyWithErrorOnWire(t *testing.T) {
func TestConnQueryReadWrongTypeError(t *testing.T) { func TestConnQueryReadWrongTypeError(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
// Read a single value incorrectly // Read a single value incorrectly
@ -331,7 +332,7 @@ func TestConnQueryReadWrongTypeError(t *testing.T) {
func TestConnQueryReadTooManyValues(t *testing.T) { func TestConnQueryReadTooManyValues(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
// Read too many values // Read too many values
@ -362,7 +363,7 @@ func TestConnQueryReadTooManyValues(t *testing.T) {
func TestConnQueryScanIgnoreColumn(t *testing.T) { func TestConnQueryScanIgnoreColumn(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
rows, err := conn.Query("select 1::int8, 2::int8, 3::int8") rows, err := conn.Query("select 1::int8, 2::int8, 3::int8")
@ -396,7 +397,7 @@ func TestConnQueryScanIgnoreColumn(t *testing.T) {
func TestConnQueryErrorWhileReturningRows(t *testing.T) { func TestConnQueryErrorWhileReturningRows(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
for i := 0; i < 100; i++ { for i := 0; i < 100; i++ {
@ -427,7 +428,7 @@ func TestConnQueryErrorWhileReturningRows(t *testing.T) {
func TestQueryEncodeError(t *testing.T) { func TestQueryEncodeError(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
rows, err := conn.Query("select $1::integer", "wrong") rows, err := conn.Query("select $1::integer", "wrong")
@ -452,7 +453,7 @@ func TestQueryEncodeError(t *testing.T) {
func TestQueryRowCoreTypes(t *testing.T) { func TestQueryRowCoreTypes(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
type allTypes struct { type allTypes struct {
@ -509,7 +510,7 @@ func TestQueryRowCoreTypes(t *testing.T) {
func TestQueryRowCoreIntegerEncoding(t *testing.T) { func TestQueryRowCoreIntegerEncoding(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
type allTypes struct { type allTypes struct {
@ -624,7 +625,7 @@ func TestQueryRowCoreIntegerEncoding(t *testing.T) {
func TestQueryRowCoreIntegerDecoding(t *testing.T) { func TestQueryRowCoreIntegerDecoding(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
type allTypes struct { type allTypes struct {
@ -799,7 +800,7 @@ func TestQueryRowCoreIntegerDecoding(t *testing.T) {
func TestQueryRowCoreByteSlice(t *testing.T) { func TestQueryRowCoreByteSlice(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
tests := []struct { tests := []struct {
@ -832,7 +833,7 @@ func TestQueryRowCoreByteSlice(t *testing.T) {
func TestQueryRowUnknownType(t *testing.T) { func TestQueryRowUnknownType(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
// Clear existing type mappings // Clear existing type mappings
@ -868,7 +869,7 @@ func TestQueryRowUnknownType(t *testing.T) {
func TestQueryRowErrors(t *testing.T) { func TestQueryRowErrors(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
type allTypes struct { type allTypes struct {
@ -909,7 +910,7 @@ func TestQueryRowErrors(t *testing.T) {
func TestQueryRowExErrorsWrongParameterOIDs(t *testing.T) { func TestQueryRowExErrorsWrongParameterOIDs(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
sql := ` sql := `
@ -946,7 +947,7 @@ func TestQueryRowExErrorsWrongParameterOIDs(t *testing.T) {
func TestQueryRowNoResults(t *testing.T) { func TestQueryRowNoResults(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
var n int32 var n int32
@ -959,7 +960,7 @@ func TestQueryRowNoResults(t *testing.T) {
} }
func TestReadingValueAfterEmptyArray(t *testing.T) { func TestReadingValueAfterEmptyArray(t *testing.T) {
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
var a []string var a []string
@ -979,7 +980,7 @@ func TestReadingValueAfterEmptyArray(t *testing.T) {
} }
func TestReadingNullByteArray(t *testing.T) { func TestReadingNullByteArray(t *testing.T) {
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
var a []byte var a []byte
@ -994,7 +995,7 @@ func TestReadingNullByteArray(t *testing.T) {
} }
func TestReadingNullByteArrays(t *testing.T) { func TestReadingNullByteArrays(t *testing.T) {
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
rows, err := conn.Query("select null::text union all select null::text") rows, err := conn.Query("select null::text union all select null::text")
@ -1023,7 +1024,7 @@ func TestReadingNullByteArrays(t *testing.T) {
func TestConnQueryDatabaseSQLScanner(t *testing.T) { func TestConnQueryDatabaseSQLScanner(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
var num decimal.Decimal var num decimal.Decimal
@ -1050,7 +1051,7 @@ func TestConnQueryDatabaseSQLScanner(t *testing.T) {
func TestConnQueryDatabaseSQLDriverValuer(t *testing.T) { func TestConnQueryDatabaseSQLDriverValuer(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
expected, err := decimal.NewFromString("1234.567") expected, err := decimal.NewFromString("1234.567")
@ -1075,7 +1076,7 @@ func TestConnQueryDatabaseSQLDriverValuer(t *testing.T) {
func TestConnQueryDatabaseSQLDriverValuerWithAutoGeneratedPointerReceiver(t *testing.T) { func TestConnQueryDatabaseSQLDriverValuerWithAutoGeneratedPointerReceiver(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
mustExec(t, conn, "create temporary table t(n numeric)") mustExec(t, conn, "create temporary table t(n numeric)")
@ -1095,7 +1096,7 @@ func TestConnQueryDatabaseSQLDriverValuerWithAutoGeneratedPointerReceiver(t *tes
func TestConnQueryDatabaseSQLDriverValuerWithBinaryPgTypeThatAcceptsSameType(t *testing.T) { func TestConnQueryDatabaseSQLDriverValuerWithBinaryPgTypeThatAcceptsSameType(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
conn.ConnInfo.RegisterDataType(pgtype.DataType{ conn.ConnInfo.RegisterDataType(pgtype.DataType{
@ -1125,7 +1126,7 @@ func TestConnQueryDatabaseSQLDriverValuerWithBinaryPgTypeThatAcceptsSameType(t *
func TestConnQueryDatabaseSQLNullX(t *testing.T) { func TestConnQueryDatabaseSQLNullX(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
type row struct { type row struct {
@ -1182,7 +1183,7 @@ func TestConnQueryDatabaseSQLNullX(t *testing.T) {
func TestQueryExContextSuccess(t *testing.T) { func TestQueryExContextSuccess(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
ctx, cancelFunc := context.WithCancel(context.Background()) ctx, cancelFunc := context.WithCancel(context.Background())
@ -1222,7 +1223,7 @@ func TestQueryExContextSuccess(t *testing.T) {
func TestQueryExContextErrorWhileReceivingRows(t *testing.T) { func TestQueryExContextErrorWhileReceivingRows(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
ctx, cancelFunc := context.WithCancel(context.Background()) ctx, cancelFunc := context.WithCancel(context.Background())
@ -1259,7 +1260,7 @@ func TestQueryExContextErrorWhileReceivingRows(t *testing.T) {
func TestQueryExContextCancelationCancelsQuery(t *testing.T) { func TestQueryExContextCancelationCancelsQuery(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
ctx, cancelFunc := context.WithCancel(context.Background()) ctx, cancelFunc := context.WithCancel(context.Background())
@ -1290,7 +1291,7 @@ func TestQueryExContextCancelationCancelsQuery(t *testing.T) {
func TestQueryRowExContextSuccess(t *testing.T) { func TestQueryRowExContextSuccess(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
ctx, cancelFunc := context.WithCancel(context.Background()) ctx, cancelFunc := context.WithCancel(context.Background())
@ -1314,7 +1315,7 @@ func TestQueryRowExContextSuccess(t *testing.T) {
func TestQueryRowExContextErrorWhileReceivingRow(t *testing.T) { func TestQueryRowExContextErrorWhileReceivingRow(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
ctx, cancelFunc := context.WithCancel(context.Background()) ctx, cancelFunc := context.WithCancel(context.Background())
@ -1332,7 +1333,7 @@ func TestQueryRowExContextErrorWhileReceivingRow(t *testing.T) {
func TestQueryRowExContextCancelationCancelsQuery(t *testing.T) { func TestQueryRowExContextCancelationCancelsQuery(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
ctx, cancelFunc := context.WithCancel(context.Background()) ctx, cancelFunc := context.WithCancel(context.Background())
@ -1356,7 +1357,7 @@ func TestQueryRowExContextCancelationCancelsQuery(t *testing.T) {
func TestConnQueryRowExSingleRoundTrip(t *testing.T) { func TestConnQueryRowExSingleRoundTrip(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
var result int32 var result int32
@ -1382,7 +1383,7 @@ func TestConnQueryRowExSingleRoundTrip(t *testing.T) {
func TestConnSimpleProtocol(t *testing.T) { func TestConnSimpleProtocol(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
// Test all supported low-level types // Test all supported low-level types
@ -1579,7 +1580,7 @@ func TestConnSimpleProtocol(t *testing.T) {
func TestConnSimpleProtocolRefusesNonUTF8ClientEncoding(t *testing.T) { func TestConnSimpleProtocolRefusesNonUTF8ClientEncoding(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
mustExec(t, conn, "set client_encoding to 'SQL_ASCII'") mustExec(t, conn, "set client_encoding to 'SQL_ASCII'")
@ -1601,7 +1602,7 @@ func TestConnSimpleProtocolRefusesNonUTF8ClientEncoding(t *testing.T) {
func TestConnSimpleProtocolRefusesNonStandardConformingStrings(t *testing.T) { func TestConnSimpleProtocolRefusesNonStandardConformingStrings(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
mustExec(t, conn, "set standard_conforming_strings to off") mustExec(t, conn, "set standard_conforming_strings to off")
@ -1623,7 +1624,7 @@ func TestConnSimpleProtocolRefusesNonStandardConformingStrings(t *testing.T) {
func TestQueryExCloseBefore(t *testing.T) { func TestQueryExCloseBefore(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
closeConn(t, conn) closeConn(t, conn)
if _, err := conn.QueryEx(context.Background(), "select 1", nil); err == nil { if _, err := conn.QueryEx(context.Background(), "select 1", nil); err == nil {

View File

@ -3,6 +3,7 @@ package pgx_test
import ( import (
"context" "context"
"fmt" "fmt"
"os"
"reflect" "reflect"
"strconv" "strconv"
"strings" "strings"
@ -41,11 +42,12 @@ func getConfirmedFlushLsnFor(t *testing.T, conn *pgx.Conn, slot string) string {
func TestSimpleReplicationConnection(t *testing.T) { func TestSimpleReplicationConnection(t *testing.T) {
var err error var err error
if replicationConnConfig == nil { connString := os.Getenv("PGX_TEST_REPLICATION_CONN_STRING")
t.Skip("Skipping due to undefined replicationConnConfig") if connString == "" {
t.Skipf("Skipping due to missing environment variable %v", "PGX_TEST_REPLICATION_CONN_STRING")
} }
conn := mustConnect(t, *replicationConnConfig) conn := mustConnectString(t, connString)
defer func() { defer func() {
// Ensure replication slot is destroyed, but don't check for errors as it // Ensure replication slot is destroyed, but don't check for errors as it
// should have already been destroyed. // should have already been destroyed.
@ -53,7 +55,8 @@ func TestSimpleReplicationConnection(t *testing.T) {
closeConn(t, conn) closeConn(t, conn)
}() }()
replicationConn := mustReplicationConnect(t, *replicationConnConfig) replicationConnConfig := mustParseConfig(t, connString)
replicationConn := mustReplicationConnect(t, replicationConnConfig)
defer closeReplicationConn(t, replicationConn) defer closeReplicationConn(t, replicationConn)
var cp string var cp string
@ -164,7 +167,7 @@ func TestSimpleReplicationConnection(t *testing.T) {
closeReplicationConn(t, replicationConn) closeReplicationConn(t, replicationConn)
replicationConn2 := mustReplicationConnect(t, *replicationConnConfig) replicationConn2 := mustReplicationConnect(t, replicationConnConfig)
defer closeReplicationConn(t, replicationConn2) defer closeReplicationConn(t, replicationConn2)
err = replicationConn2.DropReplicationSlot("pgx_test") err = replicationConn2.DropReplicationSlot("pgx_test")
@ -179,11 +182,13 @@ func TestSimpleReplicationConnection(t *testing.T) {
} }
func TestReplicationConn_DropReplicationSlot(t *testing.T) { func TestReplicationConn_DropReplicationSlot(t *testing.T) {
if replicationConnConfig == nil { connString := os.Getenv("PGX_TEST_REPLICATION_CONN_STRING")
t.Skip("Skipping due to undefined replicationConnConfig") if connString == "" {
t.Skipf("Skipping due to missing environment variable %v", "PGX_TEST_REPLICATION_CONN_STRING")
} }
replicationConn := mustReplicationConnect(t, *replicationConnConfig) replicationConnConfig := mustParseConfig(t, connString)
replicationConn := mustReplicationConnect(t, replicationConnConfig)
defer closeReplicationConn(t, replicationConn) defer closeReplicationConn(t, replicationConn)
var cp string var cp string
@ -224,11 +229,13 @@ func TestReplicationConn_DropReplicationSlot(t *testing.T) {
} }
func TestIdentifySystem(t *testing.T) { func TestIdentifySystem(t *testing.T) {
if replicationConnConfig == nil { connString := os.Getenv("PGX_TEST_REPLICATION_CONN_STRING")
t.Skip("Skipping due to undefined replicationConnConfig") if connString == "" {
t.Skipf("Skipping due to missing environment variable %v", "PGX_TEST_REPLICATION_CONN_STRING")
} }
replicationConn2 := mustReplicationConnect(t, *replicationConnConfig) replicationConnConfig := mustParseConfig(t, connString)
replicationConn2 := mustReplicationConnect(t, replicationConnConfig)
defer closeReplicationConn(t, replicationConn2) defer closeReplicationConn(t, replicationConn2)
r, err := replicationConn2.IdentifySystem() r, err := replicationConn2.IdentifySystem()
@ -276,11 +283,13 @@ func getCurrentTimeline(t *testing.T, rc *pgx.ReplicationConn) int {
} }
func TestGetTimelineHistory(t *testing.T) { func TestGetTimelineHistory(t *testing.T) {
if replicationConnConfig == nil { connString := os.Getenv("PGX_TEST_REPLICATION_CONN_STRING")
t.Skip("Skipping due to undefined replicationConnConfig") if connString == "" {
t.Skipf("Skipping due to missing environment variable %v", "PGX_TEST_REPLICATION_CONN_STRING")
} }
replicationConn := mustReplicationConnect(t, *replicationConnConfig) replicationConnConfig := mustParseConfig(t, connString)
replicationConn := mustReplicationConnect(t, replicationConnConfig)
defer closeReplicationConn(t, replicationConn) defer closeReplicationConn(t, replicationConn)
timeline := getCurrentTimeline(t, replicationConn) timeline := getCurrentTimeline(t, replicationConn)

View File

@ -1,8 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -eux set -eux
mv conn_config_test.go.travis conn_config_test.go
if [ "${PGVERSION-}" != "" ] if [ "${PGVERSION-}" != "" ]
then then
# The tricky test user, below, has to actually exist so that it can be used in a test # The tricky test user, below, has to actually exist so that it can be used in a test

View File

@ -3,6 +3,7 @@ package pgx_test
import ( import (
"context" "context"
"fmt" "fmt"
"os"
"testing" "testing"
"time" "time"
@ -15,7 +16,7 @@ import (
func TestTransactionSuccessfulCommit(t *testing.T) { func TestTransactionSuccessfulCommit(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
createSql := ` createSql := `
@ -57,7 +58,7 @@ func TestTransactionSuccessfulCommit(t *testing.T) {
func TestTxCommitWhenTxBroken(t *testing.T) { func TestTxCommitWhenTxBroken(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
createSql := ` createSql := `
@ -149,7 +150,7 @@ func TestTxCommitSerializationFailure(t *testing.T) {
func TestTransactionSuccessfulRollback(t *testing.T) { func TestTransactionSuccessfulRollback(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
createSql := ` createSql := `
@ -191,7 +192,7 @@ func TestTransactionSuccessfulRollback(t *testing.T) {
func TestBeginExIsoLevels(t *testing.T) { func TestBeginExIsoLevels(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
isoLevels := []pgx.TxIsoLevel{pgx.Serializable, pgx.RepeatableRead, pgx.ReadCommitted, pgx.ReadUncommitted} isoLevels := []pgx.TxIsoLevel{pgx.Serializable, pgx.RepeatableRead, pgx.ReadCommitted, pgx.ReadUncommitted}
@ -217,7 +218,7 @@ func TestBeginExIsoLevels(t *testing.T) {
func TestBeginExReadOnly(t *testing.T) { func TestBeginExReadOnly(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
tx, err := conn.BeginEx(context.Background(), &pgx.TxOptions{AccessMode: pgx.ReadOnly}) tx, err := conn.BeginEx(context.Background(), &pgx.TxOptions{AccessMode: pgx.ReadOnly})
@ -336,7 +337,7 @@ func TestTxCommitExCancel(t *testing.T) {
func TestTxStatus(t *testing.T) { func TestTxStatus(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
tx, err := conn.Begin() tx, err := conn.Begin()
@ -360,7 +361,7 @@ func TestTxStatus(t *testing.T) {
func TestTxStatusErrorInTransactions(t *testing.T) { func TestTxStatusErrorInTransactions(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
tx, err := conn.Begin() tx, err := conn.Begin()
@ -407,7 +408,7 @@ func TestTxStatusErrorInTransactions(t *testing.T) {
func TestTxErr(t *testing.T) { func TestTxErr(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
tx, err := conn.Begin() tx, err := conn.Begin()

1
v4.md
View File

@ -35,6 +35,7 @@ Minor Potential Changes:
## Changes ## Changes
`pgconn.PgConn` now contains core PostgreSQL connection functionality. `pgconn.PgConn` now contains core PostgreSQL connection functionality.
Test configuration now done with environment variables instead of `.gitignore`'d locally modified `conn_config_test.go` file.
### Incompatible Changes ### Incompatible Changes

View File

@ -3,6 +3,7 @@ package pgx_test
import ( import (
"bytes" "bytes"
"net" "net"
"os"
"reflect" "reflect"
"testing" "testing"
"time" "time"
@ -13,7 +14,7 @@ import (
func TestDateTranscode(t *testing.T) { func TestDateTranscode(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
dates := []time.Time{ dates := []time.Time{
@ -53,7 +54,7 @@ func TestDateTranscode(t *testing.T) {
func TestTimestampTzTranscode(t *testing.T) { func TestTimestampTzTranscode(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
inputTime := time.Date(2013, 1, 2, 3, 4, 5, 6000, time.Local) inputTime := time.Date(2013, 1, 2, 3, 4, 5, 6000, time.Local)
@ -74,7 +75,7 @@ func TestTimestampTzTranscode(t *testing.T) {
func TestJSONAndJSONBTranscode(t *testing.T) { func TestJSONAndJSONBTranscode(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
for _, typename := range []string{"json", "jsonb"} { for _, typename := range []string{"json", "jsonb"} {
@ -229,7 +230,7 @@ func mustParseCIDR(t *testing.T, s string) *net.IPNet {
func TestStringToNotTextTypeTranscode(t *testing.T) { func TestStringToNotTextTypeTranscode(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
input := "01086ee0-4963-4e35-9116-30c173a8d0bd" input := "01086ee0-4963-4e35-9116-30c173a8d0bd"
@ -255,7 +256,7 @@ func TestStringToNotTextTypeTranscode(t *testing.T) {
func TestInetCIDRTranscodeIPNet(t *testing.T) { func TestInetCIDRTranscodeIPNet(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
tests := []struct { tests := []struct {
@ -304,7 +305,7 @@ func TestInetCIDRTranscodeIPNet(t *testing.T) {
func TestInetCIDRTranscodeIP(t *testing.T) { func TestInetCIDRTranscodeIP(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
tests := []struct { tests := []struct {
@ -364,7 +365,7 @@ func TestInetCIDRTranscodeIP(t *testing.T) {
func TestInetCIDRArrayTranscodeIPNet(t *testing.T) { func TestInetCIDRArrayTranscodeIPNet(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
tests := []struct { tests := []struct {
@ -423,7 +424,7 @@ func TestInetCIDRArrayTranscodeIPNet(t *testing.T) {
func TestInetCIDRArrayTranscodeIP(t *testing.T) { func TestInetCIDRArrayTranscodeIP(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
tests := []struct { tests := []struct {
@ -504,7 +505,7 @@ func TestInetCIDRArrayTranscodeIP(t *testing.T) {
func TestInetCIDRTranscodeWithJustIP(t *testing.T) { func TestInetCIDRTranscodeWithJustIP(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
tests := []struct { tests := []struct {
@ -546,7 +547,7 @@ func TestInetCIDRTranscodeWithJustIP(t *testing.T) {
func TestArrayDecoding(t *testing.T) { func TestArrayDecoding(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
tests := []struct { tests := []struct {
@ -660,7 +661,7 @@ func TestArrayDecoding(t *testing.T) {
func TestEmptyArrayDecoding(t *testing.T) { func TestEmptyArrayDecoding(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
var val []string var val []string
@ -708,7 +709,7 @@ func TestEmptyArrayDecoding(t *testing.T) {
func TestPointerPointer(t *testing.T) { func TestPointerPointer(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
type allTypes struct { type allTypes struct {
@ -786,7 +787,7 @@ func TestPointerPointer(t *testing.T) {
func TestPointerPointerNonZero(t *testing.T) { func TestPointerPointerNonZero(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
f := "foo" f := "foo"
@ -804,7 +805,7 @@ func TestPointerPointerNonZero(t *testing.T) {
func TestEncodeTypeRename(t *testing.T) { func TestEncodeTypeRename(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
type _int int type _int int
@ -908,7 +909,7 @@ func TestEncodeTypeRename(t *testing.T) {
func TestRowDecode(t *testing.T) { func TestRowDecode(t *testing.T) {
t.Parallel() t.Parallel()
conn := mustConnect(t, *defaultConnConfig) conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer closeConn(t, conn) defer closeConn(t, conn)
tests := []struct { tests := []struct {