Skip to content

Commit 27dcf35

Browse files
committed
Improve http-kit integration / test coverage
See also: #288
1 parent 1399da2 commit 27dcf35

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed

project.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
:add-linters [:performance :boxed-math]
7676
:config-files ["eastwood.clj"]}}
7777
:clj-kondo [:test
78-
{:dependencies [[clj-kondo "2021.06.18"]]}]}
78+
{:dependencies [[clj-kondo "2021.09.15"]]}]}
7979

8080
:jvm-opts ~(cond-> []
8181
(System/getenv "CI")

src/refactor_nrepl/artifacts.clj

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
;; Ignore artifact if not readable. See #255
5252
nil)))
5353

54-
(defn get-clojars-artifacts!
54+
(defn- get-clojars-artifacts!
5555
"Returns a vector of [[some/lib \"0.1\"]...]."
5656
[]
5757
(try
@@ -68,18 +68,21 @@
6868
(defn- get-mvn-artifacts!
6969
"All the artifacts under org.clojure in mvn central"
7070
[group-id]
71-
(let [search-prefix "http://search.maven.org/solrsearch/select?q=g:%22"
71+
(let [search-prefix "https://search.maven.org/solrsearch/select?q=g:%22"
7272
search-suffix "%22+AND+p:%22jar%22&rows=2000&wt=json"
7373
search-url (str search-prefix group-id search-suffix)
7474
{:keys [_ _ body _]} @(http/get search-url (assoc (get-proxy-opts) :as :text))
7575
search-result (json/read-str body :key-fn keyword)]
76-
(map :a (-> search-result :response :docs))))
76+
(->> search-result
77+
:response
78+
:docs
79+
(keep :a))))
7780

7881
(defn- get-mvn-versions!
7982
"Fetches all the versions of particular artifact from maven repository."
8083
[artifact]
8184
(let [[group-id artifact] (str/split artifact #"/")
82-
search-prefix "http://search.maven.org/solrsearch/select?q=g:%22"
85+
search-prefix "https://search.maven.org/solrsearch/select?q=g:%22"
8386
{:keys [_ _ body _]} @(http/get (str search-prefix
8487
group-id
8588
"%22+AND+a:%22"
@@ -89,7 +92,7 @@
8992
(->> (json/read-str body :key-fn keyword)
9093
:response
9194
:docs
92-
(map :v))))
95+
(keep :v))))
9396

9497
(defn- get-artifacts-from-mvn-central!
9598
[]
@@ -105,7 +108,9 @@
105108
(let [{:keys [body status]} @(http/get (str "https://clojars.org/api/artifacts/"
106109
artifact))]
107110
(when (= 200 status)
108-
(map :version (:recent_versions (json/read-str body :key-fn keyword))))))
111+
(->> (json/read-str body :key-fn keyword)
112+
:recent_versions
113+
(keep :version)))))
109114

110115
(defn- get-artifacts-from-clojars!
111116
[]

test/refactor_nrepl/artifacts_test.clj

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,28 @@
1818
(def clojure-artifacts ["clojure"])
1919
(def clojars-artifacts (resource "clojars-artifacts.edn"))
2020

21+
(deftest get-mvn-artifacts!-test
22+
(is (> (count (#'artifacts/get-mvn-artifacts! "org.clojure"))
23+
10)))
24+
25+
(deftest get-clojars-artifacts!-test
26+
(is (> (count (#'artifacts/get-clojars-artifacts!))
27+
1000)))
28+
29+
(deftest get-mvn-versions!-test
30+
(is (> (count (#'artifacts/get-mvn-versions! "org.clojure/clojure"))
31+
20)))
32+
33+
(deftest get-clojars-versions!-test
34+
(is (> (count (#'artifacts/get-clojars-versions! "refactor-nrepl/refactor-nrepl"))
35+
30)))
36+
2137
(deftest creates-a-map-of-artifacts
2238
(reset! artifacts/artifacts {})
23-
(with-redefs
24-
[artifacts/get-clojars-artifacts! (constantly clojars-artifacts)
25-
artifacts/get-clojars-versions! (constantly aero-versions)
26-
artifacts/get-mvn-artifacts! (constantly clojure-artifacts)
27-
artifacts/get-mvn-versions! (constantly clojure-versions)]
39+
(with-redefs [artifacts/get-clojars-artifacts! (constantly clojars-artifacts)
40+
artifacts/get-clojars-versions! (constantly aero-versions)
41+
artifacts/get-mvn-artifacts! (constantly clojure-artifacts)
42+
artifacts/get-mvn-versions! (constantly clojure-versions)]
2843

2944
(is (#'artifacts/stale-cache?))
3045

0 commit comments

Comments
 (0)