diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 862235a..8961b4b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,19 +10,58 @@ jobs: test: name: Test - runs-on: ubuntu-latest + runs-on: ubuntu-18.04 strategy: + fail-fast: false matrix: - go_version: [1.14, 1.15] - pg_version: [9.6, 10, 11, 12, 13] + go-version: [1.15, 1.16] + pg-version: [9.6, 10, 11, 12, 13, cockroachdb] + include: + - pg-version: 9.6 + pgx-test-conn-string: postgres://pgx_md5:secret@127.0.0.1/pgx_test + pgx-test-unix-socket-conn-string: "host=/var/run/postgresql dbname=pgx_test" + pgx-test-tcp-conn-string: postgres://pgx_md5:secret@127.0.0.1/pgx_test + pgx-test-tls-conn-string: postgres://pgx_md5:secret@127.0.0.1/pgx_test?sslmode=require + 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 + - pg-version: 10 + pgx-test-conn-string: postgres://pgx_md5:secret@127.0.0.1/pgx_test + pgx-test-unix-socket-conn-string: "host=/var/run/postgresql dbname=pgx_test" + pgx-test-tcp-conn-string: postgres://pgx_md5:secret@127.0.0.1/pgx_test + pgx-test-tls-conn-string: postgres://pgx_md5:secret@127.0.0.1/pgx_test?sslmode=require + 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 + - pg-version: 11 + pgx-test-conn-string: postgres://pgx_md5:secret@127.0.0.1/pgx_test + pgx-test-unix-socket-conn-string: "host=/var/run/postgresql dbname=pgx_test" + pgx-test-tcp-conn-string: postgres://pgx_md5:secret@127.0.0.1/pgx_test + pgx-test-tls-conn-string: postgres://pgx_md5:secret@127.0.0.1/pgx_test?sslmode=require + 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 + - pg-version: 12 + pgx-test-conn-string: postgres://pgx_md5:secret@127.0.0.1/pgx_test + pgx-test-unix-socket-conn-string: "host=/var/run/postgresql dbname=pgx_test" + pgx-test-tcp-conn-string: postgres://pgx_md5:secret@127.0.0.1/pgx_test + pgx-test-tls-conn-string: postgres://pgx_md5:secret@127.0.0.1/pgx_test?sslmode=require + 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 + - pg-version: 13 + pgx-test-conn-string: postgres://pgx_md5:secret@127.0.0.1/pgx_test + pgx-test-unix-socket-conn-string: "host=/var/run/postgresql dbname=pgx_test" + pgx-test-tcp-conn-string: postgres://pgx_md5:secret@127.0.0.1/pgx_test + pgx-test-tls-conn-string: postgres://pgx_md5:secret@127.0.0.1/pgx_test?sslmode=require + 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 + - pg-version: cockroachdb + pgx-test-conn-string: "postgresql://root@127.0.0.1:26257/pgx_test?sslmode=disable&experimental_enable_temp_tables=on" steps: - name: Set up Go 1.x uses: actions/setup-go@v2 with: - go-version: ${{ matrix.go_version }} + go-version: ${{ matrix.go-version }} - name: Check out code into the Go module directory uses: actions/checkout@v2 @@ -30,14 +69,14 @@ jobs: - name: Setup database server for testing run: ci/setup_test.bash env: - PGVERSION: ${{ matrix.pg_version }} + PGVERSION: ${{ matrix.pg-version }} - name: Test run: go test -v -race ./... env: - PGX_TEST_CONN_STRING: postgres://pgx_md5:secret@127.0.0.1/pgx_test - PGX_TEST_UNIX_SOCKET_CONN_STRING: "host=/var/run/postgresql dbname=pgx_test" - PGX_TEST_TCP_CONN_STRING: postgres://pgx_md5:secret@127.0.0.1/pgx_test - PGX_TEST_TLS_CONN_STRING: postgres://pgx_md5:secret@127.0.0.1/pgx_test?sslmode=require - 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_CONN_STRING: ${{ matrix.pgx-test-conn-string }} + PGX_TEST_UNIX_SOCKET_CONN_STRING: ${{ matrix.pgx-test-unix-socket-conn-string }} + PGX_TEST_TCP_CONN_STRING: ${{ matrix.pgx-test-tcp-conn-string }} + PGX_TEST_TLS_CONN_STRING: ${{ matrix.pgx-test-tls-conn-string }} + PGX_TEST_MD5_PASSWORD_CONN_STRING: ${{ matrix.pgx-test-md5-password-conn-string }} + PGX_TEST_PLAIN_PASSWORD_CONN_STRING: ${{ matrix.pgx-test-plain-password-conn-string }} diff --git a/auth_scram.go b/auth_scram.go index 665fc2c..6a143fc 100644 --- a/auth_scram.go +++ b/auth_scram.go @@ -18,13 +18,13 @@ import ( "crypto/rand" "crypto/sha256" "encoding/base64" + "errors" "fmt" "strconv" "github.com/jackc/pgproto3/v2" "golang.org/x/crypto/pbkdf2" "golang.org/x/text/secure/precis" - errors "golang.org/x/xerrors" ) const clientNonceLen = 18 @@ -192,12 +192,12 @@ func (sc *scramClient) recvServerFirstMessage(serverFirstMessage []byte) error { var err error sc.salt, err = base64.StdEncoding.DecodeString(string(saltStr)) if err != nil { - return errors.Errorf("invalid SCRAM salt received from server: %w", err) + return fmt.Errorf("invalid SCRAM salt received from server: %w", err) } sc.iterations, err = strconv.Atoi(string(iterationsStr)) if err != nil || sc.iterations <= 0 { - return errors.Errorf("invalid SCRAM iteration count received from server: %w", err) + return fmt.Errorf("invalid SCRAM iteration count received from server: %w", err) } if !bytes.HasPrefix(sc.clientAndServerNonce, sc.clientNonce) { diff --git a/ci/setup_test.bash b/ci/setup_test.bash index 144e93f..f71bd98 100755 --- a/ci/setup_test.bash +++ b/ci/setup_test.bash @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -eux -if [ "${PGVERSION-}" != "" ] +if [[ "${PGVERSION-}" =~ ^[0-9.]+$ ]] then sudo apt-get remove -y --purge postgresql libpq-dev libpq5 postgresql-client-common postgresql-common sudo rm -rf /var/lib/postgresql @@ -38,6 +38,14 @@ then psql -U postgres -c "create user \" tricky, ' } \"\" \\ test user \" superuser password 'secret'" fi +if [[ "${PGVERSION-}" =~ ^cockroach ]] +then + wget -qO- https://binaries.cockroachdb.com/cockroach-v20.2.5.linux-amd64.tgz | tar xvz + sudo mv cockroach-v20.2.5.linux-amd64/cockroach /usr/local/bin/ + cockroach start-single-node --insecure --background --listen-addr=localhost + cockroach sql --insecure -e 'create database pgx_test' +fi + if [ "${CRATEVERSION-}" != "" ] then docker run \ diff --git a/config.go b/config.go index 38e94f2..c162d3c 100644 --- a/config.go +++ b/config.go @@ -4,6 +4,7 @@ import ( "context" "crypto/tls" "crypto/x509" + "errors" "fmt" "io" "io/ioutil" @@ -20,7 +21,6 @@ import ( "github.com/jackc/pgpassfile" "github.com/jackc/pgproto3/v2" "github.com/jackc/pgservicefile" - errors "golang.org/x/xerrors" ) type AfterConnectFunc func(ctx context.Context, pgconn *PgConn) error @@ -409,7 +409,7 @@ func parseURLSettings(connString string) (map[string]string, error) { } h, p, err := net.SplitHostPort(host) if err != nil { - return nil, errors.Errorf("failed to split host:port in '%s', err: %w", host, err) + return nil, fmt.Errorf("failed to split host:port in '%s', err: %w", host, err) } hosts = append(hosts, h) ports = append(ports, p) @@ -617,7 +617,7 @@ func configTLS(settings map[string]string) ([]*tls.Config, error) { caPath := sslrootcert caCert, err := ioutil.ReadFile(caPath) if err != nil { - return nil, errors.Errorf("unable to read CA file: %w", err) + return nil, fmt.Errorf("unable to read CA file: %w", err) } if !caCertPool.AppendCertsFromPEM(caCert) { @@ -635,7 +635,7 @@ func configTLS(settings map[string]string) ([]*tls.Config, error) { if sslcert != "" && sslkey != "" { cert, err := tls.LoadX509KeyPair(sslcert, sslkey) if err != nil { - return nil, errors.Errorf("unable to read cert: %w", err) + return nil, fmt.Errorf("unable to read cert: %w", err) } tlsConfig.Certificates = []tls.Certificate{cert} diff --git a/errors.go b/errors.go index b37b1d9..77adfcf 100644 --- a/errors.go +++ b/errors.go @@ -2,13 +2,12 @@ package pgconn import ( "context" + "errors" "fmt" "net" "net/url" "regexp" "strings" - - errors "golang.org/x/xerrors" ) // SafeToRetry checks if the err is guaranteed to have occurred before sending any data to the server. diff --git a/go.mod b/go.mod index 7e57876..2dc0cd4 100644 --- a/go.mod +++ b/go.mod @@ -12,5 +12,4 @@ require ( github.com/stretchr/testify v1.5.1 golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 golang.org/x/text v0.3.3 - golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 ) diff --git a/pgconn.go b/pgconn.go index 0c1717f..20233e5 100644 --- a/pgconn.go +++ b/pgconn.go @@ -6,6 +6,8 @@ import ( "crypto/tls" "encoding/binary" "encoding/hex" + "errors" + "fmt" "io" "math" "net" @@ -16,7 +18,6 @@ import ( "github.com/jackc/pgconn/internal/ctxwatch" "github.com/jackc/pgio" "github.com/jackc/pgproto3/v2" - errors "golang.org/x/xerrors" ) const ( @@ -1043,7 +1044,7 @@ func (pgConn *PgConn) execExtendedPrefix(ctx context.Context, paramValues [][]by } if len(paramValues) > math.MaxUint16 { - result.concludeCommand(nil, errors.Errorf("extended protocol limited to %v parameters", math.MaxUint16)) + result.concludeCommand(nil, fmt.Errorf("extended protocol limited to %v parameters", math.MaxUint16)) result.closed = true pgConn.unlock() return result diff --git a/pgconn_test.go b/pgconn_test.go index 87edefc..7ceda79 100644 --- a/pgconn_test.go +++ b/pgconn_test.go @@ -5,6 +5,7 @@ import ( "compress/gzip" "context" "crypto/tls" + "errors" "fmt" "io" "io/ioutil" @@ -17,12 +18,9 @@ import ( "testing" "time" - "github.com/jackc/pgmock" - "github.com/jackc/pgconn" + "github.com/jackc/pgmock" "github.com/jackc/pgproto3/v2" - errors "golang.org/x/xerrors" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" )