Skip to content

Duct tests with integrant #60

Description

@zerg000000

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions