Skip to content

Commit

Permalink
add pgconn method
Browse files Browse the repository at this point in the history
  • Loading branch information
jsnb-devoted committed Aug 5, 2022
1 parent 5372698 commit a3ace84
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pgxmock.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ type pgxMockIface interface {
NewColumn(name string) *pgproto3.FieldDescription

ConnInfo() *pgtype.ConnInfo

PgConn() *pgconn.PgConn
}

type pgxIface interface {
Expand All @@ -124,6 +126,7 @@ type pgxIface interface {
Prepare(context.Context, string, string) (*pgconn.StatementDescription, error)
Deallocate(ctx context.Context, name string) error
ConnInfo() *pgtype.ConnInfo
PgConn() *pgconn.PgConn
}

type PgxConnIface interface {
Expand Down Expand Up @@ -263,6 +266,11 @@ func (c *pgxmock) ConnInfo() *pgtype.ConnInfo {
return &ci
}

func (c *pgxmock) PgConn() *pgconn.PgConn {
p := pgconn.PgConn{}
return &p
}

// NewRowsWithColumnDefinition allows Rows to be created from a
// sql driver.Value slice with a definition of sql metadata
func (c *pgxmock) NewRowsWithColumnDefinition(columns ...pgproto3.FieldDescription) *Rows {
Expand Down
10 changes: 10 additions & 0 deletions pgxmock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1240,3 +1240,13 @@ func TestConnInfo(t *testing.T) {

_ = mock.ConnInfo()
}

func TestPgConn(t *testing.T) {
mock, err := NewConn()
if err != nil {
t.Errorf("an error '%s' was not expected when opening a stub database connection", err)
}
defer mock.Close(context.Background())

_ = mock.PgConn()
}

0 comments on commit a3ace84

Please sign in to comment.