Open zerg000000 opened 7 years ago
Ideally in Duct you'll have three types of tests:
init
the entire system and test it from end to endSo my initial advice is to test the boundary functions directly:
(deftest db-test
(jdbc/with-db-transaction [tx db-spec]
(jdbc/db-set-rollback-only! tx)
(seed-database tx)
(let [db (->Boundary tx)]
...)))
If you want to test boundary functions in conjunction with your handler, perhaps because you're uncertain of the interactions between the handler and the database, then you could use init-key
directly:
(deftest db-test
(jdbc/with-db-transaction [tx db-spec]
(jdbc/db-set-rollback-only! tx)
(seed-database tx)
(let [db (->Boundary tx)
handler (init-key :foo.handler/bar {:db db})]
...)))
Obviously you can wrap a lot of the above in a macro or function to automate the process of setting up the transaction and seeding the database.
I would consider my tests falling into second case, that's why we will have code that's only pick the keys needed. As the example you provided, seed-database
would be some calls to ragtime, since the ragtime configuration is a bit duct-ized in config.edn
, if we don't touch the integrant for migrator.ragtime
we needs to add some code that's similar to migrator.ragtime to seed the database.
That makes sense. In which case, rather than using init-key
, you can use a selective init
.
(deftest db-test
(jdbc/with-db-transaction [tx db-spec]
(jdbc/db-set-rollback-only! tx)
(let [config (assoc test-config :duct.database/sql {:connection tx})
system (-> config duct/prep (ig/init [:foo.handler/bar]))
handler (:foo.handler/bar system)]
...)))
The Duct unit test example only cover init a handler with no dependences which is impossible in real world. Currently, if I want to do integration test with db. I need to do something like
is there any better method to test with
integrant
?The primary use case is for testing all the boundaries in duct, to see if they are healthy.