Skip to content

Commit

Permalink
Support header extractions
Browse files Browse the repository at this point in the history
  • Loading branch information
Julio Rincon committed Apr 22, 2020
1 parent 3465ee2 commit cdd2cc5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
5 changes: 3 additions & 2 deletions example/sample-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ Fake API:
{id:"#\\d+"}
headers:
Content-Type: application/json; charset=utf-8
extract:
postId: $.id
extract:
postId: $.id
respType: header.Content-Type
Retrieve Post:
get: $fakeServer$/posts/$postId$
headers:
Expand Down
1 change: 1 addition & 0 deletions src/rester/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
(let [result (cond
(.startsWith path "$") (piped-json-path path body)
(.startsWith path "#") (re-find (re-pattern path) body)
(.startsWith path "header.") (headers (str/replace-first path "header." ""))
true (piped-json-path (str "$." path) resp))]
(log/info "extracted:" name "=" result)
[name result])
Expand Down
4 changes: 3 additions & 1 deletion test/rester/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@

(deftest test-extract-data
(testing "simple json path"
(is (= {"id" 100} (extract-data {:body {:id 100 "name" "blah"}} {"id" "$.id"})))))
(is (= {"id" 100} (extract-data {:body {:id 100 "name" "blah"}} {"id" "$.id"}))))
(testing "extract headers"
(is (= {"x" "1234"} (extract-data {:body {} :headers {"header 123" "1234"}} {"x" "header.header 123"})))))

(deftest test-ordered-iterator
(testing "test ordered iterator"
Expand Down

0 comments on commit cdd2cc5

Please sign in to comment.