Fork me on GitHub

Do any of you Ductors have tips on how to set up integration tests on a Duct/Ataraxy API? Ideally, within a test, I'd be able to send a mock request like {:uri "/something", :action :get} to some local handler and also be able to rollback the DB transaction after each test. I have a really complicated version of the former working, but it doesn't respect the j/set-rollback-only! that I pass it, and I figured there must be someone else on here who knows how to pull it off.


(This would include passing through middleware, because my Ataraxy routes expect, for example, body-params or session)


Alright, I've thrown in the towel on this one. Just gonna test routes separately from handlers and call it a day - that gives me the same amount of confidence.


Hi @U4GBG4PUY. Do you have rollbacks working in other system tests. Is this ataraxy specific? We have some functions that we use in test fixtures that setup a system with rollbacks enabled. We basically take the “source” db connection and then wrap it with set-rollback-only! Then we assoc that connection into each database component (boundary) that needs rollbacks enabled for that test. This is the only way that I’ve found that keeps the rollbacks working.


So we set up a new test system and enable rollbacks with a clojure.test fixture as needed in each test namespace.


The assoc ing of the txn wrapped source connection into other components has the been the key for me to make it all work. This may be too abstract to discuss without code (which would be difficult to me to share quickly). Let me know if you decide to give it another shot and want to discuss further.


That makes sense, and I haven't tried that yet. Might I guess that you're doing that on the connection pool you get after initing duct.database.sql/hikaricp (assuming you're using it), or am I way off?


Yep, you got it. We use the connection from hikari and assoc it into the other components.

💪 4

Very useful information! I'll fiddle with this once I'm at my text editor again, many thanks Ticean!

👍 4