Fixed validate-config to handle planet mode.

This commit is contained in:
John Wiseman 2020-10-12 15:44:39 -07:00
parent 6a55807542
commit d5c325493e
2 changed files with 18 additions and 17 deletions

View File

@ -787,21 +787,24 @@
(defn validate-config [config] (defn validate-config [config]
(let [required [[:lat] (let [required [[:aircraft-info-db-path]
[:lon]
[:radius-km]
[:aircraft-info-db-path]
[:adsbx :url] [:adsbx :url]
[:adsbx :api-key] [:adsbx :api-key]
[:pelias :url]] [:pelias :url]]
present (util/nested-keys config) present (set (util/nested-keys config))
missing1 (set/difference (set required) (set present)) missing1 (set/difference (set required) present)
missing2 (when (get-in config [:twitter :enabled?]) missing2 (when (get-in config [:twitter :enabled?])
(let [required (map (fn [key] [:twitter key]) (let [required (map (fn [key] [:twitter key])
[:consumer-key :consumer-secret [:consumer-key :consumer-secret
:access-token :access-token-secret])] :access-token :access-token-secret])]
(set/difference (set required) (set present)))) (set/difference (set required) present)))
missing (concat missing1 missing2)] 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) (when (seq missing)
(throw (js/Error. (str "Missing configuration values: " (throw (js/Error. (str "Missing configuration values: "
(string/join ", " (sort-by str missing)))))))) (string/join ", " (sort-by str missing))))))))

View File

@ -443,21 +443,19 @@
(advisorycircular/validate-config {})))) (advisorycircular/validate-config {}))))
(testing "Bad config missing lat-lon-radius" (testing "Bad config missing lat-lon-radius"
(is (thrown-with-msg? (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 (advisorycircular/validate-config
{:adsbx {:api-key "my-adsbx-key" {:adsbx {:api-key "my-adsbx-key"
:url "http://adsbx"} :url "http://adsbx"}
:aircraft-info-db-path "/" :aircraft-info-db-path "/"
:pelias {:url "http://pelias/"}})))) :pelias {:url "http://pelias/"}}))))
(testing "Bad config with icaos instead of lat/lon/radius" (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 (advisorycircular/validate-config
{:adsbx {:api-key "my-adsbx-key" {:adsbx {:api-key "my-adsbx-key"
:url "http://adsbx"} :url "http://adsbx"}
:aircraft-info-db-path "/" :aircraft-info-db-path "/"
:pelias {:url "http://pelias/"} :pelias {:url "http://pelias/"}
:icaos ["123" "456"]}))))) :icaos ["123" "456"]})))
(deftest adsbx-url (deftest adsbx-url