1+ (ns clojure.tools.tools.api-test
2+ (:require
3+ [clojure.string :as str]
4+ [clojure.test :refer :all ]
5+ [clojure.tools.tools.api :as sut]))
6+
7+ (def tool-install-name " temporary-ci-test-tool" )
8+
9+ (deftest install-update-list-and-remove
10+ (testing " Install specific version that is not the latest"
11+ (let [expected-response (str tool-install-name " : Installed com.github.seancorfield/deps-new v0.4.9" )
12+ actual-response (with-out-str (sut/install {'com.github.seancorfield/deps-new {:git/url " https://github.com/seancorfield/deps-new"
13+ :git/tag " v0.4.9" } :as tool-install-name}))]
14+ (is (str/includes? actual-response expected-response))))
15+
16+ (testing " list installed tools"
17+ (let [expected-response (re-pattern (str tool-install-name " \\ s*com\\ .github\\ .seancorfield/deps-new\\ s*:git\\ s*v0\\ .4\\ .9" ))
18+ actual-response (with-out-str (sut/list nil ))]
19+ (is (re-find expected-response actual-response))))
20+
21+ (testing " update installed tool to latest version"
22+ ; ; Would be more desirable if we had a test tool to install and could check the specific version that wouldn't change
23+ (let [expected-response (re-pattern (str tool-install-name " : Installed com\\ .github\\ .seancorfield/deps-new" ))
24+ actual-response (with-out-str (sut/install-latest {:tool tool-install-name}))]
25+ (is (re-find expected-response actual-response))))
26+
27+ (testing " list installed tools reflects updated version"
28+ (let [old-tool (re-pattern (str tool-install-name " \\ s*com\\ .github\\ .seancorfield/deps-new\\ s*:git\\ s*v0\\ .4\\ .9" ))
29+ expected-response (re-pattern (str tool-install-name " \\ s*com\\ .github\\ .seancorfield/deps-new" ))
30+ actual-response (with-out-str (sut/list nil ))]
31+ (is (not (re-find old-tool actual-response)) " The old tool was not successfully updated" )
32+ (is (re-find expected-response actual-response))))
33+
34+ (testing " remove installed tool"
35+ (let [removal-response (with-out-str (sut/remove {:tool tool-install-name}))
36+ list-response (with-out-str (sut/list nil ))]
37+ (is (str/includes? removal-response " Tool removed" ))
38+ (is (not (str/includes? list-response tool-install-name)) " The tool was not successfully removed" ))))
39+
40+ (deftest install-latest-git-procurer-with-provided-coord
41+ (testing " Installed latest version of tool, for git procurer providing coord"
42+ (let [expected-response (re-pattern (str tool-install-name " : Installed com\\ .github\\ .seancorfield/deps-new" ))
43+ actual-response (with-out-str (sut/install-latest {:lib 'com.github.seancorfield/deps-new
44+ :coord {:git/url " https://github.com/seancorfield/deps-new" }
45+ :as tool-install-name}))]
46+ (is (re-find expected-response actual-response))))
47+
48+ (testing " remove installed tool"
49+ (let [removal-response (with-out-str (sut/remove {:tool tool-install-name}))
50+ list-response (with-out-str (sut/list nil ))]
51+ (is (str/includes? removal-response " Tool removed" ))
52+ (is (not (str/includes? list-response tool-install-name)) " The tool was not successfully removed" ))))
0 commit comments