Skip to content

Commit 6c128fd

Browse files
authored
Run entire test suite under Babashka (#58)
We were formerly running a small sanity test for babashka. By separating out our test http server to a process, we can now hit our full suite with babashka. We've kept our bb sanity tests but moved them under our full suite. (see client-sanity-test ns). Bb task `test:bb` now runs the full suite. For consistency, I've re-added `test:jvm` which behaves the same as `test:bb` but also supports a `--clj-version` option. CI has been updated to use/exercise the test:jvm task. Also added a simple test reporter for better feedback when testing and to make it abundantly clear which platform we are testing on. See update README for usage. Some tests initially failed under bb: - Tests were checking specifically for thrown `java.net.ssl.SSLException` and `java.net.SocketTimeoutException`. Neither of these classes are currently available in bb. I switched to checking the message only. - Encoding tests were testing against "windows-1252" charset. Bb does include this charset, but on Windows only. I switched the test to use "iso-8859-1" which is available on bb on all platforms. Other notes: - noticed that the timeout test sometimes very rarely did not timeout; I increased the server-side timeout to hopefully force the expected failure. - GitHub Actions on Windows can be very slow. Bumped wait time for our http-server process startup to a very generous 2 mins and added some logging so that we can witness how long this typically takes. Closes #48
1 parent 392e700 commit 6c128fd

14 files changed

+295
-123
lines changed

.github/workflows/ci.yml

+5-8
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
- name: Lint
4444
run: bb lint
4545

46-
test:
46+
test-jvm:
4747
runs-on: ${{ matrix.os }}-latest
4848
strategy:
4949
fail-fast: false
@@ -78,24 +78,21 @@ jobs:
7878
uses: DeLaGuardo/setup-clojure@9.4
7979
with:
8080
bb: 'latest'
81-
cli: 'latest'
8281

8382
- name: Tools versions
8483
run: |
8584
echo "bb --version"
8685
bb --version
87-
echo "clojure --version"
88-
clojure --version
8986
echo "java -version"
9087
java -version
9188
9289
- name: Bring down deps
9390
run: bb deps
9491

9592
- name: Run tests
96-
run: clojure -M:${{ matrix.clojure-version }}:test
93+
run: bb test:jvm --clj-version ${{ matrix.clojure-version }}
9794

98-
bb-test:
95+
test-bb:
9996
runs-on: ${{ matrix.os }}-latest
10097
strategy:
10198
fail-fast: false
@@ -143,8 +140,8 @@ jobs:
143140
runs-on: ubuntu-latest
144141
needs:
145142
- lint
146-
- test
147-
- bb-test
143+
- test-jvm
144+
- test-bb
148145

149146
steps:
150147
- name: Checkout

README.md

+20-7
Original file line numberDiff line numberDiff line change
@@ -315,26 +315,39 @@ are sugar over this `clj-http.lite.client/request` function.
315315

316316
### Clojure JVM Tests
317317

318-
To run tests for the JVM:
319-
318+
Optionally:
320319
```shell
321320
$ bb clean
322321
$ bb deps
322+
```
323+
324+
Run all Clojure tests against minimum supported version of Clojure (1.8):
323325

324-
Run all Clojure tests against minimum supported version of Clojure (1.8)
325-
$ clojure -M:test
326+
```shell
327+
$ bb test:jvm
328+
```
326329

327-
Run Clojure against a specific Clojure version, for example 1.11
328-
$ clojure -M:1.11:test
330+
Run tests against a specific Clojure version, for example 1.11
331+
```shell
332+
$ bb test:jvm --clj-version 1.11
333+
```
334+
335+
You can also include cognitect test runner options:
336+
```shell
337+
$ bb test:jvm --clj-version 1.9 --namespace-regex '*.sanity.*'
329338
```
330339

331340
### Babashka Tests
332341

333-
To run a small suite of sanity tests for babashka (found under ./bb]):
342+
To run the entire test suite under Babashka:
334343

335344
```shell
336345
$ bb test:bb
337346
```
347+
You can also include cognitect test runner options:
348+
```shell
349+
$ bb test:bb --var clj-http.lite.integration-test/roundtrip
350+
```
338351

339352
### Linting
340353

