Define deftest-db to do async testing with an open DB.

This commit is contained in:
Richard Newman 2016-08-19 09:13:57 -07:00
parent 479a7fd583
commit bdac50e03c

View file

@ -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)))))))))