From d5c325493e708061b0ec9af142d11c49acfeca52 Mon Sep 17 00:00:00 2001 From: John Wiseman Date: Mon, 12 Oct 2020 15:44:39 -0700 Subject: [PATCH] Fixed validate-config to handle planet mode. --- src/main/lemondronor/advisorycircular.cljs | 19 +++++++++++-------- .../lemondronor/advisorycircular_test.cljs | 16 +++++++--------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/main/lemondronor/advisorycircular.cljs b/src/main/lemondronor/advisorycircular.cljs index 78308fd..5cb7174 100644 --- a/src/main/lemondronor/advisorycircular.cljs +++ b/src/main/lemondronor/advisorycircular.cljs @@ -787,21 +787,24 @@ (defn validate-config [config] - (let [required [[:lat] - [:lon] - [:radius-km] - [:aircraft-info-db-path] + (let [required [[:aircraft-info-db-path] [:adsbx :url] [:adsbx :api-key] [:pelias :url]] - present (util/nested-keys config) - missing1 (set/difference (set required) (set present)) + present (set (util/nested-keys config)) + missing1 (set/difference (set required) present) missing2 (when (get-in config [:twitter :enabled?]) (let [required (map (fn [key] [:twitter key]) [:consumer-key :consumer-secret :access-token :access-token-secret])] - (set/difference (set required) (set present)))) - missing (concat missing1 missing2)] + (set/difference (set required) present))) + missing3 (when (or (:lat config) (:lon config) (:radius-km config)) + (let [required [[:lat] [:lon] [:radius-km]]] + (set/difference (set required) present))) + missing4 (when (and (not (or (:lat config) (:lon config) (:radius-km config))) + (not (:icaos config))) + ["[lat, lon, and radius-km OR icaos]"]) + missing (concat missing1 missing2 missing3 missing4)] (when (seq missing) (throw (js/Error. (str "Missing configuration values: " (string/join ", " (sort-by str missing)))))))) diff --git a/src/test/lemondronor/advisorycircular_test.cljs b/src/test/lemondronor/advisorycircular_test.cljs index f1100a0..3e937c4 100644 --- a/src/test/lemondronor/advisorycircular_test.cljs +++ b/src/test/lemondronor/advisorycircular_test.cljs @@ -443,21 +443,19 @@ (advisorycircular/validate-config {})))) (testing "Bad config missing lat-lon-radius" (is (thrown-with-msg? - js/Error #"Missing configuration values.*lat.*lon.*radius-km" + js/Error #"Missing configuration values.*lat.*lon.*radius-km.*OR.*icaos" (advisorycircular/validate-config {:adsbx {:api-key "my-adsbx-key" :url "http://adsbx"} :aircraft-info-db-path "/" :pelias {:url "http://pelias/"}})))) (testing "Bad config with icaos instead of lat/lon/radius" - (is (thrown-with-msg? - js/Error #"Missing configuration values.*lat.*lon.*radius-km" - (advisorycircular/validate-config - {:adsbx {:api-key "my-adsbx-key" - :url "http://adsbx"} - :aircraft-info-db-path "/" - :pelias {:url "http://pelias/"} - :icaos ["123" "456"]}))))) + (advisorycircular/validate-config + {:adsbx {:api-key "my-adsbx-key" + :url "http://adsbx"} + :aircraft-info-db-path "/" + :pelias {:url "http://pelias/"} + :icaos ["123" "456"]}))) (deftest adsbx-url