Skip to content

Commit

Permalink
Add upgrade-maven-jar-test
Browse files Browse the repository at this point in the history
  • Loading branch information
rads authored and borkdude committed Jun 12, 2024
1 parent 9fdcaf4 commit 92644a3
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 16 deletions.
12 changes: 6 additions & 6 deletions bbin
Original file line number Diff line number Diff line change
Expand Up @@ -1282,9 +1282,7 @@ WARNING: (We won't make any changes without asking you first.)
(let [vparse (requiring-resolve 'version-clj.core/parse)]
(some (fn [version]
(let [{:keys [qualifiers]} (vparse version)]
(when-not
;; assume all qualifiers indicate non-stable version
(some #{"rc" "alpha" "beta" "snapshot" "milestone"} qualifiers)
(when-not (some #{"rc" "alpha" "beta" "snapshot" "milestone"} qualifiers)
version)))
versions)))

Expand Down Expand Up @@ -1355,9 +1353,11 @@ WARNING: (We won't make any changes without asking you first.)

(upgrade [_]
(let [latest-version (or (latest-stable-clojars-version lib)
(latest-stable-mvn-version lib))]
(p/install (map->MavenJar {:cli-opts {:script/lib (str lib)
:mvn/version latest-version}
(latest-stable-mvn-version lib))
cli-opts' (merge (select-keys cli-opts [:edn])
{:script/lib (str lib)
:mvn/version latest-version})]
(p/install (map->MavenJar {:cli-opts cli-opts'
:lib lib}))))

(uninstall [_]
Expand Down
12 changes: 6 additions & 6 deletions src/babashka/bbin/scripts/maven_jar.clj
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@
(let [vparse (requiring-resolve 'version-clj.core/parse)]
(some (fn [version]
(let [{:keys [qualifiers]} (vparse version)]
(when-not
;; assume all qualifiers indicate non-stable version
(some #{"rc" "alpha" "beta" "snapshot" "milestone"} qualifiers)
(when-not (some #{"rc" "alpha" "beta" "snapshot" "milestone"} qualifiers)
version)))
versions)))

Expand Down Expand Up @@ -121,9 +119,11 @@

(upgrade [_]
(let [latest-version (or (latest-stable-clojars-version lib)
(latest-stable-mvn-version lib))]
(p/install (map->MavenJar {:cli-opts {:script/lib (str lib)
:mvn/version latest-version}
(latest-stable-mvn-version lib))
cli-opts' (merge (select-keys cli-opts [:edn])
{:script/lib (str lib)
:mvn/version latest-version})]
(p/install (map->MavenJar {:cli-opts cli-opts'
:lib lib}))))

(uninstall [_]
Expand Down
26 changes: 22 additions & 4 deletions test/babashka/bbin/scripts/maven_jar_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
{:lib 'org.babashka/http-server
:coords {:mvn/version "0.1.11"}})

(def help-text
"Serves static assets using web server.")

(deftest install-from-mvn-version-test
(testing "install */* --mvn/version *"
(tu/reset-test-dir)
Expand All @@ -21,7 +24,22 @@
(is (= maven-lib out))
(is (fs/exists? (fs/file (dirs/bin-dir nil) (name (:lib maven-lib)))))
(is (str/starts-with? (tu/run-bin-script (:lib maven-lib) "--help")
"Serves static assets using web server."))
(is (= '{http-server {:lib org.babashka/http-server
:coords {:mvn/version "0.1.11"}}}
(tu/run-ls))))))
help-text))
(is (= `{~'http-server ~maven-lib} (tu/run-ls))))))

(def upgraded-lib
(assoc-in maven-lib [:coords :mvn/version] "0.1.12"))

(deftest upgrade-maven-jar-test
(testing "upgrade (maven jar)"
(tu/reset-test-dir)
(dirs/ensure-bbin-dirs {})
(let [out (tu/run-install {:script/lib (str (:lib maven-lib))
:mvn/version (-> maven-lib :coords :mvn/version)})
out2 (tu/run-upgrade {:script/lib "http-server"})]
(is (= maven-lib out))
(is (= upgraded-lib out2))
(is (fs/exists? (fs/file (dirs/bin-dir nil) (name (:lib upgraded-lib)))))
(is (str/starts-with? (tu/run-bin-script (:lib upgraded-lib) "--help")
help-text))
(is (= `{~'http-server ~upgraded-lib} (tu/run-ls))))))
4 changes: 4 additions & 0 deletions test/babashka/bbin/test_util.clj
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
(some-> (with-out-str (scripts/install (assoc cli-opts :edn true)))
edn/read-string))

(defn run-upgrade [cli-opts]
(some-> (with-out-str (scripts/upgrade (assoc cli-opts :edn true)))
edn/read-string))

(defn run-ls []
(some-> (with-out-str (scripts/ls {:edn true}))
edn/read-string))
Expand Down

0 comments on commit 92644a3

Please sign in to comment.