Fork me on GitHub
#sql
<
2022-07-08
>
seancorfield04:07:23

There's an "embedded" version of PostgreSQL that next.jdbc is tested against -- instead of a separate instance of PG running standalone, the tests start the embedded version and use that for all the DB tests. See https://github.com/seancorfield/next-jdbc/blob/develop/test/next/jdbc/test_fixtures.clj#L130-L133 for the setup as a datasource but you'll need to look at deps.edn and the top of that test-fixtures namespace for a few more bits of it.

HT05:07:29

do you recommend the embedded version vs a separate PG running standalone?

seancorfield05:07:29

With Docker, it's easy to spin up a new instance of PG on demand so that's a possibility too. At work we use Docker for local instances of Elastic Search, Percona, and Redis. I mentioned the embedded PG option because quite a few people suggest using some embedded DB for testing... I use it for the ease of testing but if you're already using Docker, that's probably "better".

👍 1
HT04:07:12

It seems pretty easy for me to spin up a PG instance, so that's not an issue I moreso can't find a simple copy and pastable code snippet for setting up and tearing down that second testing db

seancorfield17:07:33

I guess I'm not sure what you're asking then -- you just point your app at a different database for running tests.

seancorfield17:07:59

If you have specific data that is needed by tests in a particular namespace, you can use-fixtures (in clojure.test) to setup data, run the test, and tear it down.

HT18:07:37

yeah I'm mainly just looking for a simple example of use-fixtures that shows how to setup the db and tear it down on demand for the unit tests

seancorfield18:07:38

Take a look at the test code for next.jdbc

seancorfield21:07:48

There are so many moving parts there... but next.jdbc itself has tests that run things inside a rollback-only transaction and that works. I suspect something inside HugSQL is causing the behavior you are seeing -- but I don't use HugSQL (nor do I use Mount).

seancorfield21:07:26

This is partly why I recommend beginners don't use Luminus until they've learned more of the basics and can figure out how each piece works on its own.

seancorfield21:07:01

I had a quick look at HugSQL's code and I don't see anything that would mess with the connection but it's several levels of abstraction and it's not clear to me exactly what processing it is doing on the connection being passed in...

👍 1