Skip to content

Commit 6dda820

Browse files
committed
maint: update sanity test to use httpbingo.org
Postman-echo was giving us 403s on CI. Let's instead try httpbingo.org with some extra sanity checks with the help of cheshire and nubank's matcher-combinators.
1 parent b08fbe0 commit 6dda820

File tree

4 files changed

+48
-19
lines changed

4 files changed

+48
-19
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{:linters
2+
{:unresolved-symbol
3+
{:exclude [(cljs.test/is [match? thrown-match?])
4+
(clojure.test/is [match? thrown-match?])]}}}

bb.edn

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
{:doc "Runs tests under babashka Clojure (recognizes cognitect test-runner args)"
2929
:extra-paths ["src" "test" "test-resources"]
3030
:extra-deps {io.github.cognitect-labs/test-runner
31-
{:git/tag "v0.5.1" :git/sha "dfb30dd"}}
31+
{:git/tag "v0.5.1" :git/sha "dfb30dd"}
32+
nubank/matcher-combinators {:mvn/version "3.9.2"}}
3233
:requires ([cognitect.test-runner :as tr])
3334
:task (apply tr/-main *command-line-args*)}
3435
lint

deps.edn

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
:test
3030
{:extra-paths ["test"]
3131
:extra-deps {io.github.cognitect-labs/test-runner
32-
{:git/tag "v0.5.1" :git/sha "dfb30dd"}}
32+
{:git/tag "v0.5.1" :git/sha "dfb30dd"}
33+
cheshire/cheshire {:mvn/version "6.1.0"}
34+
nubank/matcher-combinators {:mvn/version "3.9.2"}}
3335
:main-opts ["-m" "cognitect.test-runner"]}
3436
;; for consistent linting we use a specific version of clj-kondo through the jvm
3537
:clj-kondo {:extra-deps {clj-kondo/clj-kondo {:mvn/version "2025.10.23"}}
Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,53 @@
11
(ns clj-http.lite.client-sanity-test
2-
"A small subset of tests suitable for sanity testing.
3-
Used by babashka libs tests."
2+
"A small subset of tests suitable for sanity testing."
43
(:require [clj-http.lite.client :as client]
4+
[cheshire.core :as json]
5+
[matcher-combinators.test]
6+
[matcher-combinators.matchers :as m]
57
[clojure.test :as t :refer [deftest is]]))
68

79
(deftest client-test
810
(is (= 200 (:status (client/get "https://www.clojure.org" {:throw-exceptions false}))))
911

10-
(is (= 200 (:status (client/get "https://postman-echo.com/get?foo1=bar1&foo2=bar2" {:throw-exceptions false}))))
12+
(is (match? {:status 200
13+
:body (m/via json/decode {"method" "GET"
14+
"args" {"foo1" ["bar1"]
15+
"foo2" ["bar2"]}})}
16+
(client/get "https://httpbingo.org/get?foo1=bar1&foo2=bar2" {:throw-exceptions false})))
1117

12-
(is (= 200 (:status (client/post "https://postman-echo.com/post" {:throw-exceptions false}))))
18+
(is (match? {:status 200
19+
:body (m/via json/decode {"method" "POST"
20+
"headers" {"Content-Type" m/absent}
21+
"args" {}
22+
"data" ""})}
23+
(client/post "https://httpbingo.org/post" {:throw-exceptions false})))
1324

14-
(is (= 200 (:status (client/post "https://postman-echo.com/post"
15-
{:body "{\"a\": 1}"
16-
:headers {"X-Hasura-Role" "admin"}
17-
:content-type :json
18-
:accept :json
19-
:throw-exceptions false}))))
25+
(is (match? {:status 200
26+
:body (m/via json/decode {"method" "POST"
27+
"headers" {"Content-Type" ["application/json; charset=UTF-8"]
28+
"X-Hasura-Role" ["admin"]}
29+
"data" "{\"a\": 1}"})}
30+
(client/post "https://httpbingo.org/post"
31+
{:body "{\"a\": 1}"
32+
:headers {"X-Hasura-Role" "admin"}
33+
:content-type :json
34+
:accept :json
35+
:throw-exceptions false})))
2036

21-
(is (= 200 (:status (client/put "https://postman-echo.com/put"
22-
{:body "{\"a\": 1}"
23-
:headers {"X-Hasura-Role" "admin"}
24-
:content-type :json
25-
:accept :json
26-
:throw-exceptions false})))))
37+
(is (match? {:status 200
38+
:body (m/via json/decode {"method" "PUT"
39+
"headers" {"Content-Type" ["application/json; charset=UTF-8"]
40+
"X-Hasura-Role" ["admin"]}
41+
"data" "{\"a\": 1}"})}
42+
(client/put "https://httpbingo.org/put"
43+
{:body "{\"a\": 1}"
44+
:headers {"X-Hasura-Role" "admin"}
45+
:content-type :json
46+
:accept :json
47+
:throw-exceptions false}))))
2748

2849
(deftest exception-test
29-
(try (client/get "https://httpbin.org/status/404")
50+
(try (client/get "https://httpbingo.org/status/404")
3051
(is false "should not reach here")
3152
(catch Exception e
3253
(is (:headers (ex-data e))))))
@@ -37,3 +58,4 @@
3758
(is (= 200 (:status (client/get "https://expired.badssl.com" {:insecure? true}))))
3859
(is (thrown? Exception
3960
(client/get "https://expired.badssl.com"))))
61+

0 commit comments

Comments
 (0)