From 3b0400a0d401491f45add1f347ed0383ca6a76a1 Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Sat, 6 Mar 2021 14:42:22 -0600 Subject: [PATCH 1/8] Test Go 1.15 and 1.16 in CI --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 862235a..fa5c9e8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: strategy: matrix: - go_version: [1.14, 1.15] + go_version: [1.15, 1.16] pg_version: [9.6, 10, 11, 12, 13] steps: From cf5894e0927e66175468e7622712d2a4c6df0964 Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Sat, 6 Mar 2021 14:45:33 -0600 Subject: [PATCH 2/8] Use std errors instead of golang.org/x/xerrors New error functionality was introduced in Go 1.13. pgconn only officially supports 1.15+. Transitional xerrors package can now be removed. --- auth_scram.go | 6 +++--- config.go | 8 ++++---- errors.go | 3 +-- go.mod | 1 - pgconn.go | 5 +++-- pgconn_test.go | 6 ++---- 6 files changed, 13 insertions(+), 16 deletions(-) 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/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" ) From a0350a932a7e4313c547e36e6e2e8b7ccd8ce3d1 Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Sat, 6 Mar 2021 15:01:44 -0600 Subject: [PATCH 3/8] ci.yml consistently uses kebab case --- .github/workflows/ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fa5c9e8..77d32cb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,15 +14,15 @@ jobs: strategy: matrix: - go_version: [1.15, 1.16] - pg_version: [9.6, 10, 11, 12, 13] + go-version: [1.15, 1.16] + pg-version: [9.6, 10, 11, 12, 13] 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,7 +30,7 @@ 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 ./... From 7de3392269f1eb7d43900b8406392ea767fae479 Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Sat, 6 Mar 2021 15:15:03 -0600 Subject: [PATCH 4/8] Manually specify all build matrix options - Saves some CI time by only testing older version of Go once - Specify connection --- .github/workflows/ci.yml | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 77d32cb..67ffeaa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,8 +14,30 @@ jobs: strategy: matrix: - go-version: [1.15, 1.16] - pg-version: [9.6, 10, 11, 12, 13] + include: + - go-version: 1.15 + pg-version: 13 + pgx-test-conn-string: postgres://pgx_md5:secret@127.0.0.1/pgx_test + - go-version: 1.16 + pg-version: 9.6 + pgx-test-conn-string: postgres://pgx_md5:secret@127.0.0.1/pgx_test + - go-version: 1.16 + pg-version: 10 + pgx-test-conn-string: postgres://pgx_md5:secret@127.0.0.1/pgx_test + - go-version: 1.16 + pg-version: 11 + pgx-test-conn-string: postgres://pgx_md5:secret@127.0.0.1/pgx_test + - go-version: 1.16 + pg-version: 12 + pgx-test-conn-string: postgres://pgx_md5:secret@127.0.0.1/pgx_test + - go-version: 1.16 + 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 steps: @@ -35,9 +57,9 @@ jobs: - 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 }} From 1e905d8e38f6c9344707931ccd2afa03a2f34273 Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Sat, 6 Mar 2021 15:20:03 -0600 Subject: [PATCH 5/8] Refactor connection strings into build matrix This is in preparation for adding CockroachDB to the build matrix. --- .github/workflows/ci.yml | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 67ffeaa..6880ae9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,24 +14,38 @@ jobs: strategy: matrix: + go-version: [1.15, 1.16] + pg-version: [9.6, 10, 11, 12, 13] include: - - go-version: 1.15 - pg-version: 13 + - pg-version: 9.6 pgx-test-conn-string: postgres://pgx_md5:secret@127.0.0.1/pgx_test - - go-version: 1.16 - pg-version: 9.6 - pgx-test-conn-string: postgres://pgx_md5:secret@127.0.0.1/pgx_test - - go-version: 1.16 - pg-version: 10 + 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 - - go-version: 1.16 - pg-version: 11 + 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 - - go-version: 1.16 - pg-version: 12 + 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 - - go-version: 1.16 - pg-version: 13 + 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 From c57ee10556410a342ec9227286ab935c834bbc95 Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Sat, 6 Mar 2021 15:49:50 -0600 Subject: [PATCH 6/8] Add CockroachDB to CI --- .github/workflows/ci.yml | 4 +++- ci/setup_test.bash | 10 +++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6880ae9..3f45989 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,7 @@ jobs: strategy: matrix: go-version: [1.15, 1.16] - pg-version: [9.6, 10, 11, 12, 13] + 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 @@ -52,6 +52,8 @@ jobs: 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: diff --git a/ci/setup_test.bash b/ci/setup_test.bash index 144e93f..f934182 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 + cp 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_text' +fi + if [ "${CRATEVERSION-}" != "" ] then docker run \ From 7edb2b2e37a24d9dbb2c940c8ea46fb9e8bb5a4a Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Sat, 6 Mar 2021 15:54:37 -0600 Subject: [PATCH 7/8] Fix CI --- ci/setup_test.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/setup_test.bash b/ci/setup_test.bash index f934182..959d07e 100755 --- a/ci/setup_test.bash +++ b/ci/setup_test.bash @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -eux -if [[ "${PGVERSION-}" =~ ^[0-9]+$ ]] +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 @@ -41,7 +41,7 @@ fi if [[ "${PGVERSION-}" =~ ^cockroach ]] then wget -qO- https://binaries.cockroachdb.com/cockroach-v20.2.5.linux-amd64.tgz | tar xvz - cp cockroach-v20.2.5.linux-amd64/cockroach /usr/local/bin/ + 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_text' fi From 353d28882e5b86971ef7d9bed1cee4af8e4a6df2 Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Sat, 6 Mar 2021 16:02:26 -0600 Subject: [PATCH 8/8] More CI tweaks --- .github/workflows/ci.yml | 3 ++- ci/setup_test.bash | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3f45989..8961b4b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,9 +10,10 @@ jobs: test: name: Test - runs-on: ubuntu-latest + runs-on: ubuntu-18.04 strategy: + fail-fast: false matrix: go-version: [1.15, 1.16] pg-version: [9.6, 10, 11, 12, 13, cockroachdb] diff --git a/ci/setup_test.bash b/ci/setup_test.bash index 959d07e..f71bd98 100755 --- a/ci/setup_test.bash +++ b/ci/setup_test.bash @@ -43,7 +43,7 @@ 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_text' + cockroach sql --insecure -e 'create database pgx_test' fi if [ "${CRATEVERSION-}" != "" ]