provide multi-file-loading
This commit is contained in:
parent
9eaf2818e1
commit
67af5c1d67
5 changed files with 27 additions and 13 deletions
|
@ -43,15 +43,21 @@
|
|||
(map #(str prefix "." % ".edn")
|
||||
(range 10)))))
|
||||
|
||||
(s/defn load-data-test-specs :- '(TestDataSpec)
|
||||
[file-prefix :- s/Str]
|
||||
(let [file-path (str file-prefix ".edn")]
|
||||
(try
|
||||
(read-test-data-spec (io/resource file-path))
|
||||
(catch IllegalArgumentException e
|
||||
(throw (ex-info (str "Could not find test spec on " file-path)
|
||||
{:message "Could not find test spec"
|
||||
:file-path file-prefix} e))))))
|
||||
(s/defn load-data-test-spec
|
||||
[file-path :- s/Str]
|
||||
(let [file-resource (io/resource file-path)]
|
||||
(when file-resource
|
||||
(read-test-data-spec file-resource))))
|
||||
|
||||
(s/defn load-data-test-specs :- [TestDataSpec]
|
||||
[name-key :- s/Keyword]
|
||||
(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
|
||||
[file-prefix :- s/Str]
|
||||
|
|
|
@ -1 +1 @@
|
|||
{:test "data"}
|
||||
{:test "data1"}
|
1
test/resources/data_test/file_loader_test/test_it.9.edn
Normal file
1
test/resources/data_test/file_loader_test/test_it.9.edn
Normal file
|
@ -0,0 +1 @@
|
|||
{:test "data9"}
|
|
@ -1 +0,0 @@
|
|||
{:test "data"}
|
|
@ -47,8 +47,16 @@
|
|||
|
||||
(deftest should-load-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
|
||||
(is (thrown? RuntimeException
|
||||
(sut/load-test-data (sut/data-test-spec-file-prefix ::not-existing)))))
|
||||
(sut/load-data-test-specs ::not-existing))))
|
||||
|
|
Loading…
Reference in a new issue