Define deftest-db to do async testing with an open DB.
This commit is contained in:
parent
967a655dd9
commit
4d2079380c
1 changed files with 20 additions and 1 deletions
|
@ -4,7 +4,9 @@
|
||||||
|
|
||||||
(ns datomish.test-macros
|
(ns datomish.test-macros
|
||||||
#?(:cljs
|
#?(:cljs
|
||||||
(:require-macros [datomish.test-macros]))
|
(:require-macros
|
||||||
|
[datomish.test-macros]
|
||||||
|
[datomish.node-tempfile-macros]))
|
||||||
(:require
|
(:require
|
||||||
[datomish.pair-chan]))
|
[datomish.pair-chan]))
|
||||||
|
|
||||||
|
@ -38,3 +40,20 @@
|
||||||
(let [[v# e#] (clojure.core.async/<!! (datomish.pair-chan/go-pair ~@body))]
|
(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.
|
(when e# (throw e#)) ;; Assert nil just to be safe, even though we should always throw first.
|
||||||
(clojure.test/is (= e# nil))))))
|
(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