Skip to content

Commit b5ca4d1

Browse files
authored
Merge pull request #583 from bevuta/fix-linter-warnings-and-errors-in-tests
Fix all linter warnings and errors in test suite
2 parents d3dc025 + 6644c88 commit b5ca4d1

14 files changed

+148
-161
lines changed

.clj-kondo/config.edn

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
{:config-paths ["../resources/clj-kondo.exports/clj-commons/aleph"]}
1+
{:config-paths ["../resources/clj-kondo.exports/clj-commons/aleph"]
2+
:linters {:unsorted-required-namespaces {:level :warning}}
3+
:lint-as {dynamic-redef.core/with-dynamic-redefs clojure.core/with-redefs
4+
manifold.deferred/let-flow clojure.core/let
5+
manifold.deferred/loop clojure.core/let}}

test/aleph/classloader_test.clj

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
(ns aleph.classloader-test
2-
(:require [clojure.test :refer [deftest testing is]]
3-
[aleph.http :as http]
4-
[aleph.netty :as netty]
5-
[manifold.deferred :as d]
6-
[manifold.utils :refer [when-class]]
7-
[signal.handler :refer [on-signal]]
8-
[dynamic-redef.core :refer [with-dynamic-redefs]])
9-
(:import [io.netty.util.concurrent Future]
10-
[java.lang.management ManagementFactory]
11-
[java.util.concurrent CompletableFuture]))
2+
(:require
3+
[aleph.http :as http]
4+
[aleph.netty :as netty]
5+
[clojure.test :refer [deftest is testing]]
6+
[dynamic-redef.core :refer [with-dynamic-redefs]]
7+
[manifold.deferred :as d]
8+
[manifold.utils :refer [when-class]]
9+
[signal.handler :refer [on-signal]])
10+
(:import
11+
(io.netty.util.concurrent Future)
12+
(java.lang.management ManagementFactory)
13+
(java.util.concurrent CompletableFuture)))
1214

1315
(defn- operation-complete
1416
"Stubs for `GenericFutureListener/operationComplete` which

test/aleph/http/client_middleware_test.clj

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
(ns aleph.http.client-middleware-test
2-
(:require [aleph.http.client-middleware :as middleware]
3-
[clojure.test :as t :refer [deftest is]])
4-
(:import java.net.URLDecoder))
2+
(:require
3+
[aleph.http.client-middleware :as middleware]
4+
[clojure.test :as t :refer [deftest is]])
5+
(:import
6+
(java.net URLDecoder)))
57

68
(deftest test-empty-query-string
79
(is (= "" (middleware/generate-query-string {})))

test/aleph/http/client_test.clj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
(ns aleph.http.client-test
2-
(:require [aleph.http.client :as client]
3-
[clojure.test :as t :refer [deftest is testing]]))
2+
(:require
3+
[aleph.http.client :as client]
4+
[clojure.test :as t :refer [deftest is testing]]))
45

56
(deftest test-domain-extracting
67
(testing "ASCII domain is extracted from URL as is."

test/aleph/http/core_test.clj

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
(ns aleph.http.core-test
2-
(:use
3-
[clojure test])
42
(:require
5-
[aleph.http.core :as core])
3+
[aleph.http.core :as core]
4+
[clojure.test :refer [deftest is]])
65
(:import
7-
[io.netty.handler.codec.http
8-
DefaultHttpRequest]))
6+
(io.netty.handler.codec.http DefaultHttpRequest)))
97

