-
Notifications
You must be signed in to change notification settings - Fork 52
Open
Description
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
(defn config-fixture [keys deps]
(fn [f]
(let [config (-> (duct/read-config (io/resource "test.edn"))
duct/prep
(dissoc :duct.core/handler))] ; remove handler because it will start the jetty
(let [sys (ig/init config keys)]
(ig/run! sys keys (fn [_ db]
(reset! deps db)
(f)
(reset! deps nil)
(ig/halt! sys keys)))))))
(def system (atom nil)) ; this is the trick to use ig dependents
(use-fixtures :once (fixtures/config-fixture
[:duct.database/sql]
system))
(deftest db-itest
(testing "create dumb in db"
(let [dumbs (-> (s/gen :dumb/dumb)
(gen/sample 100))
db-spec @system
apply-dissoc #(apply dissoc %1 %2)]
(is db-spec "db-spec should exists")
(doseq [dumb dumbs]
(let [expected dumb
actual (db/create db-spec dumb)]
(is (= expected actual) "inserted dumb should be same as input"))))))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.
Metadata
Metadata
Assignees
Labels
No labels