Define deftest-db to do async testing with an open DB.
This commit is contained in:
parent
479a7fd583
commit
bdac50e03c
1 changed files with 20 additions and 1 deletions
|
@ -4,7 +4,9 @@
|
|||
|
||||
(ns datomish.test-macros
|
||||
#?(:cljs
|
||||
(:require-macros [datomish.test-macros]))
|
||||
(:require-macros
|
||||
[datomish.test-macros]
|
||||
[datomish.node-tempfile-macros]))
|
||||
(:require
|
||||
[datomish.pair-chan]))
|
||||
|
||||
|
@ -38,3 +40,20 @@
|
|||
(let [[v# e#] (clojure.core.async/<!! (datomish.pair-chan/go-pair ~@body))]
|
||||
(when e# (throw e#)) ;; Assert nil just to be safe, even though we should always throw first.
|
||||
(clojure.test/is (= e# nil))))))
|
||||
|
||||
(defmacro deftest-db
|
||||
[n conn-var & body]
|
||||
`(deftest-async ~n
|
||||
(if-cljs
|
||||
(datomish.node-tempfile-macros/with-tempfile [t# (datomish.node-tempfile/tempfile)]
|
||||
(let [~conn-var (datomish.pair-chan/<? (datomish.api/<connect t#))]
|
||||
(try
|
||||
~@body
|
||||
(finally
|
||||
(datomish.pair-chan/<? (datomish.api/<close ~conn-var))))))
|
||||
(tempfile.core/with-tempfile [t# (tempfile.core/tempfile)]
|
||||
(let [~conn-var (datomish.pair-chan/<? (datomish.api/<connect t#))]
|
||||
(try
|
||||
~@body
|
||||
(finally
|
||||
(datomish.pair-chan/<? (datomish.api/<close ~conn-var)))))))))
|
||||
|
|
Loading…
Reference in a new issue