108
(deftest test-HeaderMap-keys
119
(let [^DefaultHttpRequest req (core/ring-request->netty-request

test/aleph/http/multipart_test.clj

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
(ns aleph.http.multipart-test
22
(:require
3-
[aleph.http :as http]
4-
[aleph.http.core :as core]
5-
[aleph.http.multipart :as mp]
6-
[clj-commons.byte-streams :as bs]
7-
[clojure.edn :as edn]
8-
[clojure.test :refer [deftest testing is]]
9-
[manifold.deferred :as d]
10-
[manifold.stream :as s]
11-
[clojure.string :as str])
3+
[aleph.http :as http]
4+
[aleph.http.core :as core]
5+
[aleph.http.multipart :as mp]
6+
[clj-commons.byte-streams :as bs]
7+
[clojure.edn :as edn]
8+
[clojure.string :as str]
9+
[clojure.test :refer [deftest is testing]]
10+
[manifold.deferred :as d]
11+
[manifold.stream :as s])
1212
(:import
13-
(io.netty.buffer
14-
ByteBufAllocator)
15-
(io.netty.handler.codec.http
16-
HttpContent)
17-
(io.netty.handler.stream
18-
ChunkedInput)
19-
(java.io
20-
File)))
13+
(io.netty.buffer ByteBufAllocator)
14+
(io.netty.handler.codec.http HttpContent)
15+
(io.netty.handler.stream ChunkedInput)
16+
(java.io File)))
2117

2218
(def file-to-send (File. (str (System/getProperty "user.dir") "/test/file.txt")))
2319

20+
#_{:clj-kondo/ignore [:deprecated-var]}
2421
(deftest test-multipart-builder
2522
(let [body (mp/encode-body [{:part-name "part1"
2623
:content "content1"
@@ -58,12 +55,14 @@
5855
;; filename header
5956
(is (.contains body-str "filename=\"content5.pdf\""))))
6057

58+
#_{:clj-kondo/ignore [:deprecated-var]}
6159
(deftest test-custom-boundary
6260
(let [b (mp/boundary)
6361
body (mp/encode-body b [{:part-name "part1" :content "content1"}])
6462
body-str (bs/to-string body)]
6563
(is (.endsWith body-str (str b "--")))))
6664

65+
#_{:clj-kondo/ignore [:deprecated-var]}
6766
(deftest test-base64-content-transfer-encoding
6867
(let [body (mp/encode-body [{:part-name "part1"
6968
:content "content1"
@@ -72,6 +71,7 @@
7271
(is (.contains body-str "base64"))
7372
(is (.contains body-str "Y29udGVudDE="))))
7473

74+
#_{:clj-kondo/ignore [:deprecated-var]}
7575
(deftest test-binary-content-transfer-encoding
7676
(testing "specify 'binary' in headers"
7777
(let [body (mp/encode-body [{:part-name "part1"
@@ -88,12 +88,14 @@
8888
(is (.contains body-str "content2"))
8989
(is (false? (.contains body-str "Content-Transfer-Encoding"))))))
9090

91+
#_{:clj-kondo/ignore [:deprecated-var]}
9192
(deftest reject-unknown-transfer-encoding
9293
(is (thrown? IllegalArgumentException
9394
(mp/encode-body [{:part-name "part1"
9495
:content "content1"
9596
:transfer-encoding :uknown-transfer-encoding}]))))
9697

98+
#_{:clj-kondo/ignore [:deprecated-var]}
9799
(deftest test-content-as-file
98100
(let [parts [{:part-name "part1"
99101
:content file-to-send}

test/aleph/http_continue_test.clj

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
(ns aleph.http-continue-test
2-
(:use [clojure test])
3-
(:require [aleph
4-
[http :as http]
5-
[netty :as netty]
6-
[flow :as flow]
7-
[tcp :as tcp]]
8-
[clj-commons.byte-streams :as bs]
9-
[manifold.deferred :as d]
10-
[manifold.stream :as s]
11-
[clojure.string :as str])
12-
(:import [java.util.concurrent ExecutorService]))
2+
(:require
3+
[aleph.flow :as flow]
4+
[aleph.http :as http]
5+
[aleph.netty :as netty]
6+
[aleph.tcp :as tcp]
7+
[clj-commons.byte-streams :as bs]
8+
[clojure.string :as str]
9+
[clojure.test :refer [deftest is testing]]
10+
[manifold.deferred :as d]
11+
[manifold.stream :as s]))
1312

1413
(defmacro with-server [server & body]
1514
`(let [server# ~server]

test/aleph/http_test.clj

Lines changed: 47 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,24 @@
11
(ns aleph.http-test
22
(:require
3-
[clojure.java.io :as io]
4-
[clojure.string :as str]
5-
[clojure.test :refer [deftest testing is]]
6-
[aleph
7-
[http :as http]
8-
[netty :as netty]
9-
[flow :as flow]
10-
[ssl :as ssl]
11-
[tcp :as tcp]]
12-
[clj-commons.byte-streams :as bs]
13-
[manifold.deferred :as d]
14-
[manifold.stream :as s]
15-
[manifold.time :as t])
3+
[aleph.flow :as flow]
4+
[aleph.http :as http]
5+
[aleph.netty :as netty]
6+
[aleph.ssl :as ssl]
7+
[aleph.tcp :as tcp]
8+
[clj-commons.byte-streams :as bs]
9+
[clojure.java.io :as io]
10+
[clojure.string :as str]
11+
[clojure.test :refer [deftest is testing]]
12+
[manifold.deferred :as d]
13+
[manifold.stream :as s]
14+
[manifold.time :as t])
1615
(:import
17-
(java.io
18-
File)
19-
(java.util.zip
20-
GZIPInputStream
21-
ZipException)
22-
(java.util.concurrent
23-
TimeoutException)
24-
(aleph.utils
25-
ConnectionTimeoutException
26-
RequestTimeoutException)
27-
(io.netty.channel
28-
ChannelHandlerContext
29-
ChannelOutboundHandlerAdapter
30-
ChannelPipeline
31-
ChannelPromise)
32-
(io.netty.handler.codec.http
33-
HttpMessage)))
16+
(aleph.utils ConnectionTimeoutException RequestTimeoutException)
17+
(io.netty.channel ChannelHandlerContext ChannelOutboundHandlerAdapter ChannelPipeline ChannelPromise)
18+
(io.netty.handler.codec.http HttpMessage)
19+
(java.io File)
20+
(java.util.concurrent TimeoutException)
21+
(java.util.zip GZIPInputStream ZipException)))
3422

3523
;;;
3624

@@ -69,35 +57,35 @@
6957
(def http-file-region-response (http/file filepath 5 4))
7058
(def stream-response "Stream!")
7159

72-
(defn string-handler [request]
60+
(defn string-handler [_request]
7361
{:status 200
7462
:body string-response})
7563

76-
(defn seq-handler [request]
64+
(defn seq-handler [_request]
7765
{:status 200
7866
:body seq-response})
7967

80-
(defn file-handler [request]
68+
(defn file-handler [_request]
8169
{:status 200
8270
:body file-response})
8371

84-
(defn http-file-handler [request]
72+
(defn http-file-handler [_request]
8573
{:status 200
8674
:body http-file-response})
8775

88-
(defn http-file-region-handler [request]
76+
(defn http-file-region-handler [_request]
8977
{:status 200
9078
:body http-file-region-response})
9179

92-
(defn stream-handler [request]
80+
(defn stream-handler [_request]
9381
{:status 200
9482
:body (bs/to-input-stream stream-response)})
9583

96-
(defn slow-handler [request]
84+
(defn slow-handler [_request]
9785
{:status 200
9886
:body (cons "1" (lazy-seq (do (Thread/sleep 500) '("2"))))})
9987

100-
(defn manifold-handler [request]
88+
(defn manifold-handler [_request]
10189
{:status 200
10290
:body (->> stream-response (map str) s/->source)})
10391

@@ -109,14 +97,14 @@
10997
{:status 200
11098
:body (->> request :body bs/to-line-seq)})
11199

112-
(defn hello-handler [request]
100+
(defn hello-handler [_request]
113101
{:status 200
114102
:body "hello"})
115103

116-
(defn big-handler [request]
104+
(defn big-handler [_request]
117105
{:status 200
118106
:body (->> (s/periodically 0.1 #(byte-array 1024))
119-
(s/transform (take 1e3)))})
107+
(s/transform (take (long 1e3))))})
120108

121109
(defn redirect-handler [{:keys [query-string] :as request}]
122110
(let [count (-> (.split #"[?=]" query-string) second Integer/parseInt)
@@ -152,7 +140,7 @@
152140
(try
153141
(deliver latch true) ;;this can be triggered more than once, sometimes
154142
(.close ^java.io.Closeable @browser-server)
155-
(catch Exception e)))})
143+
(catch Exception _)))})
156144

157145
(defn print-vals [& args]
158146
(apply prn args)
@@ -215,18 +203,17 @@
215203

216204
(deftest test-response-formats
217205
(with-handler basic-handler
218-
(doseq [[index [path result]] (map-indexed vector expected-results)]
219-
(is
220-
(= result
221-
(bs/to-string
222-
(:body
223-
@(http-get (str "http://localhost:" port "/" path)))))))))
206+
(doseq [[path result] expected-results]
207+
(is (= result
208+
(bs/to-string
209+
(:body
210+
@(http-get (str "http://localhost:" port "/" path)))))))))
224211

225212
(deftest test-compressed-response
226213
(with-compressed-handler basic-handler
227-
(doseq [[index [path result]] (map-indexed vector expected-results)
214+
(doseq [[path result] expected-results
228215
:let [resp @(http-get (str "http://localhost:" port "/" path)
229-
{:headers {:accept-encoding "gzip"}})
216+
{:headers {:accept-encoding "gzip"}})
230217
unzipped (try
231218
(bs/to-string (GZIPInputStream. (:body resp)))
232219
(catch ZipException _ nil))]]
@@ -237,7 +224,7 @@
237224

238225
(deftest test-ssl-response-formats
239226
(with-handler-options basic-handler default-ssl-options
240-
(doseq [[index [path result]] (map-indexed vector expected-results)]
227+
(doseq [[path result] expected-results]
241228
(is
242229
(= result
243230
(bs/to-string
@@ -297,13 +284,13 @@
297284
deref))))
298285

299286
(deftest test-overly-long-url
300-
(let [long-url (apply str "http://localhost:" port "/" (repeat 1e4 "a"))]
287+
(let [long-url (apply str "http://localhost:" port "/" (repeat (long 1e4) "a"))]
301288
(with-handler basic-handler
302289
(is (= 414 (:status @(http-get long-url)))))))
303290

304291
(deftest test-overly-long-header
305292
(let [url (str "http://localhost:" port)
306-
long-header-value (apply str (repeat 1e5 "a"))
293+
long-header-value (apply str (repeat (long 1e5) "a"))
307294
opts {:headers {"X-Long" long-header-value}}]
308295
(with-handler basic-handler
309296
(is (= 431 (:status @(http-get url opts)))))))
@@ -436,10 +423,6 @@
436423
(let [rsp (http/get (str "http://localhost:" port) {:connection-pool pool})]
437424
(is (= http/default-response-executor (.executor rsp))))))))
438425

439-
(defn echo-handler [req]
440-
{:status 200
441-
:body (:body req)})
442-
443426
(deftest test-trace-request-omitted-body
444427
(with-handler echo-handler
445428
(is (= "" (-> @(http/trace (str "http://localhost:" port) {:body "REQUEST"})
@@ -496,7 +479,7 @@
496479
[]
497480
(let [body (s/stream 10)]
498481
(-> (d/loop [cnt 0]
499-
(t/in 50
482+
(t/in 50.0
500483
(fn []
501484
(d/chain' (s/put! body (str cnt))
502485
(fn [_]
@@ -533,14 +516,13 @@
533516

534517
(deftest test-large-responses
535518
(with-handler basic-handler
536-
(let [pool (http/connection-pool {:connection-options {:response-buffer-size 16}})]
537-
(dotimes [i 1 #_1e6]
538-
#_(when (zero? (rem i 1e2))
539-
(prn i))
540-
(-> @(http/get (str "http://localhost:" port "/big")
541-
{:as :byte-array})
519+
(dotimes [_ 1 #_1e6]
520+
#_(when (zero? (rem i 1e2))
521+
(prn i))
522+
(-> @(http/get (str "http://localhost:" port "/big")
523+
{:as :byte-array})
542524
:body
543-
count)))))
525+
count))))
544526

545527
;;;
546528

0 commit comments

Comments
 (0)