fixed tests with completly activated schema validation
This commit is contained in:
parent
041bf20426
commit
8b56e89782
8 changed files with 31 additions and 18 deletions
|
@ -27,7 +27,8 @@
|
||||||
:expected s/Any
|
:expected s/Any
|
||||||
(s/optional-key :meta) {(s/optional-key :name) s/Str
|
(s/optional-key :meta) {(s/optional-key :name) s/Str
|
||||||
(s/optional-key :description) s/Str
|
(s/optional-key :description) s/Str
|
||||||
(s/optional-key :link) s/Str}})
|
(s/optional-key :link) s/Str}
|
||||||
|
(s/optional-key :references) s/Any})
|
||||||
|
|
||||||
(def RuntimeTestDataSpec
|
(def RuntimeTestDataSpec
|
||||||
(merge
|
(merge
|
||||||
|
@ -38,8 +39,8 @@
|
||||||
[runtime-test-data-spec :- RuntimeTestDataSpec]
|
[runtime-test-data-spec :- RuntimeTestDataSpec]
|
||||||
(:data-spec-file runtime-test-data-spec))
|
(:data-spec-file runtime-test-data-spec))
|
||||||
|
|
||||||
(s/defn read-test-data-spec :- TestDataSpec
|
(s/defn read-test-data-spec ; :- TestDataSpec - at least TestDataSpec but more keys are allowed
|
||||||
[resource-url :- s/Str]
|
[resource-url] ; input is a url object
|
||||||
(aero/read-config resource-url))
|
(aero/read-config resource-url))
|
||||||
|
|
||||||
(s/defn data-test-spec-file-prefix :- s/Str
|
(s/defn data-test-spec-file-prefix :- s/Str
|
||||||
|
@ -56,7 +57,7 @@
|
||||||
(map #(str prefix "." % ".edn")
|
(map #(str prefix "." % ".edn")
|
||||||
(range 10)))))
|
(range 10)))))
|
||||||
|
|
||||||
(s/defn load-data-test-spec :- RuntimeTestDataSpec
|
(s/defn load-data-test-spec ; either :- RuntimeTestDataSpec or nil
|
||||||
[file-path :- s/Str]
|
[file-path :- s/Str]
|
||||||
(let [file-resource (io/resource file-path)]
|
(let [file-resource (io/resource file-path)]
|
||||||
(when file-resource
|
(when file-resource
|
||||||
|
@ -64,7 +65,7 @@
|
||||||
{:data-spec-file file-path}
|
{:data-spec-file file-path}
|
||||||
(read-test-data-spec file-resource)))))
|
(read-test-data-spec file-resource)))))
|
||||||
|
|
||||||
(s/defn load-data-test-specs :- [RuntimeTestDataSpec]
|
(s/defn load-data-test-specs ; :- [RuntimeTestDataSpec] at least but more keys are allowed in elements
|
||||||
[name-key :- s/Keyword]
|
[name-key :- s/Keyword]
|
||||||
(let [locations (data-test-spec-file-names name-key)
|
(let [locations (data-test-spec-file-names name-key)
|
||||||
data-test-specs (filter some? (map load-data-test-spec locations))]
|
data-test-specs (filter some? (map load-data-test-spec locations))]
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
{:test "data1"}
|
{:input "data1"
|
||||||
|
:expectation true}
|
|
@ -1 +1,2 @@
|
||||||
{:test "data9"}
|
{:input "data9"
|
||||||
|
:expectation true}
|
|
@ -1 +1,2 @@
|
||||||
{:test "data"}
|
{:input "data"
|
||||||
|
:expectation true}
|
|
@ -1 +1,2 @@
|
||||||
{:simple "test"}
|
{:input "test"
|
||||||
|
:expected true}
|
|
@ -1,3 +1,3 @@
|
||||||
{:to-be-refernced "ref-test"
|
{:references {:to-be-refernced "ref-test"}
|
||||||
:key1 #ref [:to-be-refernced]
|
:input #ref [:references :to-be-refernced]
|
||||||
:key2 #ref [:to-be-refernced]}
|
:expected #ref [:references :to-be-refernced]}
|
|
@ -20,9 +20,10 @@
|
||||||
[data-test.loader :as sut]))
|
[data-test.loader :as sut]))
|
||||||
|
|
||||||
(deftest should-read-test-data-spec
|
(deftest should-read-test-data-spec
|
||||||
(is (= {:simple "test"}
|
(is (= {:input "test"
|
||||||
|
:expected true}
|
||||||
(sut/read-test-data-spec (io/resource "simple_aero.edn"))))
|
(sut/read-test-data-spec (io/resource "simple_aero.edn"))))
|
||||||
(is (= {:to-be-refernced "ref-test", :key1 "ref-test", :key2 "ref-test"}
|
(is (= {:references {:to-be-refernced "ref-test"}, :input "ref-test", :expected "ref-test"}
|
||||||
(sut/read-test-data-spec (io/resource "tagged_aero.edn"))))
|
(sut/read-test-data-spec (io/resource "tagged_aero.edn"))))
|
||||||
(is (thrown? RuntimeException
|
(is (thrown? RuntimeException
|
||||||
(sut/read-test-data-spec (io/resource "aero_with_deserialization_issue.edn")))))
|
(sut/read-test-data-spec (io/resource "aero_with_deserialization_issue.edn")))))
|
||||||
|
@ -46,7 +47,8 @@
|
||||||
(sut/data-test-spec-file-names ::test-it))))
|
(sut/data-test-spec-file-names ::test-it))))
|
||||||
|
|
||||||
(deftest should-load-data
|
(deftest should-load-data
|
||||||
(is (= {:test "data"
|
(is (= {:input "data"
|
||||||
|
:expectation true
|
||||||
:data-spec-file "data_test/loader_test/test_it.edn"}
|
:data-spec-file "data_test/loader_test/test_it.edn"}
|
||||||
(sut/load-data-test-spec (str (sut/data-test-spec-file-prefix ::test-it) ".edn")))))
|
(sut/load-data-test-spec (str (sut/data-test-spec-file-prefix ::test-it) ".edn")))))
|
||||||
|
|
||||||
|
@ -55,11 +57,14 @@
|
||||||
(sut/load-data-test-spec (str (sut/data-test-spec-file-prefix ::not-existing) ".edn")))))
|
(sut/load-data-test-spec (str (sut/data-test-spec-file-prefix ::not-existing) ".edn")))))
|
||||||
|
|
||||||
(deftest should-load-data-test-specs
|
(deftest should-load-data-test-specs
|
||||||
(is (= [{:test "data"
|
(is (= [{:input "data"
|
||||||
|
:expectation true
|
||||||
:data-spec-file "data_test/loader_test/test_it.edn"}
|
:data-spec-file "data_test/loader_test/test_it.edn"}
|
||||||
{:test "data1"
|
{:input "data1"
|
||||||
|
:expectation true
|
||||||
:data-spec-file "data_test/loader_test/test_it.1.edn"}
|
:data-spec-file "data_test/loader_test/test_it.1.edn"}
|
||||||
{:test "data9"
|
{:input "data9"
|
||||||
|
:expectation true
|
||||||
:data-spec-file "data_test/loader_test/test_it.9.edn"}]
|
:data-spec-file "data_test/loader_test/test_it.9.edn"}]
|
||||||
(sut/load-data-test-specs ::test-it))))
|
(sut/load-data-test-specs ::test-it))))
|
||||||
|
|
||||||
|
|
|
@ -17,9 +17,12 @@
|
||||||
(:require
|
(:require
|
||||||
[clojure.test :refer :all]
|
[clojure.test :refer :all]
|
||||||
[clojure.java.io :as io]
|
[clojure.java.io :as io]
|
||||||
|
[schema.core :as s]
|
||||||
[data-test.loader :as loader]
|
[data-test.loader :as loader]
|
||||||
[data-test :as sut]))
|
[data-test :as sut]))
|
||||||
|
|
||||||
|
(s/set-fn-validation! true)
|
||||||
|
|
||||||
; -------------------- explicit version ------------------
|
; -------------------- explicit version ------------------
|
||||||
(deftest should-test-with-data-explicit-version
|
(deftest should-test-with-data-explicit-version
|
||||||
(let [testdata (loader/read-test-data-spec (io/resource "data_test_test/should_test_with_data_explicit_version.edn"))
|
(let [testdata (loader/read-test-data-spec (io/resource "data_test_test/should_test_with_data_explicit_version.edn"))
|
||||||
|
|
Loading…
Reference in a new issue