diff --git a/cmd/com/eldrix/hermes/cmd/cli.clj b/cmd/com/eldrix/hermes/cmd/cli.clj index 3ed8648f..db2658ee 100644 --- a/cmd/com/eldrix/hermes/cmd/cli.clj +++ b/cmd/com/eldrix/hermes/cmd/cli.clj @@ -171,7 +171,7 @@ (if (str/blank? (:allowed-origins options)) parsed (-> parsed - (update :options disj :allowed-origins) + (update :options dissoc :allowed-origins) (update-in [:options :allowed-origin] #(apply conj % (str/split (:allowed-origins options) #",")))))) (defn parse-cli diff --git a/test/com/eldrix/hermes/cmd_test.clj b/test/com/eldrix/hermes/cmd_test.clj index 58426eb2..6ecbb9bf 100644 --- a/test/com/eldrix/hermes/cmd_test.clj +++ b/test/com/eldrix/hermes/cmd_test.clj @@ -57,30 +57,39 @@ (is (= cmd "index")) (is (= (:db options) "snomed.db")) (is (= (:locale options) "en-GB,en-US")))} - {:s "Test status with missing database" + {:s "Test status with missing database" :args ["status"] :test (fn [{:keys [errors]}] (is (seq errors)))} - {:s "Test status " + {:s "Test status " :args ["status" "--db" "snomed.db"] :test (fn [{:keys [cmd options errors]}] (is (nil? errors)) (is (= cmd "status")) (is (= (:db options) "snomed.db")))} - {:s "Run a server" + {:s "Run a server" :args (str/split "--db snomed.db --port 8090 serve" #" ") :test (fn [{:keys [cmd options errors]}] (is (nil? errors)) (is (= "serve" cmd)) (is (= (:db options) "snomed.db")) - (is (= (:port options) 8090)))}]) + (is (= (:port options) 8090)))} + {:s "Avoid extraneous options being included" + :args ["serve"] + :test (fn [{:keys [options]}] + (is (not (contains? options :dist)) "parse-cli mistakenly included :dist options key when not provided"))}]) (deftest test-parse-cli-options (doseq [{:keys [s args test]} cli-tests] (testing s (test (cli/parse-cli args))))) - +(deftest test-allowed-origins + (is (= (cli/parse-cli ["serve" "--db=snomed.db" "--allowed-origins" "example.com,example.net"]) + (cli/parse-cli ["serve" "--db=snomed.db" "--allowed-origin" "example.com" "--allowed-origin" "example.net"]) + (cli/parse-cli ["serve" "--db=snomed.db" "--allowed-origins=example.com,example.net"]) + (cli/parse-cli ["serve" "--db=snomed.db" "--allowed-origin=example.com" "--allowed-origin=example.net"])) + "--allowed-origin and --allowed-origins are not parsed to be be equivalent")) (comment (cli/parse-cli ["download" "uk.nhs/sct-clinical" "api-key" "api-key.txt" "cache-dir" "/var/tmp"])) \ No newline at end of file