Skip to content

Commit

Permalink
Merge pull request #86 from jsnb-devoted/master
Browse files Browse the repository at this point in the history
Add `ConnInfo` method to pgx interface
  • Loading branch information
pashagolub authored Aug 1, 2022
2 parents e70b0cd + 483d3cc commit 19ea54c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pgxmock.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/jackc/pgconn"
"github.com/jackc/pgproto3/v2"
"github.com/jackc/pgtype"
"github.com/jackc/pgx/v4"
"github.com/jackc/pgx/v4/pgxpool"
)
Expand Down Expand Up @@ -106,6 +107,8 @@ type pgxMockIface interface {

// New Column allows to create a Column
NewColumn(name string) *pgproto3.FieldDescription

ConnInfo() *pgtype.ConnInfo
}

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

type PgxConnIface interface {
Expand Down Expand Up @@ -253,6 +257,12 @@ func (c *pgxmock) NewRows(columns []string) *Rows {
return r
}

// ConnInfo returns the connection info used for this connection
func (c *pgxmock) ConnInfo() *pgtype.ConnInfo {
ci := pgtype.ConnInfo{}
return &ci
}

// 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 @@ -1198,3 +1198,13 @@ func TestCon(t *testing.T) {
}()
_ = mock.Conn()
}

func TestConnInfo(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.ConnInfo()
}

0 comments on commit 19ea54c

Please sign in to comment.