Skip to content

Commit

Permalink
[+] add pgxmockPool.AsCon() method to emulate Acquire() in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pashagolub committed Jul 5, 2023
1 parent a96d463 commit 5020f24
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ func (p *pgxmockPool) Acquire(context.Context) (*pgxpool.Conn, error) {
return nil, errors.New("pgpool.Acquire() method is not implemented")
}

// AsConn is similar to Acquire but returns proper mocking interface
func (p *pgxmockPool) AsConn() PgxConnIface {
return &pgxmockConn{pgxmock: p.pgxmock}
}

func (p *pgxmockPool) Stat() *pgxpool.Stat {
return &pgxpool.Stat{}
}
}
1 change: 1 addition & 0 deletions pgxmock.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ type PgxPoolIface interface {
AcquireFunc(ctx context.Context, f func(*pgxpool.Conn) error) error
Close()
Stat() *pgxpool.Stat
AsConn() PgxConnIface
}

type pgxmock struct {
Expand Down

0 comments on commit 5020f24

Please sign in to comment.