Skip to content

Commit

Permalink
Add tests for loading ledgers from files
Browse files Browse the repository at this point in the history
...and make the cljtest alias loadable in a REPL w/o auto-executing tests at load
  • Loading branch information
cap10morgan committed Jan 23, 2023
1 parent f948bb0 commit ff57724
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Makefile
Expand Up @@ -109,12 +109,12 @@ browser-test: out/fluree-browser-sdk.js
cljstest: cljs-browser-test cljs-node-test

cljtest:
clojure -M:cljtest
clojure -X:cljtest

test: cljtest cljstest nodejs-test browser-test

eastwood:
clojure -M:test:eastwood
clojure -M:cljtest:eastwood

ci: test eastwood

Expand Down
8 changes: 5 additions & 3 deletions deps.edn
Expand Up @@ -60,9 +60,11 @@

:cljtest
{:extra-paths ["test" "dev-resources"]
:extra-deps {lambdaisland/kaocha {:mvn/version "1.71.1119"}
org.clojure/test.check {:mvn/version "1.1.1"}}
:main-opts ["-m" "kaocha.runner"]}
:extra-deps {lambdaisland/kaocha {:mvn/version "1.71.1119"}
org.clojure/test.check {:mvn/version "1.1.1"}
com.magnars/test-with-files {:mvn/version "2021-02-17"}}
:exec-fn kaocha.runner/exec-fn
:exec-args {}}

:js-deps
{:extra-deps {com.timetraveltoaster/target-bundle-libs {:mvn/version "RELEASE"}}
Expand Down
79 changes: 78 additions & 1 deletion test/fluree/db/json_ld/api_test.cljc
Expand Up @@ -4,7 +4,8 @@
#?@(:cljs [[clojure.core.async :refer [go <!]]
[clojure.core.async.interop :refer [<p!]]])
[fluree.db.json-ld.api :as fluree]
[fluree.db.test-utils :as test-utils]))
[fluree.db.test-utils :as test-utils]
#?(:clj [test-with-files.tools :refer [with-tmp-dir]])))

(deftest exists?-test
(testing "returns true after committing data to a ledger"
Expand Down Expand Up @@ -34,3 +35,79 @@
(is (<p! (fluree/exists? conn ledger-alias)))
(is (not (<p! (fluree/exists? conn "notaledger"))))
(done)))))))

#?(:clj
(deftest load-from-file-test
(testing "can load a file ledger with single cardinality predicates"
(with-tmp-dir storage-path
(let [conn @(fluree/connect
{:method :file :storage-path storage-path
:defaults
{:context test-utils/default-context}})
ledger-alias "transact-basic-test-single-card"
ledger @(fluree/create conn ledger-alias)
db @(fluree/stage
(fluree/db ledger)
[{:context {:ex "http://example.org/ns/"}
:id :ex/brian,
:type :ex/User,
:schema/name "Brian"
:schema/email "brian@example.org"
:schema/age 50
:ex/favNums 7}

{:context {:ex "http://example.org/ns/"}
:id :ex/cam,
:type :ex/User,
:schema/name "Cam"
:schema/email "cam@example.org"
:schema/age 34
:ex/favNums 5
:ex/friend :ex/brian}])
_ @(fluree/commit! ledger db)
_ (Thread/sleep 1000)
loaded @(fluree/load conn ledger-alias)]
(if (instance? Throwable loaded)
(throw loaded)
(is (= (:t db) (:t (fluree/db loaded))))))))

(testing "can load a file ledger with multi-cardinality predicates"
(with-tmp-dir storage-path
(let [conn @(fluree/connect
{:method :file :storage-path storage-path
:defaults
{:context test-utils/default-context}})
ledger-alias "transact-basic-test-multi-card"
ledger @(fluree/create conn ledger-alias)
db @(fluree/stage
(fluree/db ledger)
[{:context {:ex "http://example.org/ns/"}
:id :ex/brian,
:type :ex/User,
:schema/name "Brian"
:schema/email "brian@example.org"
:schema/age 50
:ex/favNums 7}

{:context {:ex "http://example.org/ns/"}
:id :ex/alice,
:type :ex/User,
:schema/name "Alice"
:schema/email "alice@example.org"
:schema/age 50
:ex/favNums [42, 76, 9]}

{:context {:ex "http://example.org/ns/"}
:id :ex/cam,
:type :ex/User,
:schema/name "Cam"
:schema/email "cam@example.org"
:schema/age 34
:ex/favNums [5, 10]
:ex/friend [:ex/brian :ex/alice]}])
_ @(fluree/commit! ledger db)
_ (Thread/sleep 1000)
loaded @(fluree/load conn ledger-alias)]
(if (instance? Throwable loaded)
(throw loaded)
(is (= (:t db) (:t (fluree/db loaded))))))))))

0 comments on commit ff57724

Please sign in to comment.