Skip to content

Commit 70b67f6

Browse files
committed
Update tests
1 parent 6596c50 commit 70b67f6

File tree

2 files changed

+23
-63
lines changed

2 files changed

+23
-63
lines changed

test/resources/csv-config.edn

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{:some-config #csv #or [#env SOME "value1, value2"]
2+
:malformed-config #csv #or [#env MALFORMED "value3, value4,value5, "]
3+
:trailing-comma-config #csv #or [#env TRAILING_COMMA "value6, value7,"]}
Lines changed: 20 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,28 @@
11
(ns unit.codes.clj.docs.backend.config-test
2-
(:require [clojure.test :refer [deftest is testing use-fixtures]]
2+
(:require [aero.core :as aero]
3+
[clojure.test :refer [deftest is testing use-fixtures]]
34
[codes.clj.docs.backend.config :as backend.config]
4-
[com.stuartsierra.component :as component]
5-
[matcher-combinators.matchers :refer [embeds]]
65
[matcher-combinators.test :refer [match?]]
7-
[parenthesin.components.config.aero :as config.aero]
86
[parenthesin.helpers.malli :as helpers.malli]))
97

108
(use-fixtures :once helpers.malli/with-intrumentation)
119

12-
(defn- create-and-start-system!
13-
[{:keys [config]}]
14-
(component/start-system
15-
(component/system-map :config config)))
16-
1710
(deftest str-var->vector-var-test
18-
(let [system (create-and-start-system!
19-
{:config (config.aero/new-config {:some-config "value1, value2"
20-
:another-config
21-
{:nested-config "value3, value4"}
22-
:malformed-config "value5, value6,value7, "
23-
:trailing-comma "value8, value9,"})})
24-
config-component (:config system)]
25-
26-
(testing "root-level configs should be converted to vectors"
27-
(is (match? {:config {:some-config ["value1" "value2"]}}
28-
(#'backend.config/str-var->vector-var
29-
config-component [:config :some-config]))))
30-
31-
(testing "nested configs should be converted to vectors"
32-
(is (match? {:config {:another-config {:nested-config ["value3" "value4"]}}}
33-
(#'backend.config/str-var->vector-var
34-
config-component [:config :another-config :nested-config]))))
35-
36-
(testing "trailing and extra whitespaces should be ignored"
37-
(is (match? {:config {:malformed-config ["value5" "value6" "value7"]}}
38-
(#'backend.config/str-var->vector-var
39-
config-component [:config :malformed-config]))))
40-
41-
(testing "trailing commas should be ignored"
42-
(is (match? {:config {:trailing-comma ["value8" "value9"]}}
43-
(#'backend.config/str-var->vector-var
44-
config-component [:config :trailing-comma]))))
45-
46-
(let [vector-env-vars [[:config :some-config]
47-
[:config :another-config :nested-config]
48-
[:config :malformed-config]
49-
[:config :trailing-comma]]
50-
no-matching-env-vars [[:config :non-existent-config]]
51-
converted-configs {:some-config ["value1" "value2"],
52-
:another-config {:nested-config ["value3" "value4"]}
53-
:malformed-config ["value5" "value6" "value7"]
54-
:trailing-comma ["value8" "value9"]}
55-
unaltered-configs {:some-config "value1, value2",
56-
:another-config {:nested-config "value3, value4"}
57-
:malformed-config "value5, value6,value7, "
58-
:trailing-comma "value8, value9,"}]
59-
60-
(testing "all defined vector-env-vars should be processed"
61-
(is (match? {:config (embeds converted-configs)}
62-
(backend.config/config config-component vector-env-vars))))
63-
64-
(testing "when vector-env-vars is empty, the config should be left unaltered"
65-
(is (match? {:config (embeds unaltered-configs)}
66-
(backend.config/config config-component []))))
67-
68-
(testing "when vector-env-vars has no matches, the config should be left unaltered"
69-
(is (match? {:config (embeds unaltered-configs)}
70-
(backend.config/config config-component
71-
no-matching-env-vars)))))))
11+
(testing "root-level configs should be converted to vectors"
12+
(is (match? ["value1" "value2"]
13+
(#'backend.config/str-var->vector-var "value1, value2"))))
14+
15+
(testing "trailing and extra whitespaces should be ignored"
16+
(is (match? ["value3" "value4" "value5"]
17+
(#'backend.config/str-var->vector-var "value3, value4,value5, "))))
18+
19+
(testing "trailing commas should be ignored"
20+
(is (match? ["value6" "value7"]
21+
(#'backend.config/str-var->vector-var "value6, value7,")))))
22+
23+
(deftest csv-reader-test
24+
(testing "tag literal #csv should turn comma-separated strings into vectors"
25+
(is (match? {:some-config ["value1" "value2"]
26+
:malformed-config ["value3" "value4" "value5"]
27+
:trailing-comma-config ["value6" "value7"]}
28+
(aero/read-config "test/resources/csv-config.edn")))))

0 commit comments

Comments
 (0)