Skip to content
Snippets Groups Projects
Commit 832bd10e authored by Bruno Burke's avatar Bruno Burke :hamburger:
Browse files

generate testdocuments for protocol tests

parent 9f01c083
No related branches found
No related tags found
1 merge request!1Draft: Migration
Pipeline #91806 passed
...@@ -18,9 +18,11 @@ ...@@ -18,9 +18,11 @@
:profiles {:test [:project/test :profiles/test] :profiles {:test [:project/test :profiles/test]
:dev [:project/dev :profiles/dev] :dev [:project/dev :profiles/dev]
:profiles/dev {} :profiles/dev {}
:project/dev {:dependencies [[environ "1.2.0"]] :project/dev {:dependencies [[environ "1.2.0"]
[org.clojure/test.check "0.9.0"]]
:plugins [[lein-environ "1.2.0"]]} :plugins [[lein-environ "1.2.0"]]}
:profiles/test {} :profiles/test {}
:project/test {:dependencies [[environ "1.2.0"]] :project/test {:dependencies [[environ "1.2.0"]
[org.clojure/test.check "0.9.0"]]
:plugins [[lein-environ "1.2.0"]]}}) :plugins [[lein-environ "1.2.0"]]}})
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
:repositories [:testrepo] :repositories [:testrepo]
:jdbc-url (env :database-url)})) :jdbc-url (env :database-url)}))
(f) (f)
#_(.delete-repository @ds-atom :testrepo)) (.delete-repository @ds-atom :testrepo))
(use-fixtures :once storage-fixture) (use-fixtures :once storage-fixture)
......
...@@ -2,12 +2,13 @@ ...@@ -2,12 +2,13 @@
(:require [document-storage.protocol :as sut] (:require [document-storage.protocol :as sut]
[clojure.test :refer :all] [clojure.test :refer :all]
[clj-helper.string :refer [get-unique-id]] [clj-helper.string :refer [get-unique-id]]
[clojure.data :refer [diff]])) [clojure.data :refer [diff]]
[document-storage.testdata :refer [generate-document]]))
(defn test-save-document [ds-atom] (defn test-save-document [ds-atom]
(testing "save basic structure and load it" (testing "save basic structure and load it"
(let [structure {:a 7 :c [1 2 3 4 99 5 -4] :v 3} (let [structure (generate-document)
id "simple-test1" id "simple-test1"
repo :testrepo] repo :testrepo]
(.save-document @ds-atom id structure repo) (.save-document @ds-atom id structure repo)
...@@ -17,7 +18,7 @@ ...@@ -17,7 +18,7 @@
(defn test-versioning [ds-atom] (defn test-versioning [ds-atom]
(testing "update document and check if changes are versioned" (testing "update document and check if changes are versioned"
(let [structure-v1 {:a 7 :c [1 2 3 4 99 5 -4] :v 3} (let [structure-v1 (generate-document) #_{:a 7 :c [1 2 3 4 99 5 -4] :v 3}
structure-v2 (-> structure-v1 structure-v2 (-> structure-v1
(assoc :a 1 :v -3) (assoc :a 1 :v -3)
(assoc-in [:c 2] 1258)) (assoc-in [:c 2] 1258))
......
(ns document-storage.testdata
(:require [clojure.test :as t]
[clojure.spec.alpha :as s]
[clojure.spec.gen.alpha :as gen]
[clojure.string :as str]))
(s/def :content-element.html/content (s/and
string?
#(> (count %) 32)))
(s/def :content-element.text/content (s/and
string?
#(> (count %) 32)))
(s/def :content-element/id string?)
(s/def :content-element/type #{:html :text})
(defmulti content-type :type)
(defmethod content-type :html [_]
(s/keys :req-un [:content-element/id :content-element/type :content-element.html/content]))
(defmethod content-type :text [_]
(s/keys :req-un [:content-element/id :content-element/type :content-element.text/content]))
(s/def ::content-element (s/multi-spec content-type :type))
(s/explain-str ::content-element {:type :html})
(s/def :document/content (s/coll-of ::content-element
:into []
:gen-max 35))
(s/def :document/created-at inst?)
(s/def :document/updated-at (s/nilable inst?))
(s/def :document/title (s/and
string?
#(> (count %) 10)))
(s/def :document/tags (s/coll-of string?
:into #{}
:gen-max 6))
(s/def ::document (s/keys :req-un [:document/title
:document/tags
:document/created-at
:document/updated-at
:document/content]))
(defn generate-document []
(gen/generate (s/gen ::document)))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment