-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpgx_pool_test.go
58 lines (47 loc) · 1.03 KB
/
pgx_pool_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
// Copyright 2022 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package serialkey_test
import (
"context"
"errors"
"fmt"
"os"
"testing"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/pfmt/serialkey"
)
var (
pgxPool *pgxpool.Pool
pgxErr error
pgxOpt = serialkey.PgxPoolWithStart(1)
)
func TestPgx(t *testing.T) {
if pgxErr != nil {
t.Log(pgxErr)
return
}
chain := serialkey.NewPgxPool(pgxPool, pgxOpt)
serailKeyTest(t, chain)
closer.add(chain.Close)
}
func BenchmarkPgxNext(b *testing.B) {
if pgxErr != nil {
b.Log(pgxErr)
return
}
chain := serialkey.NewPgxPool(pgxPool, pgxOpt)
nextSerailKeyBenchmark(b, chain)
closer.add(chain.Close)
}
func NewPgxPool(ctx context.Context) (*pgxpool.Pool, error) {
url, ok := os.LookupEnv("PGXURL")
if !ok {
return nil, errors.New("missing pgx URL")
}
pool, err := pgxpool.New(ctx, url)
if err != nil {
return nil, fmt.Errorf("pgx connect %s: %w", url, err)
}
return pool, nil
}