-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpgxconn_test.go
57 lines (46 loc) · 1.14 KB
/
pgxconn_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
package main
import (
"context"
"testing"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgconn"
"github.com/jackc/pgx/v5/pgtype"
"github.com/pashagolub/pgxmock/v3"
)
// embed pgxmock.PgxConnIface
type PgxConnMock struct {
pgxmock.PgxConnIface
}
// add impl by your need
func (c *PgxConnMock) Config() *pgx.ConnConfig {
return nil
}
func (c *PgxConnMock) IsClosed() bool {
return false
}
func (c *PgxConnMock) DeallocateAll(ctx context.Context) error {
return nil
}
func (c *PgxConnMock) LoadType(ctx context.Context, typeName string) (*pgtype.Type, error) {
return nil, nil
}
func (c *PgxConnMock) TypeMap() *pgtype.Map {
return nil
}
func (c *PgxConnMock) WaitForNotification(ctx context.Context) (*pgconn.Notification, error) {
return nil, nil
}
func TestPgxConnHandler(t *testing.T) {
mock, err := pgxmock.NewConn(pgxmock.QueryMatcherOption(pgxmock.QueryMatcherRegexp))
if err != nil {
t.Error(err)
}
PgxConn = func() PgxConnIface {
return &PgxConnMock{mock}
}
row := pgxmock.NewRows([]string{"result"}).AddRow(1)
mock.ExpectQuery("select").WillReturnRows(row)
if err = PgxConnHandler(); err != nil {
t.Error(err)
}
}