forked from pashagolub/pgxmock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
driver.go
50 lines (41 loc) · 1.24 KB
/
driver.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
package pgxmock
import (
"context"
"errors"
"github.com/jackc/pgx/v5/pgxpool"
)
type pgxmockConn struct {
pgxmock
}
// NewConn creates PgxConnIface database connection and a mock to manage expectations.
// Accepts options, like ValueConverterOption, to use a ValueConverter from
// a specific driver.
// Pings db so that all expectations could be
// asserted.
func NewConn(options ...func(*pgxmock) error) (PgxConnIface, error) {
smock := &pgxmockConn{}
smock.ordered = true
return smock, smock.open(options)
}
func (c *pgxmockConn) Close(ctx context.Context) error {
return c.close(ctx)
}
type pgxmockPool struct {
pgxmock
}
// NewPool creates PgxPoolIface pool of database connections and a mock to manage expectations.
// Accepts options, like ValueConverterOption, to use a ValueConverter from
// a specific driver.
// Pings db so that all expectations could be
// asserted.
func NewPool(options ...func(*pgxmock) error) (PgxPoolIface, error) {
smock := &pgxmockPool{}
smock.ordered = true
return smock, smock.open(options)
}
func (p *pgxmockPool) Close() {
_ = p.close(context.Background())
}
func (p *pgxmockPool) Acquire(ctx context.Context) (*pgxpool.Conn, error) {
return nil, errors.New("pgpool.Acquire() method is not implemented")
}