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 967a655dd9
commit 4d2079380c

View file

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