diff --git a/src/codes/clj/docs/backend/config.clj b/src/codes/clj/docs/backend/config.clj index 1b16a2c..ca0a965 100644 --- a/src/codes/clj/docs/backend/config.clj +++ b/src/codes/clj/docs/backend/config.clj @@ -1,20 +1,20 @@ (ns codes.clj.docs.backend.config - (:require [aero.core :as aero] - [clojure.string :as string])) + (:require [aero.core :as aero] + [clojure.string :as string])) (defn- str-var->vector-var "Converts a string config variable to a vector of strings, when applicable. Environment variables are expected to be set as comma-separated values." [value] (if (string? value) - (let [split-configs (-> value - (string/split #",")) - env-config (->> split-configs - (map string/trim) - (remove empty?))] - env-config) - value)) + (let [split-configs (-> value + (string/split #",")) + env-config (->> split-configs + (map string/trim) + (remove empty?))] + env-config) + value)) -(defmethod aero/reader 'csv +(defmethod aero/reader 'csv [_ _ value] (str-var->vector-var value)) diff --git a/test/unit/codes/clj/docs/backend/config_test.clj b/test/unit/codes/clj/docs/backend/config_test.clj index 77cadcd..9cf4395 100644 --- a/test/unit/codes/clj/docs/backend/config_test.clj +++ b/test/unit/codes/clj/docs/backend/config_test.clj @@ -8,21 +8,21 @@ (use-fixtures :once helpers.malli/with-intrumentation) (deftest str-var->vector-var-test - (testing "root-level configs should be converted to vectors" - (is (match? ["value1" "value2"] - (#'backend.config/str-var->vector-var "value1, value2")))) + (testing "csv configs should be converted to vectors" + (is (match? ["value1" "value2"] + (#'backend.config/str-var->vector-var "value1, value2")))) - (testing "trailing and extra whitespaces should be ignored" - (is (match? ["value3" "value4" "value5"] - (#'backend.config/str-var->vector-var "value3, value4,value5, ")))) + (testing "trailing and extra whitespaces should be ignored" + (is (match? ["value3" "value4" "value5"] + (#'backend.config/str-var->vector-var "value3, value4,value5, ")))) - (testing "trailing commas should be ignored" - (is (match? ["value6" "value7"] - (#'backend.config/str-var->vector-var "value6, value7,"))))) + (testing "trailing commas should be ignored" + (is (match? ["value6" "value7"] + (#'backend.config/str-var->vector-var "value6, value7,"))))) (deftest csv-reader-test - (testing "tag literal #csv should turn comma-separated strings into vectors" - (is (match? {:some-config ["value1" "value2"] - :malformed-config ["value3" "value4" "value5"] - :trailing-comma-config ["value6" "value7"]} - (aero/read-config "test/resources/csv-config.edn"))))) + (testing "tag literal #csv should turn comma-separated strings into vectors" + (is (match? {:some-config ["value1" "value2"] + :malformed-config ["value3" "value4" "value5"] + :trailing-comma-config ["value6" "value7"]} + (aero/read-config "test/resources/csv-config.edn")))))