2020-05-20 09:53:10 +00:00
|
|
|
(require '[babashka.pods :as pods])
|
2020-10-15 08:35:23 +00:00
|
|
|
|
|
|
|
|
(def fmt (or (System/getenv "BABASHKA_POD_TEST_FORMAT")
|
|
|
|
|
"edn"))
|
|
|
|
|
|
2020-10-15 08:55:22 +00:00
|
|
|
(def socket (System/getenv "BABASHKA_POD_TEST_SOCKET"))
|
|
|
|
|
|
2021-05-19 15:20:55 +00:00
|
|
|
(def cmd (cond-> ["clojure" "-M:test-pod"]
|
|
|
|
|
(= "json" fmt) (conj "--json")
|
|
|
|
|
(= "transit+json" fmt) (conj "--transit+json")))
|
|
|
|
|
|
|
|
|
|
;; (.println System/err cmd)
|
|
|
|
|
|
|
|
|
|
(def pod-id (:pod/id (pods/load-pod cmd
|
2020-10-15 08:55:22 +00:00
|
|
|
{:socket (boolean socket)})))
|
|
|
|
|
|
2020-05-20 09:53:10 +00:00
|
|
|
(require '[pod.test-pod :as pod])
|
2020-05-20 18:11:46 +00:00
|
|
|
(def pod-ns-name (ns-name (find-ns 'pod.test-pod)))
|
2020-05-20 09:53:10 +00:00
|
|
|
|
|
|
|
|
(def stream-results (atom []))
|
2020-05-20 11:28:04 +00:00
|
|
|
(def done-prom (promise))
|
2020-05-20 09:53:10 +00:00
|
|
|
(pods/invoke "pod.test-pod" 'pod.test-pod/range-stream [1 10]
|
2020-05-20 15:12:23 +00:00
|
|
|
{:handlers {:success (fn [value]
|
2020-05-20 11:28:04 +00:00
|
|
|
(swap! stream-results conj value))
|
2020-05-20 15:12:23 +00:00
|
|
|
:done (fn []
|
2020-05-20 11:28:04 +00:00
|
|
|
(deliver done-prom :ok))}})
|
|
|
|
|
@done-prom
|
2020-05-20 09:53:10 +00:00
|
|
|
|
|
|
|
|
(def ex-result
|
|
|
|
|
(try (pod.test-pod/error 1 2 3)
|
|
|
|
|
(catch clojure.lang.ExceptionInfo e
|
|
|
|
|
(str (ex-message e) " / " (ex-data e)))))
|
|
|
|
|
|
|
|
|
|
(pod.test-pod/print "hello" "print" "this" "debugging" "message")
|
|
|
|
|
(pod.test-pod/print-err "hello" "print" "this" "error")
|
|
|
|
|
|
|
|
|
|
(pod/do-twice (prn :foo))
|
|
|
|
|
|
|
|
|
|
(def callback-result (promise))
|
2020-05-20 19:56:54 +00:00
|
|
|
(pods/invoke pod-id 'pod.test-pod/add-sync [1 2]
|
2020-05-20 11:28:04 +00:00
|
|
|
{:handlers {:success
|
2020-05-20 15:12:23 +00:00
|
|
|
(fn [value]
|
2020-05-20 11:28:04 +00:00
|
|
|
(deliver callback-result value))}})
|
2020-05-20 09:53:10 +00:00
|
|
|
|
2020-05-20 19:56:54 +00:00
|
|
|
(def sync-invoke
|
|
|
|
|
(pods/invoke pod-id 'pod.test-pod/add-sync [1 2]))
|
|
|
|
|
|
2020-05-20 09:53:10 +00:00
|
|
|
(def error-result (promise))
|
2020-05-20 19:56:54 +00:00
|
|
|
(pods/invoke pod-id 'pod.test-pod/add-sync ["1" 2]
|
2020-05-20 11:28:04 +00:00
|
|
|
{:handlers
|
|
|
|
|
{:error (fn [m]
|
|
|
|
|
(deliver error-result m))}})
|
2020-05-20 09:53:10 +00:00
|
|
|
|
2020-05-20 18:11:46 +00:00
|
|
|
(def assoc-result (pod/assoc {:a 1} :b 2))
|
|
|
|
|
(def add-result (pod.test-pod/add-sync 1 2 3))
|
|
|
|
|
(def nil-result (pod.test-pod/return-nil))
|
|
|
|
|
|
2021-10-15 15:43:12 +00:00
|
|
|
(def add-sync-meta (:doc (meta #'pod.test-pod/add-sync)))
|
|
|
|
|
(def error-meta (:doc (meta #'pod.test-pod/error)))
|
|
|
|
|
(def read-other-tag-meta (:doc (meta #'pod.test-pod/read-other-tag)))
|
|
|
|
|
|
2020-05-21 15:28:14 +00:00
|
|
|
(def x9 pod.test-pod/x9)
|
|
|
|
|
|
2020-10-15 08:35:23 +00:00
|
|
|
(def tagged (if (= "edn" fmt)
|
|
|
|
|
(pod/reader-tag)
|
|
|
|
|
[1 2 3]))
|
|
|
|
|
|
|
|
|
|
(def other-tagged
|
|
|
|
|
(if (= "edn" fmt)
|
|
|
|
|
(pod/other-tag)
|
|
|
|
|
[[1] [1]]))
|
2020-05-22 15:45:01 +00:00
|
|
|
|
2020-09-28 14:40:21 +00:00
|
|
|
(def fn-called (pod.test-pod/fn-call inc 2))
|
|
|
|
|
|
2021-05-17 09:41:51 +00:00
|
|
|
;; (.println System/err (str :fmt " " fmt))
|
|
|
|
|
(def local-date-time
|
|
|
|
|
(if (= "transit+json" fmt)
|
|
|
|
|
(instance? java.time.LocalDateTime (pod.test-pod/local-date-time (java.time.LocalDateTime/now)))
|
|
|
|
|
true))
|
|
|
|
|
|
2021-05-19 19:19:18 +00:00
|
|
|
(def assoc-string-array
|
|
|
|
|
(if (= "transit+json" fmt)
|
|
|
|
|
(let [v (:a (pod.test-pod/assoc {} :a (into-array String ["foo"])))]
|
|
|
|
|
(.isArray (class v)))
|
|
|
|
|
true))
|
|
|
|
|
|
2023-05-12 14:09:40 +00:00
|
|
|
(def round-trip-meta
|
|
|
|
|
(if (= "transit+json" fmt)
|
|
|
|
|
(= {:my-meta 2} (meta (pod.test-pod/round-trip-meta (with-meta [2] {:my-meta 2}))))
|
|
|
|
|
true))
|
|
|
|
|
|
|
|
|
|
(def round-trip-meta-nested
|
|
|
|
|
(if (= "transit+json" fmt)
|
|
|
|
|
(= {:my-meta 3} (meta (first (pod.test-pod/round-trip-meta [(with-meta [3] {:my-meta 3})]))))
|
|
|
|
|
true))
|
|
|
|
|
|
|
|
|
|
(def dont-round-trip-meta
|
|
|
|
|
(if (= "transit+json" fmt)
|
|
|
|
|
(= nil (meta (pod.test-pod/dont-round-trip-meta (with-meta [2] {:my-meta 2}))))
|
|
|
|
|
true))
|
|
|
|
|
|
2020-09-30 10:24:04 +00:00
|
|
|
(require '[pod.test-pod.only-code :as only-code])
|
|
|
|
|
(def should-be-1 (only-code/foo))
|
|
|
|
|
|
2020-05-26 14:30:46 +00:00
|
|
|
(require '[pod.test-pod.loaded2 :as loaded2])
|
|
|
|
|
(def loaded (loaded2/loaded 1))
|
|
|
|
|
|
2022-12-29 16:05:23 +00:00
|
|
|
(def incorrect-edn-response
|
|
|
|
|
(try (pod.test-pod/incorrect-edn)
|
|
|
|
|
(catch Exception e (ex-message e))))
|
|
|
|
|
|
2020-05-20 18:11:46 +00:00
|
|
|
(pods/unload-pod pod-id)
|
|
|
|
|
(def successfully-removed (nil? (find-ns 'pod.test-pod)))
|
|
|
|
|
|
|
|
|
|
[pod-id
|
|
|
|
|
pod-ns-name
|
|
|
|
|
assoc-result
|
|
|
|
|
add-result
|
2020-05-20 19:56:54 +00:00
|
|
|
sync-invoke
|
2020-05-20 09:53:10 +00:00
|
|
|
@stream-results
|
|
|
|
|
ex-result
|
2020-05-20 18:11:46 +00:00
|
|
|
nil-result
|
2020-05-20 09:53:10 +00:00
|
|
|
@callback-result
|
|
|
|
|
(:ex-message @error-result)
|
2020-05-20 18:11:46 +00:00
|
|
|
(:ex-data @error-result)
|
2020-05-21 15:28:14 +00:00
|
|
|
successfully-removed
|
2020-05-22 15:45:01 +00:00
|
|
|
x9
|
|
|
|
|
tagged
|
2020-05-26 14:30:46 +00:00
|
|
|
other-tagged
|
2020-09-28 14:40:21 +00:00
|
|
|
loaded
|
2020-09-30 10:24:04 +00:00
|
|
|
fn-called
|
2021-05-17 09:41:51 +00:00
|
|
|
local-date-time
|
2021-05-19 19:19:18 +00:00
|
|
|
assoc-string-array
|
2023-05-12 14:09:40 +00:00
|
|
|
round-trip-meta
|
|
|
|
|
round-trip-meta-nested
|
|
|
|
|
dont-round-trip-meta
|
2021-10-15 15:43:12 +00:00
|
|
|
should-be-1
|
|
|
|
|
add-sync-meta
|
|
|
|
|
error-meta
|
2022-12-29 16:05:23 +00:00
|
|
|
read-other-tag-meta
|
|
|
|
|
incorrect-edn-response]
|