mentat/test/datomish/sqlite_user_version_test.cljc

36 lines
1.6 KiB
Text
Raw Normal View History

;; This Source Code Form is subject to the terms of the Mozilla Public
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
(ns datomish.sqlite-user-version-test
#?(:cljs
(:require-macros
[datomish.pair-chan :refer [go-pair <?]]
[datomish.node-tempfile-macros :refer [with-tempfile]]
[cljs.core.async.macros :as a :refer [go]]))
(:require
[datomish.util :as util #?(:cljs :refer-macros :clj :refer) [raise raise-str cond-let]]
[datomish.sqlite :as s]
#?@(:clj [[datomish.pair-chan :refer [go-pair <?]]
[tempfile.core :refer [tempfile with-tempfile]]
[datomish.test-macros :refer [deftest-async]]
[clojure.test :as t :refer [is are deftest testing]]
[clojure.core.async :refer [go <! >!]]])
#?@(:cljs [[datomish.pair-chan]
[datomish.test-macros :refer-macros [deftest-async]]
[datomish.node-tempfile :refer [tempfile]]
[cljs.test :as t :refer-macros [is are deftest testing async]]
[cljs.core.async :as a :refer [<! >!]]])))
(deftest-async test-all-rows
(with-tempfile [t (tempfile)]
(let [db (<? (s/<sqlite-connection t))]
(try
(<? (s/execute! db ["CREATE TABLE test (a INTEGER)"]))
(<? (s/execute! db ["INSERT INTO test VALUES (?)" 1]))
(<? (s/execute! db ["INSERT INTO test VALUES (?)" 2]))
(let [rows (<? (s/all-rows db ["SELECT * FROM test ORDER BY a ASC"]))]
(is (= rows [{:a 1} {:a 2}])))
(finally
(<? (s/close db)))))))