Pod resolver tests. See borkdude/babashka#690
This commit is contained in:
parent
22f200ef30
commit
280f99888c
5 changed files with 61 additions and 14 deletions
|
|
@ -18,20 +18,26 @@
|
|||
(def os {:os/name (System/getProperty "os.name")
|
||||
:os/arch (let [arch (System/getProperty "os.arch")]
|
||||
(normalize-arch arch))})
|
||||
|
||||
(defn warn [& strs]
|
||||
(binding [*out* *err*]
|
||||
(apply println strs)))
|
||||
|
||||
(defn match-artifacts [package]
|
||||
(let [artifacts (:pod/artifacts package)]
|
||||
(filter (fn [{os-name :os/name
|
||||
os-arch :os/arch}]
|
||||
(let [os-arch (normalize-arch os-arch)]
|
||||
(and (re-matches (re-pattern os-name) (:os/name os))
|
||||
(re-matches (re-pattern os-arch)
|
||||
(:os/arch os)))))
|
||||
artifacts)))
|
||||
(let [artifacts (:pod/artifacts package)
|
||||
res (filter (fn [{os-name :os/name
|
||||
os-arch :os/arch}]
|
||||
(let [os-arch (normalize-arch os-arch)]
|
||||
(and (re-matches (re-pattern os-name) (:os/name os))
|
||||
(re-matches (re-pattern os-arch)
|
||||
(:os/arch os)))))
|
||||
artifacts)]
|
||||
(when (empty? res)
|
||||
(throw (IllegalArgumentException. (format "No executable found for pod %s (%s) and OS %s/%s"
|
||||
(:pod/name package)
|
||||
(:pod/version package)
|
||||
(:os/name os)
|
||||
(:os/arch os)))))
|
||||
res))
|
||||
|
||||
(defn unzip [{:keys [^java.io.File zip-file
|
||||
^java.io.File destination-dir
|
||||
|
|
@ -149,7 +155,8 @@
|
|||
(String. "UTF-8"))))
|
||||
|
||||
(defn resolve [qsym version force?]
|
||||
(assert (string? version) "Version must be provided!")
|
||||
(when-not (string? version)
|
||||
(throw (IllegalArgumentException. "Version must be provided for resolving from pod registry!")))
|
||||
(when-let [manifest (pod-manifest qsym version force?)]
|
||||
(let [artifacts (match-artifacts manifest)
|
||||
cdir (cache-dir manifest)
|
||||
|
|
|
|||
11
test-resources/pod_registry.clj
Normal file
11
test-resources/pod_registry.clj
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
(require '[babashka.pods :as pods])
|
||||
|
||||
(pods/load-pod 'org.babashka/buddy "0.0.1")
|
||||
|
||||
(require '[pod.babashka.buddy.codecs :as codecs]
|
||||
'[pod.babashka.buddy.hash :as hash])
|
||||
|
||||
(println (-> (hash/sha256 "foobar")
|
||||
(codecs/bytes->hex)))
|
||||
|
||||
(pods/load-pod 'org.babashka/etaoin) ;; should cause error when version is missing
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
(ns babashka.pods.jvm-test
|
||||
(:require [babashka.pods.test-common :refer [test-program assertions]]
|
||||
[clojure.test :refer [deftest]]))
|
||||
(:require [babashka.pods.test-common :refer [test-program assertions
|
||||
pod-registry]]
|
||||
[clojure.string :as str]
|
||||
[clojure.test :refer [deftest is]]))
|
||||
|
||||
(deftest jvm-test
|
||||
(let [out (java.io.StringWriter.)
|
||||
|
|
@ -12,3 +14,15 @@
|
|||
(catch Exception e (prn e))))]
|
||||
|
||||
(assertions out err ret)))
|
||||
|
||||
(deftest pod-registry-test
|
||||
(let [out (java.io.StringWriter.)
|
||||
err (java.io.StringWriter.)
|
||||
ex (binding [*out* out
|
||||
*err* err]
|
||||
(try (load-string
|
||||
pod-registry)
|
||||
(catch Exception e
|
||||
e)))]
|
||||
(is (str/includes? (str out) "c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2"))
|
||||
(is (str/includes? (pr-str ex) "Version must be provided" ))))
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
(ns babashka.pods.sci-test
|
||||
(:require [babashka.pods.sci :as pods]
|
||||
[babashka.pods.test-common :refer [test-program assertions]]
|
||||
[clojure.test :refer [deftest]]
|
||||
[babashka.pods.test-common :refer [test-program assertions pod-registry]]
|
||||
[clojure.string :as str]
|
||||
[clojure.test :refer [deftest is]]
|
||||
[sci.core :as sci]))
|
||||
|
||||
(deftest sci-test
|
||||
|
|
@ -19,3 +20,15 @@
|
|||
sci/err err]
|
||||
(sci/eval-string* ctx test-program))]
|
||||
(assertions out err ret)))
|
||||
|
||||
(deftest pod-registry-test
|
||||
(let [out (java.io.StringWriter.)
|
||||
err (java.io.StringWriter.)
|
||||
ex (binding [*out* out
|
||||
*err* err]
|
||||
(try (load-string
|
||||
pod-registry)
|
||||
(catch Exception e
|
||||
e)))]
|
||||
(is (str/includes? (str out) "c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2"))
|
||||
(is (str/includes? (pr-str ex) "Version must be provided" ))))
|
||||
|
|
|
|||
|
|
@ -30,3 +30,5 @@
|
|||
(is (= expected actual))))
|
||||
(is (= "(\"hello\" \"print\" \"this\" \"debugging\" \"message\")\n:foo\n:foo\n" (str out)))
|
||||
(is (= "(\"hello\" \"print\" \"this\" \"error\")\n" (str err))))
|
||||
|
||||
(def pod-registry (slurp (io/file "test-resources" "pod_registry.clj")))
|
||||
|
|
|
|||
Loading…
Reference in a new issue