Fixed validate-config to handle planet mode.
This commit is contained in:
parent
6a55807542
commit
d5c325493e
@ -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))))))))
|
||||||
|
@ -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?
|
(advisorycircular/validate-config
|
||||||
js/Error #"Missing configuration values.*lat.*lon.*radius-km"
|
{:adsbx {:api-key "my-adsbx-key"
|
||||||
(advisorycircular/validate-config
|
:url "http://adsbx"}
|
||||||
{:adsbx {:api-key "my-adsbx-key"
|
:aircraft-info-db-path "/"
|
||||||
:url "http://adsbx"}
|
:pelias {:url "http://pelias/"}
|
||||||
:aircraft-info-db-path "/"
|
:icaos ["123" "456"]})))
|
||||||
:pelias {:url "http://pelias/"}
|
|
||||||
:icaos ["123" "456"]})))))
|
|
||||||
|
|
||||||
|
|
||||||
(deftest adsbx-url
|
(deftest adsbx-url
|
||||||
|
Loading…
Reference in New Issue
Block a user