Skip to content

Commit 35d0120

Browse files
authored
Merge pull request #2 from olomix/pgx_v5
Pgx v5
2 parents 9e4cc0c + 5adf660 commit 35d0120

File tree

7 files changed

+47
-189
lines changed

7 files changed

+47
-189
lines changed

.github/workflows/lint.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ jobs:
1010
lint:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v2
14-
- uses: actions/setup-go@v2
13+
- uses: actions/checkout@v3
14+
- uses: actions/setup-go@v3
1515
with:
16-
go-version: 1.17.7
17-
- uses: golangci/golangci-lint-action@v2
16+
go-version: 1.19.2
17+
- uses: golangci/golangci-lint-action@v3
1818
with:
19-
version: v1.44.2
19+
version: v1.50.0

.github/workflows/test.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ jobs:
1010
test:
1111
strategy:
1212
matrix:
13-
containers: [ 1.17.8-bullseye ]
13+
containers:
14+
- 1.18.7-bullseye
15+
- 1.19.2-bullseye
1416
runs-on: ubuntu-latest
1517
container: golang:${{ matrix.containers }}
1618
env:
@@ -19,8 +21,8 @@ jobs:
1921
PGUSER: postgres
2022
steps:
2123
- name: Checkout code
22-
uses: actions/checkout@v2
23-
- uses: actions/cache@v2
24+
uses: actions/checkout@v3
25+
- uses: actions/cache@v3
2426
with:
2527
path: |
2628
~/.cache/go-build

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
[![GoDoc](https://godoc.org/github.com/olomix/go-test-pg?status.svg)](https://godoc.org/github.com/olomix/go-test-pg)
44

5+
v2 version depends on pgx/v5. If you want support for pgx/v4, use 1.x.x
6+
version of this package.
7+
58
The aim this package is to help test golang programs against PostgreSQL
69
database. It creates an empty database for each test and drops it when test
710
is complete.
@@ -35,7 +38,7 @@ import (
3538
"context"
3639
"testing"
3740

38-
ptg "github.com/olomix/go-test-pg"
41+
ptg "github.com/olomix/go-test-pg/v2"
3942
)
4043

4144
var dbpool = &ptg.Pgpool{SchemaFile: "../schema.sql"}

database.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ import (
1414
"testing"
1515
"time"
1616

17-
"github.com/jackc/pgtype"
18-
"github.com/jackc/pgx/v4"
19-
"github.com/jackc/pgx/v4/pgxpool"
20-
"github.com/jackc/pgx/v4/stdlib"
17+
"github.com/jackc/pgx/v5"
18+
"github.com/jackc/pgx/v5/pgxpool"
19+
"github.com/jackc/pgx/v5/stdlib"
20+
"github.com/jackc/pgx/v5/tracelog"
2121
"github.com/pkg/errors"
2222
)
2323

@@ -148,7 +148,10 @@ func (p *Pgpool) registerStdConfig(t testing.TB,
148148
if err != nil {
149149
return "", errors.WithStack(err)
150150
}
151-
connConfig.Logger = newLogger(t)
151+
connConfig.Tracer = &tracelog.TraceLog{
152+
Logger: newLogger(t),
153+
LogLevel: tracelog.LogLevelTrace,
154+
}
152155
connConfig.Database = dbName
153156
return stdlib.RegisterConnConfig(connConfig), nil
154157
}
@@ -180,7 +183,7 @@ func (p *Pgpool) createRndDBPool(
180183
ctx, cancel := context.WithTimeout(context.Background(), defaultTimeout)
181184
defer cancel()
182185

183-
pool, err = pgxpool.ConnectConfig(ctx, cfg)
186+
pool, err = pgxpool.NewWithConfig(ctx, cfg)
184187
if err != nil {
185188
_ = dropDB(dbName)
186189
t.Fatal()
@@ -372,7 +375,7 @@ func (p *Pgpool) createTemplateDB() (string, error) {
372375
// If we need to create a database, take an advisory lock on
373376
// master database to prevent parallel creation of databases
374377
// from several test processes.
375-
var x pgtype.Unknown
378+
var x interface{}
376379
err = conn.
377380
QueryRow(ctx, `SELECT pg_advisory_lock($1)`, lockID).
378381
Scan(&x)

go.mod

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1-
module github.com/olomix/go-test-pg
1+
module github.com/olomix/go-test-pg/v2
22

3-
go 1.14
3+
go 1.18
44

55
require (
6-
github.com/jackc/pgtype v1.10.0
7-
github.com/jackc/pgx/v4 v4.15.0
6+
github.com/jackc/pgx/v5 v5.0.2
87
github.com/pkg/errors v0.8.1
98
)
9+
10+
require (
11+
github.com/jackc/pgpassfile v1.0.0 // indirect
12+
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
13+
github.com/jackc/puddle/v2 v2.0.0 // indirect
14+
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90 // indirect
15+
golang.org/x/text v0.3.7 // indirect
16+
)

0 commit comments

Comments
 (0)