Skip to content

Commit

Permalink
Additional test coverage (#57)
Browse files Browse the repository at this point in the history
One existing test contains several cases and attempted to use `map` to
run through the cases. Unfortunately, `map` is lazy so the cases were
never run. The fix uses `doseq` to walk through the cases.
  • Loading branch information
bruceadams authored Jul 4, 2016
1 parent 4651b0b commit 8746429
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 26 deletions.
10 changes: 5 additions & 5 deletions src/kale/retrieve_and_rank.clj
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@
(defn exception-response-msg
"Parse exception response message sent from R&R service"
[response]
(if-let [exception (response "exception")]
(exception "msg")))
(if-let [exception (response :exception)]
(exception :msg)))

(defn solr-error-msg
"Parse Solr error message sent from R&R service"
[response]
(if-let [exception (response "solrErrorMessage")]
(exception "message")))
(if-let [exception (response :solrErrorMessage)]
(exception :message)))

(defn process-json-exception
"Try to interpret the exception json returned by R&R"
[exception]
(try+
(let [decoded (json/decode exception)]
(let [decoded (json/decode exception true)]
(if-let [message (or (exception-response-msg decoded)
(solr-error-msg decoded))]
(fail message)
Expand Down
60 changes: 39 additions & 21 deletions test/kale/retrieve_and_rank_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,31 @@

(set-language :en)

(deftest process-json-exception-invalid-json
(is (thrown+-with-msg?
[:type :kale.common/fail]
#"This in invalid JSON"
(rnr/process-json-exception
"{ \"invalid\" : [ \"This in invalid JSON.\" "))))

(deftest process-json-exception-unknown-json
(is (thrown+-with-msg?
[:type :kale.common/fail]
#"Some vaguely human readable message"
(rnr/process-json-exception
"{\"unexpected\" : \"Some vaguely human readable message.\"}"))))

(deftest validate-solr-name-bad-chars
(map (fn [solr-name]
(is (thrown+-with-msg?
[:type :kale.common/fail]
#"Invalid object name"
(rnr/validate-solr-name solr-name))))
["my-obj#",
"my@obj",
"my%obj()",
"my obj"]))
(doseq [solr-name ["my-obj#"
"my@obj"
"my/obj"
"my%obj"
"my_obj()"
"my obj"]]
(is (thrown+-with-msg?
[:type :kale.common/fail]
#"Invalid object name"
(rnr/validate-solr-name solr-name)))))

(deftest validate-solr-name-ok
(is (= nil
Expand Down Expand Up @@ -211,13 +226,20 @@
(deftest upload-config-success
(with-fake-routes-in-isolation
{(rnr-url "/v1/solr_clusters/CLUSTER_ID/config/good-config")
(respond {:status 200
:body (json/encode (config-upload-success
(respond {:body (json/encode (config-upload-success
"good-config" "CLUSTER_ID"))})}
(is (= (config-upload-success "good-config" "CLUSTER_ID")
(rnr/upload-config endpoint "CLUSTER_ID" "good-config"
"file.zip")))))

(deftest download-config-success
(with-fake-routes-in-isolation
{(rnr-url "/v1/solr_clusters/CLUSTER_ID/config/good-config")
(respond {:headers {"Content-Type" "application/zip"}
:body "stub-response"})}
(is (= (map byte "stub-response")
(vec (rnr/download-config endpoint "CLUSTER_ID" "good-config"))))))

(defn config-delete-in-use
[config-name collection-name]
{:msg (str "WRRCSS006: Configuration ["
Expand Down Expand Up @@ -248,26 +270,22 @@
(deftest delete-config-success
(with-fake-routes-in-isolation
{(rnr-url "/v1/solr_clusters/CLUSTER_ID/config/some-config")
(respond {:status 200
:body (json/encode (config-delete-success
(respond {:body (json/encode (config-delete-success
"some-config" "CLUSTER_ID"))})}
(is (= (config-delete-success "some-config" "CLUSTER_ID")
(rnr/delete-config endpoint "CLUSTER_ID" "some-config")))))

(defn exception-response
[message]
{"responseHeader" {
"status" 400
"QTime" 100}
{:responseHeader {:status 400
:QTime 100}
"Operation create caused exception:" "org.apache.solr.common.SolrException"
"exception" {
"msg" message
"rspCode" 400}})
:exception {:msg message
:rspCode 400}})

(defn solr-error-response
[message]
{"solrErrorMessage" {
"message" message}})
{:solrErrorMessage {:message message}})

(defn existing-collection
[collection-name]
Expand Down

0 comments on commit 8746429

Please sign in to comment.