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]
(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))))))))

View File

@ -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