From 9e5a7bbec55ed4021250252c24fbfb1e517d5ae2 Mon Sep 17 00:00:00 2001 From: Benjamin Lamothe Date: Tue, 1 Nov 2022 16:18:11 -0400 Subject: [PATCH 1/4] remove index watch This watch was just a placeholder for future watching functionality, but it's not currently used. The watching functionality itself also encourages propogating mutable state and complects the indexing and ledger update operation. I think we should instead use explicit function calls with persistent values instead of mutable state to implement this functionality when we eventually need it. --- src/fluree/db/ledger/json_ld.cljc | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/src/fluree/db/ledger/json_ld.cljc b/src/fluree/db/ledger/json_ld.cljc index eb10b9d27..293b5b2e2 100644 --- a/src/fluree/db/ledger/json_ld.cljc +++ b/src/fluree/db/ledger/json_ld.cljc @@ -147,31 +147,6 @@ (recur r db**)) db*)))) -;; TODO - below is just an event handler for indexing service, ultimately pass message to any listeners for the ledger -(defn update-index - "When indexing is complete, updates index market for DB/ledger" - [ledger {:keys [t port] :as event-meta}] - (async/go - (let [indexed-db (async/ Date: Wed, 2 Nov 2022 22:11:56 -0400 Subject: [PATCH 2/4] refactor tests to run in isolation and not use fixtures --- deps.edn | 4 +- dev-resources/default_context.edn | 10 + dev-resources/movies.edn | 13 ++ test/fluree/db/query/json_ld_basic_test.clj | 211 +++++++++--------- .../fluree/db/query/json_ld_compound_test.clj | 9 +- test/fluree/db/query/subclass_test.clj | 8 +- test/fluree/db/shacl/shacl_basic_test.clj | 15 +- test/fluree/db/test_fixtures.clj | 85 ------- test/fluree/db/test_utils.clj | 33 +++ test/fluree/db/transact/retraction_test.clj | 6 +- 10 files changed, 171 insertions(+), 223 deletions(-) create mode 100644 dev-resources/default_context.edn create mode 100644 dev-resources/movies.edn delete mode 100644 test/fluree/db/test_fixtures.clj create mode 100644 test/fluree/db/test_utils.clj diff --git a/deps.edn b/deps.edn index 8f967c430..f24514ce2 100644 --- a/deps.edn +++ b/deps.edn @@ -49,13 +49,13 @@ :ns-default build} :dev - {:extra-paths ["dev" "test" "src-cljs" "src-nodejs" "src-docs"] + {:extra-paths ["dev" "test" "dev-resources" "src-cljs" "src-nodejs" "src-docs"] :extra-deps {org.clojure/tools.namespace {:mvn/version "1.3.0"} figwheel-sidecar/figwheel-sidecar {:mvn/version "0.5.20"} thheller/shadow-cljs {:mvn/version "2.20.7"}}} :cljtest - {:extra-paths ["test"] + {: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"]} diff --git a/dev-resources/default_context.edn b/dev-resources/default_context.edn new file mode 100644 index 000000000..7b0d4b679 --- /dev/null +++ b/dev-resources/default_context.edn @@ -0,0 +1,10 @@ +{:id "@id" + :type "@type" + :xsd "http://www.w3.org/2001/XMLSchema#" + :rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" + :rdfs "http://www.w3.org/2000/01/rdf-schema#" + :sh "http://www.w3.org/ns/shacl#" + :schema "http://schema.org/" + :skos "http://www.w3.org/2008/05/skos#" + :wiki "https://www.wikidata.org/wiki/" + :f "https://ns.flur.ee/ledger#"} diff --git a/dev-resources/movies.edn b/dev-resources/movies.edn new file mode 100644 index 000000000..7a91fcd8c --- /dev/null +++ b/dev-resources/movies.edn @@ -0,0 +1,13 @@ +{"@context" "https://schema.org", + "id" "https://www.wikidata.org/wiki/Q836821", + "type" ["Movie"], + "name" "The Hitchhiker's Guide to the Galaxy", + "disambiguatingDescription" "2005 British-American comic science fiction film directed by Garth Jennings", + "titleEIDR" "10.5240/B752-5B47-DBBE-E5D4-5A3F-N", + "isBasedOn" {"id" "https://www.wikidata.org/wiki/Q3107329", + "type" "Book", + "name" "The Hitchhiker's Guide to the Galaxy", + "isbn" "0-330-25864-8", + "author" {"@id" "https://www.wikidata.org/wiki/Q42" + "@type" "Person" + "name" "Douglas Adams"}}} diff --git a/test/fluree/db/query/json_ld_basic_test.clj b/test/fluree/db/query/json_ld_basic_test.clj index b5c8b8862..21d532199 100644 --- a/test/fluree/db/query/json_ld_basic_test.clj +++ b/test/fluree/db/query/json_ld_basic_test.clj @@ -1,61 +1,37 @@ (ns fluree.db.query.json-ld-basic-test (:require [clojure.test :refer :all] - [fluree.db.test-fixtures :as test] + [fluree.db.test-utils :as test-utils] [fluree.db.json-ld.api :as fluree] [fluree.db.util.log :as log])) -(use-fixtures :once test/test-system) - (deftest json-ld-basic-query (testing "json-ld" - (testing "basic wildcard single subject query" - (let [movies (test/get-ledger :test/movies) - db (fluree/db movies) - query-res @(fluree/query db {:select [:*] - :from :wiki/Q836821})] - (is (= (count query-res) 1) - "There should only be one subject in the result set") - (is (= query-res [{:id :wiki/Q836821, - :rdf/type [:schema/Movie], - :schema/name "The Hitchhiker's Guide to the Galaxy", - :schema/disambiguatingDescription "2005 British-American comic science fiction film directed by Garth Jennings", - :schema/titleEIDR "10.5240/B752-5B47-DBBE-E5D4-5A3F-N", - :schema/isBasedOn {:id :wiki/Q3107329}}]) - "Basic select * is working will context normalization"))) - (testing "basic single subject query with explicit field selection" - (let [movies (test/get-ledger :test/movies) - db (fluree/db movies) - query-res @(fluree/query db {:select [:id :schema/name] - :from :wiki/Q836821})] - (is (= query-res [{:id :wiki/Q836821, :schema/name "The Hitchhiker's Guide to the Galaxy"}])))) - (testing "basic single subject query with selectOne" - (let [movies (test/get-ledger :test/movies) - db (fluree/db movies) - query-res @(fluree/query db {:selectOne [:id :schema/name] - :from :wiki/Q836821})] - (is (= query-res {:id :wiki/Q836821, :schema/name "The Hitchhiker's Guide to the Galaxy"})))) - (testing "basic single subject query with graph crawl" - (let [movies (test/get-ledger :test/movies) - db (fluree/db movies) - query-res @(fluree/query db {:selectOne [:* {:schema/isBasedOn [:*]}] - :from :wiki/Q836821})] - (is (= query-res {:id :wiki/Q836821, - :rdf/type [:schema/Movie], - :schema/name "The Hitchhiker's Guide to the Galaxy", - :schema/disambiguatingDescription "2005 British-American comic science fiction film directed by Garth Jennings", - :schema/titleEIDR "10.5240/B752-5B47-DBBE-E5D4-5A3F-N", - :schema/isBasedOn {:id :wiki/Q3107329, - :rdf/type [:schema/Book], - :schema/name "The Hitchhiker's Guide to the Galaxy", - :schema/isbn "0-330-25864-8", - :schema/author {:id :wiki/Q42}}})))) - (testing "basic single subject query using depth graph crawl" - (testing "using only wildcard" - (let [movies (test/get-ledger :test/movies) - db (fluree/db movies) - query-res @(fluree/query db {:selectOne [:*] - :from :wiki/Q836821 - :depth 3})] + (let [conn (test-utils/create-conn) + movies (test-utils/load-movies conn) + db (fluree/db movies)] + (testing "basic wildcard single subject query" + (let [query-res @(fluree/query db {:select [:*] + :from :wiki/Q836821})] + (is (= (count query-res) 1) + "There should only be one subject in the result set") + (is (= query-res [{:id :wiki/Q836821, + :rdf/type [:schema/Movie], + :schema/name "The Hitchhiker's Guide to the Galaxy", + :schema/disambiguatingDescription "2005 British-American comic science fiction film directed by Garth Jennings", + :schema/titleEIDR "10.5240/B752-5B47-DBBE-E5D4-5A3F-N", + :schema/isBasedOn {:id :wiki/Q3107329}}]) + "Basic select * is working will context normalization"))) + (testing "basic single subject query with explicit field selection" + (let [query-res @(fluree/query db {:select [:id :schema/name] + :from :wiki/Q836821})] + (is (= query-res [{:id :wiki/Q836821, :schema/name "The Hitchhiker's Guide to the Galaxy"}])))) + (testing "basic single subject query with selectOne" + (let [query-res @(fluree/query db {:selectOne [:id :schema/name] + :from :wiki/Q836821})] + (is (= query-res {:id :wiki/Q836821, :schema/name "The Hitchhiker's Guide to the Galaxy"})))) + (testing "basic single subject query with graph crawl" + (let [query-res @(fluree/query db {:selectOne [:* {:schema/isBasedOn [:*]}] + :from :wiki/Q836821})] (is (= query-res {:id :wiki/Q836821, :rdf/type [:schema/Movie], :schema/name "The Hitchhiker's Guide to the Galaxy", @@ -65,70 +41,83 @@ :rdf/type [:schema/Book], :schema/name "The Hitchhiker's Guide to the Galaxy", :schema/isbn "0-330-25864-8", - :schema/author {:id :wiki/Q42, - :rdf/type [:schema/Person], - :schema/name "Douglas Adams"}}})))) - (testing "using graph sub-selection" - (let [movies (test/get-ledger :test/movies) - db (fluree/db movies) - query-res @(fluree/query db {:selectOne [:* {:schema/isBasedOn [:*]}] - :from :wiki/Q836821 - :depth 3})] - (is (= query-res {:id :wiki/Q836821, - :rdf/type [:schema/Movie], - :schema/name "The Hitchhiker's Guide to the Galaxy", - :schema/disambiguatingDescription "2005 British-American comic science fiction film directed by Garth Jennings", - :schema/titleEIDR "10.5240/B752-5B47-DBBE-E5D4-5A3F-N", - :schema/isBasedOn {:id :wiki/Q3107329, - :rdf/type [:schema/Book], - :schema/name "The Hitchhiker's Guide to the Galaxy", - :schema/isbn "0-330-25864-8", - :schema/author {:id :wiki/Q42, - :rdf/type [:schema/Person], - :schema/name "Douglas Adams"}}}))))))) - + :schema/author {:id :wiki/Q42}}})))) + (testing "basic single subject query using depth graph crawl" + (testing "using only wildcard" + (let [query-res @(fluree/query db {:selectOne [:*] + :from :wiki/Q836821 + :depth 3})] + (is (= query-res {:id :wiki/Q836821, + :rdf/type [:schema/Movie], + :schema/name "The Hitchhiker's Guide to the Galaxy", + :schema/disambiguatingDescription "2005 British-American comic science fiction film directed by Garth Jennings", + :schema/titleEIDR "10.5240/B752-5B47-DBBE-E5D4-5A3F-N", + :schema/isBasedOn {:id :wiki/Q3107329, + :rdf/type [:schema/Book], + :schema/name "The Hitchhiker's Guide to the Galaxy", + :schema/isbn "0-330-25864-8", + :schema/author {:id :wiki/Q42, + :rdf/type [:schema/Person], + :schema/name "Douglas Adams"}}})))) + (testing "using graph sub-selection" + (let [query-res @(fluree/query db {:selectOne [:* {:schema/isBasedOn [:*]}] + :from :wiki/Q836821 + :depth 3})] + (is (= query-res {:id :wiki/Q836821, + :rdf/type [:schema/Movie], + :schema/name "The Hitchhiker's Guide to the Galaxy", + :schema/disambiguatingDescription "2005 British-American comic science fiction film directed by Garth Jennings", + :schema/titleEIDR "10.5240/B752-5B47-DBBE-E5D4-5A3F-N", + :schema/isBasedOn {:id :wiki/Q3107329, + :rdf/type [:schema/Book], + :schema/name "The Hitchhiker's Guide to the Galaxy", + :schema/isbn "0-330-25864-8", + :schema/author {:id :wiki/Q42, + :rdf/type [:schema/Person], + :schema/name "Douglas Adams"}}})))))))) (deftest json-ld-rdf-type-query (testing "json-ld rdf type queries" - (testing "basic analytical RDF type query" - (let [movies (test/get-ledger :test/movies) - db (fluree/db movies) - query-res @(fluree/query db {:selectOne {'?s [:* {:f/role [:*]}]} - :where [['?s :rdf/type :f/DID]]})] - (is (= (dissoc query-res :id) ;; :id is a DID and will be unique per DB so exclude from comparison - {:rdf/type [:f/DID], - :f/role {:id "fluree-root-role", - :rdf/type [:f/Role], - :skos/definition "Default role that gives full root access to a ledger.", - :skos/prefLabel "Root role", - :f/rules {:id "fluree-root-rule"}}}) - "Standard bootstrap data isn't matching."))))) + (let [conn (test-utils/create-conn) + movies (test-utils/load-movies conn) + db (fluree/db movies)] + (testing "basic analytical RFD type query" + (let [query-res @(fluree/query db {:selectOne {'?s [:* {:f/role [:*]}]} + :where [['?s :rdf/type :f/DID]]})] + (is (= (dissoc query-res :id) ;; :id is a DID and will be unique per DB so exclude from comparison + {:rdf/type [:f/DID], + :f/role {:id "fluree-root-role", + :rdf/type [:f/Role], + :skos/definition "Default role that gives full root access to a ledger.", + :skos/prefLabel "Root role", + :f/rules {:id "fluree-root-rule"}}}) + "Standard bootstrap data isn't matching.")))))) (deftest json-ld-list-order-preservation (testing "json-ld @container @list option" - (testing "define @list container in context" - (let [movies (test/get-ledger :test/movies) - db @(fluree/stage movies {:context {:ex "http://example.org/ns#" - :ex/list {"@container" "@list"}} - :id "list-test" - :ex/list [42 2 88 1]}) - query-res @(fluree/query db {:context {:ex "http://example.org/ns#"} - :selectOne [:*] - :from "list-test"})] - (is (= query-res - {:id "list-test" - :ex/list [42 2 88 1]}) - "Order of query result is different from transaction."))) - (testing "define @list directly on subject" - (let [movies (test/get-ledger :test/movies) - db @(fluree/stage movies {:context {:ex "http://example.org/ns#"} - :id "list-test2" - :ex/list {"@list" [42 2 88 1]}}) - query-res @(fluree/query db {:context {:ex "http://example.org/ns#"} - :selectOne [:*] - :from "list-test2"})] - (is (= query-res - {:id "list-test2" - :ex/list [42 2 88 1]}) - "Order of query result is different from transaction."))))) + (let [conn (test-utils/create-conn) + movies (test-utils/load-movies conn)] + (testing "define @list container in context" + (let [db @(fluree/stage movies {:context {:ex "http://example.org/ns#" + :ex/list {"@container" "@list"}} + :id "list-test" + :ex/list [42 2 88 1]}) + query-res @(fluree/query db {:context {:ex "http://example.org/ns#"} + :selectOne [:*] + :from "list-test"})] + (is (= query-res + {:id "list-test" + :ex/list [42 2 88 1]}) + "Order of query result is different from transaction."))) + (testing "define @list directly on subject" + (let [db @(fluree/stage movies {:context {:ex "http://example.org/ns#"} + :id "list-test2" + :ex/list {"@list" [42 2 88 1]}}) + query-res @(fluree/query db {:context {:ex "http://example.org/ns#"} + :selectOne [:*] + :from "list-test2"})] + (is (= query-res + {:id "list-test2" + :ex/list [42 2 88 1]}) + "Order of query result is different from transaction.")))))) diff --git a/test/fluree/db/query/json_ld_compound_test.clj b/test/fluree/db/query/json_ld_compound_test.clj index c95068044..eb98025dd 100644 --- a/test/fluree/db/query/json_ld_compound_test.clj +++ b/test/fluree/db/query/json_ld_compound_test.clj @@ -2,16 +2,13 @@ (:require [clojure.string :as str] [clojure.test :refer :all] - [fluree.db.test-fixtures :as test] + [fluree.db.test-utils :as test-utils] [fluree.db.json-ld.api :as fluree] [fluree.db.util.log :as log])) - -(use-fixtures :once test/test-system) - (deftest simple-compound-queries (testing "Simple compound queries." - (let [conn test/memory-conn + (let [conn (test-utils/create-conn) ledger @(fluree/create conn "query/compounda") db @(fluree/stage ledger @@ -162,5 +159,3 @@ ; ["Brian" 7] ; ["Cam" 15]]) ; "Sums of favNums by person are not accurate.") - - diff --git a/test/fluree/db/query/subclass_test.clj b/test/fluree/db/query/subclass_test.clj index 151e918cd..475f2526a 100644 --- a/test/fluree/db/query/subclass_test.clj +++ b/test/fluree/db/query/subclass_test.clj @@ -1,14 +1,12 @@ (ns fluree.db.query.subclass-test (:require [clojure.test :refer :all] - [fluree.db.test-fixtures :as test] + [fluree.db.test-utils :as test-utils] [fluree.db.json-ld.api :as fluree] [fluree.db.util.log :as log])) -(use-fixtures :once test/test-system) - (deftest subclass-test (testing "Subclass queries work." - (let [conn test/memory-conn + (let [conn (test-utils/create-conn) ledger @(fluree/create conn "query/subclass") db1 @(fluree/stage ledger @@ -61,4 +59,4 @@ :schema/name "The Hitchhiker's Guide to the Galaxy", :schema/isbn "0-330-25864-8", :schema/author {:id :wiki/Q42}}]) - "CreativeWork query should return both Book and Movie")))) \ No newline at end of file + "CreativeWork query should return both Book and Movie")))) diff --git a/test/fluree/db/shacl/shacl_basic_test.clj b/test/fluree/db/shacl/shacl_basic_test.clj index 01026eceb..6260cb77c 100644 --- a/test/fluree/db/shacl/shacl_basic_test.clj +++ b/test/fluree/db/shacl/shacl_basic_test.clj @@ -1,17 +1,14 @@ (ns fluree.db.shacl.shacl-basic-test (:require [clojure.test :refer :all] - [fluree.db.test-fixtures :as test] + [fluree.db.test-utils :as test-utils] [fluree.db.json-ld.api :as fluree] [fluree.db.util.log :as log] [fluree.db.util.core :as util] [clojure.string :as str])) - -(use-fixtures :once test/test-system) - (deftest using-pre-defined-types-as-classes (testing "Class not used as class initially can still be used as one." - (let [conn test/memory-conn + (let [conn (test-utils/create-conn) ledger @(fluree/create conn "class/testing") db1 @(fluree/stage ledger @@ -35,7 +32,7 @@ (deftest shacl-cardinality-constraints (testing "shacl minimum and maximum cardinality" - (let [conn test/memory-conn + (let [conn (test-utils/create-conn) ledger @(fluree/create conn "shacl/a") user-query {:context {:ex "http://example.org/ns/"} :select {'?s [:*]} @@ -93,7 +90,7 @@ (deftest shacl-datatype-constraings (testing "shacl datatype errors" - (let [conn test/memory-conn + (let [conn (test-utils/create-conn) ledger @(fluree/create conn "shacl/b") user-query {:context {:ex "http://example.org/ns/"} :select {'?s [:*]} @@ -146,7 +143,7 @@ (deftest shacl-closed-shape (testing "shacl closed shape" - (let [conn test/memory-conn + (let [conn (test-utils/create-conn) ledger @(fluree/create conn "shacl/c") user-query {:context {:ex "http://example.org/ns/"} :select {'?s [:*]} @@ -186,4 +183,4 @@ [{:id :ex/john, :rdf/type [:ex/User], :schema/name "John"}]) - "basic rdf:type query response not correct")))) \ No newline at end of file + "basic rdf:type query response not correct")))) diff --git a/test/fluree/db/test_fixtures.clj b/test/fluree/db/test_fixtures.clj deleted file mode 100644 index 795135468..000000000 --- a/test/fluree/db/test_fixtures.clj +++ /dev/null @@ -1,85 +0,0 @@ -(ns fluree.db.test-fixtures - (:require [clojure.test :refer :all] - [fluree.db.did :as did] - [fluree.db.json-ld.api :as fluree] - [fluree.db.util.log :as log])) - - -(def default-ctx {:id "@id" - :type "@type" - :xsd "http://www.w3.org/2001/XMLSchema#" - :rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" - :rdfs "http://www.w3.org/2000/01/rdf-schema#" - :sh "http://www.w3.org/ns/shacl#" - :schema "http://schema.org/" - :skos "http://www.w3.org/2008/05/skos#" - :wiki "https://www.wikidata.org/wiki/" - :f "https://ns.flur.ee/ledger#"}) - -(def default-did (did/private->did-map "8ce4eca704d653dec594703c81a84c403c39f262e54ed014ed857438933a2e1c")) - -(def memory-conn nil) -(def ledgers {}) - -(defn get-ledger - "Retrieves a specific ledger for tests based on ledger keyword" - [ledger] - (get ledgers ledger)) - -(defn create-conn - [opts] - (let [conn @(fluree/connect-memory - {:defaults {:context default-ctx - :did default-did}})] - (alter-var-root #'memory-conn (constantly conn)))) - - -(defn load-movies - [conn] - (let [ledger @(fluree/create conn "test/movies") - stage1-db @(fluree/stage - ledger - {"@context" "https://schema.org", - "id" "https://www.wikidata.org/wiki/Q836821", - "type" ["Movie"], - "name" "The Hitchhiker's Guide to the Galaxy", - "disambiguatingDescription" "2005 British-American comic science fiction film directed by Garth Jennings", - "titleEIDR" "10.5240/B752-5B47-DBBE-E5D4-5A3F-N", - "isBasedOn" {"id" "https://www.wikidata.org/wiki/Q3107329", - "type" "Book", - "name" "The Hitchhiker's Guide to the Galaxy", - "isbn" "0-330-25864-8", - "author" {"@id" "https://www.wikidata.org/wiki/Q42" - "@type" "Person" - "name" "Douglas Adams"}}}) - commit1 @(fluree/commit! stage1-db {:message "First commit!" - :push? true})] - ledger)) - -(defn load-sample-ledgers - [] - (let [conn memory-conn - movies (load-movies conn)] - (alter-var-root #'ledgers (fn [m] (assoc m :test/movies movies))))) - - -(defn stop* - [] - (alter-var-root #'memory-conn (constantly nil)) - (alter-var-root #'ledgers (constantly {}))) - - -(defn test-system - "This fixture is intended to be used like this: - (use-fixture :once test-system) - It starts up an in-memory (by default) connection for testing." - ([tests] (test-system {} tests)) - ([opts tests] - (try - (create-conn opts) - (load-sample-ledgers) - (tests) - (catch Throwable e - (log/error e "Caught test exception") - (throw e)) - (finally (stop*))))) \ No newline at end of file diff --git a/test/fluree/db/test_utils.clj b/test/fluree/db/test_utils.clj new file mode 100644 index 000000000..23b1ee871 --- /dev/null +++ b/test/fluree/db/test_utils.clj @@ -0,0 +1,33 @@ +(ns fluree.db.test-utils + (:require [clojure.test :refer :all] + [clojure.edn :as edn] + [clojure.java.io :as io] + [fluree.db.did :as did] + [fluree.db.json-ld.api :as fluree] + [fluree.db.util.log :as log]) + (:import (java.io PushbackReader))) + +(defn load-edn-resource + [resource-path] + (with-open [r (-> resource-path io/resource io/reader PushbackReader.)] + (edn/read r))) + +(def default-did (did/private->did-map "8ce4eca704d653dec594703c81a84c403c39f262e54ed014ed857438933a2e1c")) + +(defn create-conn + ([] + (create-conn {})) + ([{:keys [context did] + :or {context (load-edn-resource "default_context.edn") + did default-did}}] + @(fluree/connect-memory {:defaults {:context context + :did did}}))) + +(defn load-movies + [conn] + (let [ledger @(fluree/create conn "test/movies") + movies (load-edn-resource "movies.edn") + stage1-db @(fluree/stage ledger movies) + commit1 @(fluree/commit! stage1-db {:message "First commit!" + :push? true})] + ledger)) diff --git a/test/fluree/db/transact/retraction_test.clj b/test/fluree/db/transact/retraction_test.clj index 49edc6305..d3def4c78 100644 --- a/test/fluree/db/transact/retraction_test.clj +++ b/test/fluree/db/transact/retraction_test.clj @@ -1,14 +1,12 @@ (ns fluree.db.transact.retraction-test (:require [clojure.test :refer :all] - [fluree.db.test-fixtures :as test] + [fluree.db.test-utils :as test-utils] [fluree.db.json-ld.api :as fluree] [fluree.db.util.log :as log])) -(use-fixtures :once test/test-system) - (deftest retracting-data (testing "Retractions of individual properties and entire subjects." - (let [conn test/memory-conn + (let [conn (test-utils/create-conn) ledger @(fluree/create conn "tx/retract") db @(fluree/stage ledger From 7d1f9acbf558502070891b92fa6c744fbad6e4a4 Mon Sep 17 00:00:00 2001 From: Benjamin Lamothe Date: Thu, 3 Nov 2022 09:28:40 -0400 Subject: [PATCH 3/4] save the dev private key on the resource path --- .../{default_context.edn => default-context.edn} | 0 dev-resources/default-dev-private-key.edn | 1 + test/fluree/db/test_utils.clj | 8 ++++---- 3 files changed, 5 insertions(+), 4 deletions(-) rename dev-resources/{default_context.edn => default-context.edn} (100%) create mode 100644 dev-resources/default-dev-private-key.edn diff --git a/dev-resources/default_context.edn b/dev-resources/default-context.edn similarity index 100% rename from dev-resources/default_context.edn rename to dev-resources/default-context.edn diff --git a/dev-resources/default-dev-private-key.edn b/dev-resources/default-dev-private-key.edn new file mode 100644 index 000000000..7289a7638 --- /dev/null +++ b/dev-resources/default-dev-private-key.edn @@ -0,0 +1 @@ +"8ce4eca704d653dec594703c81a84c403c39f262e54ed014ed857438933a2e1c" diff --git a/test/fluree/db/test_utils.clj b/test/fluree/db/test_utils.clj index 23b1ee871..05a79f82a 100644 --- a/test/fluree/db/test_utils.clj +++ b/test/fluree/db/test_utils.clj @@ -12,14 +12,14 @@ (with-open [r (-> resource-path io/resource io/reader PushbackReader.)] (edn/read r))) -(def default-did (did/private->did-map "8ce4eca704d653dec594703c81a84c403c39f262e54ed014ed857438933a2e1c")) - (defn create-conn ([] (create-conn {})) ([{:keys [context did] - :or {context (load-edn-resource "default_context.edn") - did default-did}}] + :or {context (load-edn-resource "default-context.edn") + did (-> "default-dev-private-key.edn" + load-edn-resource + did/private->did-map)}}] @(fluree/connect-memory {:defaults {:context context :did did}}))) From de2a1c241a208a54022ad3c696c402d2bcc447f4 Mon Sep 17 00:00:00 2001 From: Benjamin Lamothe Date: Thu, 3 Nov 2022 10:07:44 -0400 Subject: [PATCH 4/4] add `:integration` metadata tags to integration tests This allows us to run only the integration tests with: ``` clojure -M:cljtest --focus-meta :integration ``` --- test/fluree/db/query/json_ld_basic_test.clj | 6 +++--- test/fluree/db/query/json_ld_compound_test.clj | 2 +- test/fluree/db/query/subclass_test.clj | 2 +- test/fluree/db/shacl/shacl_basic_test.clj | 8 ++++---- test/fluree/db/transact/retraction_test.clj | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/test/fluree/db/query/json_ld_basic_test.clj b/test/fluree/db/query/json_ld_basic_test.clj index 21d532199..5703ce429 100644 --- a/test/fluree/db/query/json_ld_basic_test.clj +++ b/test/fluree/db/query/json_ld_basic_test.clj @@ -4,7 +4,7 @@ [fluree.db.json-ld.api :as fluree] [fluree.db.util.log :as log])) -(deftest json-ld-basic-query +(deftest ^:integration json-ld-basic-query (testing "json-ld" (let [conn (test-utils/create-conn) movies (test-utils/load-movies conn) @@ -76,7 +76,7 @@ :rdf/type [:schema/Person], :schema/name "Douglas Adams"}}})))))))) -(deftest json-ld-rdf-type-query +(deftest ^:integration json-ld-rdf-type-query (testing "json-ld rdf type queries" (let [conn (test-utils/create-conn) movies (test-utils/load-movies conn) @@ -94,7 +94,7 @@ "Standard bootstrap data isn't matching.")))))) -(deftest json-ld-list-order-preservation +(deftest ^:integration json-ld-list-order-preservation (testing "json-ld @container @list option" (let [conn (test-utils/create-conn) movies (test-utils/load-movies conn)] diff --git a/test/fluree/db/query/json_ld_compound_test.clj b/test/fluree/db/query/json_ld_compound_test.clj index bc74b4728..ea01752af 100644 --- a/test/fluree/db/query/json_ld_compound_test.clj +++ b/test/fluree/db/query/json_ld_compound_test.clj @@ -6,7 +6,7 @@ [fluree.db.json-ld.api :as fluree] [fluree.db.util.log :as log])) -(deftest simple-compound-queries +(deftest ^:integration simple-compound-queries (testing "Simple compound queries." (let [conn (test-utils/create-conn) ledger @(fluree/create conn "query/compounda") diff --git a/test/fluree/db/query/subclass_test.clj b/test/fluree/db/query/subclass_test.clj index 475f2526a..3b15af655 100644 --- a/test/fluree/db/query/subclass_test.clj +++ b/test/fluree/db/query/subclass_test.clj @@ -4,7 +4,7 @@ [fluree.db.json-ld.api :as fluree] [fluree.db.util.log :as log])) -(deftest subclass-test +(deftest ^:integration subclass-test (testing "Subclass queries work." (let [conn (test-utils/create-conn) ledger @(fluree/create conn "query/subclass") diff --git a/test/fluree/db/shacl/shacl_basic_test.clj b/test/fluree/db/shacl/shacl_basic_test.clj index 6260cb77c..c14b22aa0 100644 --- a/test/fluree/db/shacl/shacl_basic_test.clj +++ b/test/fluree/db/shacl/shacl_basic_test.clj @@ -6,7 +6,7 @@ [fluree.db.util.core :as util] [clojure.string :as str])) -(deftest using-pre-defined-types-as-classes +(deftest ^:integration using-pre-defined-types-as-classes (testing "Class not used as class initially can still be used as one." (let [conn (test-utils/create-conn) ledger @(fluree/create conn "class/testing") @@ -30,7 +30,7 @@ :schema/description "Now a new subject uses MyClass as a Class"}]))))) -(deftest shacl-cardinality-constraints +(deftest ^:integration shacl-cardinality-constraints (testing "shacl minimum and maximum cardinality" (let [conn (test-utils/create-conn) ledger @(fluree/create conn "shacl/a") @@ -88,7 +88,7 @@ "basic rdf:type query response not correct")))) -(deftest shacl-datatype-constraings +(deftest ^:integration shacl-datatype-constraings (testing "shacl datatype errors" (let [conn (test-utils/create-conn) ledger @(fluree/create conn "shacl/b") @@ -141,7 +141,7 @@ "basic rdf:type query response not correct")))) -(deftest shacl-closed-shape +(deftest ^:integration shacl-closed-shape (testing "shacl closed shape" (let [conn (test-utils/create-conn) ledger @(fluree/create conn "shacl/c") diff --git a/test/fluree/db/transact/retraction_test.clj b/test/fluree/db/transact/retraction_test.clj index d3def4c78..1971b3c18 100644 --- a/test/fluree/db/transact/retraction_test.clj +++ b/test/fluree/db/transact/retraction_test.clj @@ -4,7 +4,7 @@ [fluree.db.json-ld.api :as fluree] [fluree.db.util.log :as log])) -(deftest retracting-data +(deftest ^:integration retracting-data (testing "Retractions of individual properties and entire subjects." (let [conn (test-utils/create-conn) ledger @(fluree/create conn "tx/retract")