Skip to content

Commit

Permalink
Merge pull request #154 from liquidz/dev
Browse files Browse the repository at this point in the history
Add missing tests
  • Loading branch information
liquidz committed Mar 4, 2022
2 parents d242476 + 2dd33fa commit c288140
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
46 changes: 46 additions & 0 deletions test/antq/download_test.clj
@@ -0,0 +1,46 @@
(ns antq.download-test
(:require
[antq.download :as sut]
[antq.util.git :as u.git]
[clojure.test :as t]
[clojure.tools.deps.alpha :as deps]))

(defn- test-download!
[m]
(-> m
(sut/download!)
(dissoc :mvn/repos)))

(t/deftest download!-test
(with-redefs [deps/resolve-deps (fn [deps-map _args-map] deps-map)]
(t/testing "java"
(t/is (= {:deps {'foo/bar {:mvn/version "1.0.0"}}}
(test-download! [{:type :java
:name 'foo/bar
:latest-version "1.0.0"}]))))

(t/testing "git-sha"
(t/is (= {:deps {'foo/bar {:git/url "https://example.com"
:git/sha "SHA"}}}
(test-download! [{:type :git-sha
:name 'foo/bar
:latest-version "SHA"
:extra {:url "https://example.com"}}]))))

(t/testing "git-tag-and-sha"
(with-redefs [u.git/tag-sha-by-ls-remote
(fn [url tag]
(when (and (= "https://example.com" url)
(= "v1.0.0" tag))
"SHA2"))]
(t/is (= {:deps {'foo/bar {:git/url "https://example.com"
:git/tag "v1.0.0"
:git/sha "SHA2"}}}
(test-download! [{:type :git-tag-and-sha
:name 'foo/bar
:latest-version "v1.0.0"
:extra {:url "https://example.com"}}])))))

(t/testing "else"
(t/is (= {:deps nil}
(test-download! [{:type :invalid}]))))))
38 changes: 38 additions & 0 deletions test/antq/upgrade/clojure/tool_test.clj
@@ -0,0 +1,38 @@
(ns antq.upgrade.clojure.tool-test
(:require
[antq.dep.clojure.tool :as dep.clj.tool]
[antq.record :as r]
[antq.test-helper :as h]
[antq.upgrade :as upgrade]
[antq.upgrade.clojure.tool]
[antq.util.git :as u.git]
[clojure.java.io :as io]
[clojure.test :as t]))

(def ^:private dummy-dep
(r/map->Dependency {:project :clojure-tool
:type :git-tag-and-sha
:name "com.github.liquidz/antq"
:latest-version "9.9.9"
:file (io/resource "dep/clojure-cli-tool/dummy.edn")
:extra {:url "https://github.com/liquidz/antq.git"
:sha "bc28de6"}}))

(t/deftest upgrade-dep-test
(with-redefs [u.git/tag-sha-by-ls-remote (constantly "9876543210abcdefghijklmnopqrstuvwxyz1234")]
(let [from-deps (->> dummy-dep
:file
(slurp)
(dep.clj.tool/extract-deps "")
(vector))
to-deps (->> dummy-dep
(upgrade/upgrader)
(dep.clj.tool/extract-deps "")
(vector))]
(t/is (= #{{:name "com.github.liquidz/antq"
:version {:- "1.5.1" :+ "9.9.9"}
:url "https://github.com/liquidz/antq.git"
:sha {:- "bc28de64fb36b395da4267e8d7916d1a9e167bcd"
:+ "9876543"}}}
(h/diff-deps from-deps to-deps))))))

0 comments on commit c288140

Please sign in to comment.