-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7868477
commit 71b6c43
Showing
5 changed files
with
153 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,13 @@ | ||
(ns clj-wiremock-extras.core | ||
(:require | ||
[potemkin.namespaces :refer [import-vars]])) | ||
[potemkin.namespaces :refer [import-fn]] | ||
[clj-wiremock-extras.times :as times] | ||
[clj-wiremock-extras.near-misses :as near-misses] | ||
[clj-wiremock-extras.filters :as filters])) | ||
|
||
(import-vars | ||
[clj-wiremock-extras.times first-call second-call]) | ||
(import-fn times/first-call) | ||
(import-fn times/second-call) | ||
(import-fn near-misses/near-misses) | ||
(import-fn filters/requests-by-method) | ||
(import-fn filters/requests-by-url) | ||
(import-fn filters/filter-request-journal) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
(ns clj-wiremock-extras.filters | ||
(:require [clj-wiremock.core :as wmk] | ||
[clojure.string :as str])) | ||
|
||
(defn filter-request-journal | ||
[predicates server] | ||
(let [server (or server (wmk/root-server))] | ||
(->> (wmk/request-journal server) | ||
(filter (apply every-pred predicates)) | ||
(mapv :request)))) | ||
|
||
(defn requests-by-method | ||
[method & server] | ||
(filter-request-journal | ||
[(fn | ||
[{:keys [request]}] | ||
(= (str/upper-case (name method)) (:method request)))] | ||
server)) | ||
|
||
(defn requests-by-url | ||
[url & server] | ||
(filter-request-journal | ||
[(fn | ||
[{:keys [request]}] | ||
(= url (:url request)))] | ||
server)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,21 @@ | ||
(ns clj-wiremock-extras.core-test | ||
(:require | ||
[clj-wiremock-extras.filters :as filters] | ||
[clj-wiremock-extras.near-misses :as near-misses] | ||
[clojure.test :refer [deftest is testing]] | ||
[clj-wiremock-extras.core :refer [first-call second-call]])) | ||
[clj-wiremock-extras.core :refer [first-call second-call near-misses | ||
requests-by-method requests-by-url filter-request-journal]] | ||
[clj-wiremock-extras.times :as times] | ||
[clojure.repl :refer [doc]])) | ||
|
||
(defmacro out= [& args] | ||
`(= ~@(map (fn [x] `(with-out-str ~x)) args))) | ||
|
||
(deftest has-expected-core-functions | ||
(testing "has imported the various utilities from the other namespaces" | ||
(let [empty-stub {} | ||
first-call-stub (first-call empty-stub) | ||
second-call-stub (second-call empty-stub)] | ||
(is (not= empty-stub first-call-stub second-call-stub))))) | ||
(is (out= (doc times/first-call) (doc first-call))) | ||
(is (out= (doc times/second-call) (doc second-call))) | ||
(is (out= (doc near-misses/near-misses) (doc near-misses))) | ||
(is (out= (doc filters/requests-by-method) (doc requests-by-method))) | ||
(is (out= (doc filters/requests-by-url) (doc requests-by-url))) | ||
(is (out= (doc filters/filter-request-journal) (doc filter-request-journal))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
(ns clj-wiremock-extras.filters-test | ||
(:require | ||
[clj-wiremock-extras.filters :as filters] | ||
[clj-wiremock.core :as wmk] | ||
[freeport.core :refer [get-free-port!]] | ||
[clojure.test :refer [deftest is testing use-fixtures]] | ||
[clj-http.client :as http])) | ||
|
||
(def wiremock-port (get-free-port!)) | ||
(def wiremock-url (str "http://localhost:" wiremock-port)) | ||
|
||
(use-fixtures :once | ||
(partial wmk/wiremock-fixture [{:port wiremock-port}])) | ||
|
||
(deftest filter-by-method | ||
(testing "filters requests made by the method or url given" | ||
(let [get-stub {:req [:GET "/foo"] | ||
:res [200 {:body "OK"}]} | ||
post-stub {:req [:POST "/bar"] | ||
:res [200 {:body "OK"}]} | ||
delete-stub {:req [:DELETE "/foo"] | ||
:res [200 {:body "OK"}]}] | ||
(wmk/with-stubs [get-stub post-stub delete-stub] | ||
(http/get (str wiremock-url "/foo")) | ||
(http/post (str wiremock-url "/bar")) | ||
(http/delete (str wiremock-url "/foo")) | ||
|
||
(is (= (count (filters/requests-by-method :get)) 1)) | ||
(is (= (count (filters/requests-by-method :post)) 1)) | ||
(is (= (count (filters/requests-by-method :delete)) 1)) | ||
(is (= (count (filters/requests-by-url "/foo")) 2)) | ||
(is (= (count (filters/requests-by-url "/bar")) 1)))))) |