bb.edn

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{:paths ["." "bb"]
2-
:deps {org.clj-commons/clj-http-lite {:local/root "."}
3-
lread/status-line {:git/url "https://github.com/lread/status-line.git"
2+
:deps {lread/status-line {:git/url "https://github.com/lread/status-line.git"
43
:sha "35ed39645038e81b42cb15ed6753b8462e60a06d"}}
54
:tasks
65
{:requires ([tasks :as t])
@@ -10,9 +9,18 @@
109
clean
1110
{:doc "Delete any work dirs"
1211
:task (clojure "-T:build clean")}
12+
test:jvm
13+
{:doc "Runs tests under JVM Clojure [--clj-version] (recognizes cognitect test-runner args)"
14+
:task test-jvm/-main}
1315
test:bb
14-
{:doc "Run babashka tests"
15-
:task clj-http.lite.test-runner/-main}
16+
{:doc "Runs tests under babashka Clojure (recognizes cognitect test-runner args)"
17+
:extra-paths ["src" "test" "test-resources"]
18+
:extra-deps {io.github.cognitect-labs/test-runner
19+
{:git/tag "v0.5.1" :git/sha "dfb30dd"}
20+
org.clojure/tools.namespace {:git/url "https://github.com/babashka/tools.namespace"
21+
:git/sha "16b8c53174a5c9d89d6e0ce4128aa30b071aabdf"}}
22+
:requires ([cognitect.test-runner :as tr])
23+
:task (apply tr/-main *command-line-args*)}
1624
lint
1725
{:doc "[--rebuild] Lint source code"
1826
:task lint/-main}

bb/clj_http/lite/test_runner.clj

-10
This file was deleted.

bb/test_jvm.clj

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
(ns test-jvm
2+
(:require [babashka.cli :as cli]
3+
[babashka.tasks :as t]
4+
[lread.status-line :as status]))
5+
6+
(defn -main [& args]
7+
(let [valid-clojure-versions ["1.8" "1.9" "1.10" "1.11"]
8+
spec {:clj-version
9+
{:ref "<version>"
10+
:desc "The Clojure version to test against."
11+
:coerce :string
12+
:default-desc "1.8"
13+
;; don't specify :default, we want to know if the user passed this option in
14+
:validate
15+
{:pred (set valid-clojure-versions)
16+
:ex-msg (fn [_m]
17+
(str "--clj-version must be one of: " valid-clojure-versions))}}}
18+
opts (cli/parse-opts args {:spec spec})
19+
clj-version (:clj-version opts)
20+
runner-args (if-not clj-version
21+
args
22+
(loop [args args
23+
out-args []]
24+
(if-let [a (first args)]
25+
(if (re-matches #"(--|:)clj-version" a)
26+
(recur (drop 2 args) out-args)
27+
(recur (rest args) (conj out-args a)))
28+
out-args)))
29+
clj-version (or clj-version "1.8")]
30+
31+
(if (:help opts)
32+
(do
33+
(status/line :head "bb task option help")
34+
(println (cli/format-opts {:spec spec}))
35+
(status/line :head "test-runner option help")
36+
(t/clojure "-M:test --test-help"))
37+
(do
38+
(println "Testing against Clojure" clj-version)
39+
(apply t/clojure (format "-M:%s:test" clj-version) runner-args)))))
40+
41+
(when (= *file* (System/getProperty "babashka.file"))
42+
(apply -main *command-line-args*))

deps.edn

+8-3
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,21 @@
99
{:deps {io.github.clojure/tools.build {:git/tag "v0.8.3" :git/sha "0d20256"}
1010
slipset/deps-deploy {:mvn/version "0.2.0"}}
1111
:ns-default build}
12-
:test
12+
:http-server ;; used for to support integration tests
1313
{:extra-paths ["test" "test-resources"]
14-
:extra-deps {io.github.cognitect-labs/test-runner
15-
{:git/tag "v0.5.1" :git/sha "dfb30dd"}
14+
:override-deps {org.clojure/clojure {:mvn/version "1.11.1"}}
15+
:extra-deps {babashka/fs {:mvn/version "0.1.6"}
1616
ring/ring-jetty-adapter {:mvn/version "1.9.5"}
1717
ch.qos.logback/logback-classic {:mvn/version "1.2.11"
1818
:exclusions [org.slf4j/slf4j-api]}
1919
org.slf4j/jcl-over-slf4j {:mvn/version "1.7.36"}
2020
org.slf4j/jul-to-slf4j {:mvn/version "1.7.36"}
2121
org.slf4j/log4j-over-slf4j {:mvn/version "1.7.36"}}
22+
:exec-fn clj-http.lite.test-util.http-server/run}
23+
:test
24+
{:extra-paths ["test"]
25+
:extra-deps {io.github.cognitect-labs/test-runner
26+
{:git/tag "v0.5.1" :git/sha "dfb30dd"}}
2227
:main-opts ["-m" "cognitect.test-runner"]}
2328
;; for consistent linting we use a specific version of clj-kondo through the jvm
2429
:clj-kondo {:extra-deps {clj-kondo/clj-kondo {:mvn/version "2022.08.03"}}

bb/clj_http/lite/client_test.clj renamed to test/clj_http/lite/client_sanity_test.clj

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
(ns clj-http.lite.client-test
2-
(:require [cheshire.core :as json]
3-
[clj-http.lite.client :as client]
1+
(ns clj-http.lite.client-sanity-test
2+
"A small subset of tests suitable for sanity testing.
3+
Used by babashka libs tests."
4+
(:require [clj-http.lite.client :as client]
45
[clojure.test :as t :refer [deftest is]]))
56

67
(deftest client-test
@@ -11,14 +12,14 @@
1112
(is (= 200 (:status (client/post "https://postman-echo.com/post" {:throw-exceptions false}))))
1213

1314
(is (= 200 (:status (client/post "https://postman-echo.com/post"
14-
{:body (json/generate-string {:a 1})
15+
{:body "{\"a\": 1}"
1516
:headers {"X-Hasura-Role" "admin"}
1617
:content-type :json
1718
:accept :json
1819
:throw-exceptions false}))))
1920

2021
(is (= 200 (:status (client/put "https://postman-echo.com/put"
21-
{:body (json/generate-string {:a 1})
22+
{:body "{\"a\": 1}"
2223
:headers {"X-Hasura-Role" "admin"}
2324
:content-type :json
2425
:accept :json

test/clj_http/lite/client_test.clj

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
(ns clj-http.lite.client-test
22
(:require [clj-http.lite.client :as client]
33
[clj-http.lite.util :as util]
4+
[clj-http.lite.test-util.test-report]
45
[clojure.test :refer [deftest is testing]])
56
(:import (java.net UnknownHostException)))
67

@@ -132,8 +133,8 @@
132133
(is (= "fooⓕⓞⓞ" (:body resp)))))
133134

134135
(deftest apply-on-other-output-coercion
135-
(let [client (fn [_req] {:body (.getBytes "sõme ßÒññÝ chÀråcters" "windows-1252")
136-
:headers {"content-type" "text/foo;charset=windows-1252"}})
136+
(let [client (fn [_req] {:body (.getBytes "sõme ßÒññÝ chÀråcters" "ISO-8859-1")
137+
:headers {"content-type" "text/foo;charset=ISO-8859-1"}})
137138
o-client (client/wrap-output-coercion client)
138139
resp (o-client {:uri "/foo" :as :auto})]
139140
(is (= "sõme ßÒññÝ chÀråcters" (:body resp)))))
@@ -153,7 +154,7 @@
153154
(doseq [[in-body encoding expected-encoding] [["μτƒ8 нαs мαηλ ςнαяαςτεяs ൠ" nil "UTF-8"]
154155
["μτƒ8 нαs мαηλ ςнαяαςτεяs ൠ" "UTF-8" "UTF-8"]
155156
["plain text" "ASCII" "ASCII"]
156-
["sõme ßÒññÝ chÀråcters" "windows-1252" "windows-1252"]]]
157+
["sõme ßÒññÝ chÀråcters" "iso-8859-1" "iso-8859-1"]]]
157158
(let [resp (i-client {:body in-body :body-encoding encoding})
158159
decoded-body (slurp (:body resp) :encoding expected-encoding)]
159160
(is (= expected-encoding (:character-encoding resp)) "character encoding")

0 commit comments

Comments
 (0)