Closed sporto closed 2 months ago
This is a simple database connection library. If you wish for functionality unrelated to connecting to and querying a database you likely want to abstract over it in some fashion.
One thing you could do if have a zero arity function there that returns a connection, and have it panic if called in those tests that do not need a database.
Yes, that was my idea, something that just panics if actually called. Sorry, didn't mean a fully mocked connection, that will return things while called in test. That was bad naming.
Something like this I guess
@external(erlang, "rand", "uniform")
pub fn mock_connection() -> pgo.Connection
My question, was more if the library should provide a function like this. It wasn't obvious to me how to get a Connection
, without actually calling connect
.
It should not, no. This library is an API client and unrelated to mocking or testing.
I would like to put the connection in my application context e.g.
For unit testing, I want to create a fixture for the context. So I can test route handlers that expect a context. e.g.
How could I do this? I wouldn't like to create a real DB connection for many unit tests. Just something that satisfies the
Connection
type.Could this lib provide a mock connection?