-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpostgresql_test.go
72 lines (54 loc) · 1.47 KB
/
postgresql_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package testdock
import (
"context"
"testing"
"github.com/georgysavva/scany/v2/pgxscan"
"github.com/jackc/pgx/v5/pgxpool"
)
const testPostgresImage = "17.2"
func Test_PgxGooseDB(t *testing.T) {
t.Parallel()
db, informer := GetPgxPool(t,
DefaultPostgresDSN,
WithMigrations("migrations/pg/goose", GooseMigrateFactoryPGX),
WithDockerImage(testPostgresImage),
)
checkInformer(t, DefaultPostgresDSN, informer)
testPgxHelper(t, db)
}
func Test_PgxGomigrateDB(t *testing.T) {
t.Parallel()
db, informer := GetPgxPool(t,
DefaultPostgresDSN,
WithMigrations("migrations/pg/gomigrate", GolangMigrateFactory),
WithDockerImage(testPostgresImage),
WithMode(RunModeDocker), // force run in docker
)
checkInformer(t, DefaultPostgresDSN, informer)
testPgxHelper(t, db)
}
func Test_LibPGDB(t *testing.T) {
t.Parallel()
ctx := context.Background()
db, _ := GetPqConn(ctx, t,
DefaultPostgresDSN,
WithMigrations("migrations/pg/goose", GooseMigrateFactoryPQ),
WithDockerImage(testPostgresImage),
)
testSQLHelper(t, db)
}
func testPgxHelper(t *testing.T, db *pgxpool.Pool) {
t.Helper()
var rows []struct {
Name string `db:"name"`
}
if err := pgxscan.Select(context.Background(), db, &rows, "SELECT name FROM test_table"); err != nil {
t.Fatalf("error querying test_table: %s", err)
}
if len(rows) == 0 {
t.Fatal("no rows returned from test_table")
}
if rows[0].Name != "test" { //nolint:goconst // ok
t.Fatalf("expected 'test', got '%s'", rows[0].Name)
}
}