Is there a method that doesn't alter the original connection pool ? #154
-
Is your feature request related to a problem? Please describe.
For example, i have this struct:
and some function like this:
Do I must modify my structure in this way?
Ideally, I would prefer not to modify this Manager struct.
but had error : Impossible type assertion: '*pgxpool.Pool' does not implement 'PgxPoolIface' |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hello, and thanks for your interest.
Well, you don't need to use Check my own implementation of this technique in pg_timetable.
We can mock only interfaces. Because interface is an agreement, not an implementation. For example, it's straightforward with On the contrary, pgx provides us with the structs I hope I'm clean enough. If not, you may try to read this article. Check the "Interface substitution" part.
I can completely understand your question and frustration. I've been there. :) As I wrote, it's easier to mock |
Beta Was this translation helpful? Give feedback.
Hello, and thanks for your interest.
Well, you don't need to use
pgxmock.PgxIface
. It's possible, but I would recommend something other than that for one reason: you don't want to use anything from the testing environment in your production build. To overcome this problem, you may define and use your own interface. As a start, you may copy-pastePgxPoolIface
andPgxIface
into your code. You can even rename it. The main thing is that this interface will define the methods of the pool.Check my own implementation of this technique in pg_timetable.
We can mock only interfaces. Because …