Skip to content

Help with mocking returning pgx.Row from QueryRow method #51

Answered by pashagolub
stori-rusher asked this question in Q&A
Discussion options

You must be logged in to vote

Hello,

the key trick here is to use interface instead of the real pgx objects, e.g.

type AWSDB struct {
	reader DBConnector
	writer DBConnector
}

Then in the tests instead of creating a real pgxpool.Pool you should create a pgxmock object. Check here the example:
https://github.com/pashagolub/pgxmock/blob/master/examples/basic/

Instead of using the real pgxpool.Pool as an argument in the recordStats() function, we use the PgxIface interface. Which allows us to use pgxmock during tests and the real connection during work.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@stori-rusher
Comment options

@pashagolub
Comment options

Answer selected by pashagolub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested
2 participants
Converted from issue

This discussion was converted from issue #49 on December 29, 2021 11:30.