provide multi-file-loading

This commit is contained in:
jem 2019-05-28 09:18:11 +02:00
parent 9eaf2818e1
commit 67af5c1d67
5 changed files with 27 additions and 13 deletions

View file

@ -43,15 +43,21 @@
(map #(str prefix "." % ".edn") (map #(str prefix "." % ".edn")
(range 10))))) (range 10)))))
(s/defn load-data-test-specs :- '(TestDataSpec) (s/defn load-data-test-spec
[file-prefix :- s/Str] [file-path :- s/Str]
(let [file-path (str file-prefix ".edn")] (let [file-resource (io/resource file-path)]
(try (when file-resource
(read-test-data-spec (io/resource file-path)) (read-test-data-spec file-resource))))
(catch IllegalArgumentException e
(throw (ex-info (str "Could not find test spec on " file-path) (s/defn load-data-test-specs :- [TestDataSpec]
{:message "Could not find test spec" [name-key :- s/Keyword]
:file-path file-prefix} e)))))) (let [data-test-specs (filter some?
(map load-data-test-spec (data-test-spec-file-names name-key)))]
(if (empty? data-test-specs)
(throw (ex-info (str "Could not find test spec on " name-key)
{:message "Could not find test spec"
:name-key name-key}))
(into [] data-test-specs))))
(s/defn load-test-data (s/defn load-test-data
[file-prefix :- s/Str] [file-prefix :- s/Str]

View file

@ -1 +1 @@
{:test "data"} {:test "data1"}

View file

@ -0,0 +1 @@
{:test "data9"}

View file

@ -1 +0,0 @@
{:test "data"}

View file

@ -47,8 +47,16 @@
(deftest should-load-data (deftest should-load-data
(is (= {:test "data"} (is (= {:test "data"}
(sut/load-test-data (sut/data-test-spec-file-prefix ::test-it))))) (sut/load-data-test-spec (str (sut/data-test-spec-file-prefix ::test-it) ".edn")))))
(deftest should-not-load-non-existing-data
(is (= nil
(sut/load-data-test-spec (str (sut/data-test-spec-file-prefix ::not-existing) ".edn")))))
(deftest should-load-data-test-specs
(is (= [{:test "data"} {:test "data1"} {:test "data9"}]
(sut/load-data-test-specs ::test-it))))
(deftest should-throw-exception (deftest should-throw-exception
(is (thrown? RuntimeException (is (thrown? RuntimeException
(sut/load-test-data (sut/data-test-spec-file-prefix ::not-existing))))) (sut/load-data-test-specs ::not-existing))))