Skip to content

Commit

Permalink
Add upgrade-http-jar-test
Browse files Browse the repository at this point in the history
  • Loading branch information
rads committed May 5, 2024
1 parent 6e0c321 commit c932829
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
6 changes: 4 additions & 2 deletions bbin
Original file line number Diff line number Diff line change
Expand Up @@ -1186,8 +1186,10 @@ WARNING: (We won't make any changes without asking you first.)
(common/install-script script-name header script-file script-contents cli-opts)))

(upgrade [_]
(p/install (map->HttpJar {:cli-opts {:script/lib (:bbin/url coords)}
:coords coords})))
(let [cli-opts' (merge (select-keys cli-opts [:edn])
{:script/lib (:bbin/url coords)})]
(p/install (map->HttpJar {:cli-opts cli-opts'
:coords coords}))))

(uninstall [_]
(common/delete-files cli-opts)))
Expand Down
6 changes: 4 additions & 2 deletions src/babashka/bbin/scripts/http_jar.clj
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@
(common/install-script script-name header script-file script-contents cli-opts)))

(upgrade [_]
(p/install (map->HttpJar {:cli-opts {:script/lib (:bbin/url coords)}
:coords coords})))
(let [cli-opts' (merge (select-keys cli-opts [:edn])
{:script/lib (:bbin/url coords)})]
(p/install (map->HttpJar {:cli-opts cli-opts'
:coords coords}))))

(uninstall [_]
(common/delete-files cli-opts)))
24 changes: 22 additions & 2 deletions test/babashka/bbin/scripts/http_jar_test.clj
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
(ns babashka.bbin.scripts.http-jar-test
(:require [babashka.bbin.dirs :as dirs]
[babashka.bbin.test-util :as tu]
[babashka.fs :as fs]
[clojure.test :refer [deftest is testing use-fixtures]]))

(use-fixtures :once (tu/bbin-dirs-fixture))
(use-fixtures :once
(tu/bbin-dirs-fixture)
(tu/http-server-fixture))

(def hello-jar-url "https://raw.githubusercontent.com/rads/bbin-test-lib/main/hello.jar")
(def hello-jar-url
(format "http://localhost:%d/hello.jar" tu/http-port))

(deftest install-from-url-jar-test
(testing "install https://*.jar"
(tu/reset-test-dir)
(dirs/ensure-bbin-dirs {})
(let [cli-opts {:script/lib hello-jar-url}
_ (fs/copy (fs/file "test-resources" "hello.jar")
(fs/file tu/http-public-dir "hello.jar"))
out (tu/run-install cli-opts)]
(is (= {:coords {:bbin/url hello-jar-url}} out))
(is (= "Hello JAR" (tu/run-bin-script :hello)))))
Expand All @@ -21,3 +27,17 @@
(is (= {:coords {:bbin/url hello-jar-url}} out))
(is (= "Hello JAR" (tu/run-bin-script :hello)))
(is (= {'hello {:coords {:bbin/url hello-jar-url}}} (tu/run-ls))))))

(deftest upgrade-http-jar-test
(testing "upgrade (http jar)"
(tu/reset-test-dir)
(dirs/ensure-bbin-dirs {})
(fs/copy (fs/file "test-resources" "hello.jar")
(fs/file tu/http-public-dir "hello.jar"))
(tu/run-install {:script/lib hello-jar-url})
(is (= "Hello JAR" (tu/run-bin-script :hello)))
(fs/copy (fs/file "test-resources" "hello2.jar")
(fs/file tu/http-public-dir "hello.jar")
{:replace-existing true})
(tu/run-upgrade {:script/lib "hello"})
(is (= "Hello JAR 2" (tu/run-bin-script :hello)))))

0 comments on commit c932829

Please sign in to comment.