Skip to content

Commit

Permalink
test: Add test for antq.dep.clojure.tool
Browse files Browse the repository at this point in the history
cf. #146
  • Loading branch information
liquidz committed Feb 28, 2022
1 parent e0a6225 commit 23e08b7
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/antq/dep/clojure/tool.clj
Expand Up @@ -13,14 +13,16 @@
(when (and sha tag url)
(r/map->Dependency {:type :git-tag-and-sha
:file file-path
:name (:lib edn)
:name (str (:lib edn))
:project :clojure-tool
:version tag
:extra {:url url :sha sha}}))))

(defn load-deps
[]
(some->> (io/file (u.env/getenv "HOME") ".clojure" "tools")
(file-seq)
(filter #(and (.isFile %) (str/ends-with? (.getName %) ".edn")))
(keep #(extract-deps (.getAbsolutePath %) (slurp %)))))
([]
(load-deps (io/file (u.env/getenv "HOME") ".clojure" "tools")))
([dir-file]
(some->> dir-file
(file-seq)
(filter #(and (.isFile %) (str/ends-with? (.getName %) ".edn")))
(keep #(extract-deps (.getAbsolutePath %) (slurp %))))))
35 changes: 35 additions & 0 deletions test/antq/dep/clojure/tool_test.clj
@@ -0,0 +1,35 @@
(ns antq.dep.clojure.tool-test
(:require
[antq.dep.clojure.tool :as sut]
[antq.record :as r]
[clojure.java.io :as io]
[clojure.test :as t]))

(def ^:private file-path
(.getAbsolutePath (io/file (io/resource "dep/clojure-cli-tool/dummy.edn"))))

(defn- git-tag-dependency
[m]
(r/map->Dependency (merge {:project :clojure-tool
:type :git-tag-and-sha
:file file-path}
m)))

(t/deftest extract-deps-test
(let [content (pr-str '{:lib foo/bar
:coord {:git/tag "1.0.0"
:git/sha "dummy sha"
:git/url "https://example.com"}})]
(t/is (= (git-tag-dependency {:name "foo/bar" :version "1.0.0"
:extra {:url "https://example.com" :sha "dummy sha"}})
(sut/extract-deps file-path content)))))

(t/deftest extract-deps-local-root-test
(let [content (pr-str '{:lib foo/bar
:coord {:local/root "/path/to/local"}})]
(t/is (nil? (sut/extract-deps file-path content)))))

(t/deftest load-deps-test
(let [dir (io/file (io/resource "dep/clojure-cli-tool"))
deps (sut/load-deps dir)]
(t/is (every? #(= :git-tag-and-sha (:type %)) deps))))

0 comments on commit 23e08b7

Please sign in to comment.