This repository has been archived by the owner on Oct 6, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathscript.clj
executable file
·98 lines (85 loc) · 3.81 KB
/
script.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env bb
(ns script
(:require
[babashka.pods :as pods]
[clojure.edn :as edn]
[clojure.java.io :as io]
[clojure.string :as str]
[clojure.test :as t :refer [deftest is testing]]))
(defmethod clojure.test/report :begin-test-var [m]
(println "===" (-> m :var meta :name))
(println))
(if (= "executable" (System/getProperty "org.graalvm.nativeimage.kind"))
(do
(println "Running native tests")
(pods/load-pod "./pod-babashka-aws"))
(do
(println "Running JVM tests")
(pods/load-pod ["clojure" "-M" "-m" "pod.babashka.aws"])))
(require '[pod.babashka.aws :as aws])
(def region (System/getenv "AWS_REGION"))
(def s3 (aws/client {:api :s3 :region
(or region "eu-central-1")}))
(deftest aws-ops-test
(is (contains? (aws/ops s3) :ListBuckets)))
(deftest aws-doc-test
(is (str/includes?
(with-out-str (aws/doc s3 :ListBuckets))
"Returns a list of all buckets")))
(deftest aws-invoke-test
;; tests cannot be conditionally defined in bb currently, see #705, so moved
;; the conditions inside the test
(if (and (System/getenv "AWS_ACCESS_KEY_ID")
(System/getenv "AWS_SECRET_ACCESS_KEY")
region)
(do (is (= (keys (aws/invoke s3 {:op :ListBuckets})) [:Buckets :Owner]))
(let [png (java.nio.file.Files/readAllBytes
(.toPath (io/file "resources" "babashka.png")))
;; ensure bucket, ignore error if it already exists
_bucket-resp (aws/invoke
s3
{:op :CreateBucket
:request {:Bucket "pod-babashka-aws"
:CreateBucketConfiguration {:LocationConstraint region}}})
put1 (aws/invoke s3 {:op :PutObject
:request {:Bucket "pod-babashka-aws"
:Key "logo.png"
:Body png}})
_ (is (not (:Error put1)))
get1 (aws/invoke s3 {:op :GetObject
:request {:Bucket "pod-babashka-aws"
:Key "logo.png"}})
read-bytes (fn [is]
(let [baos (java.io.ByteArrayOutputStream.)]
(io/copy is baos)
(.toByteArray baos)))
bytes (read-bytes (:Body get1))
_ (is (= (count png) (count bytes)))
put2 (testing "inputstream arg"
(aws/invoke s3 {:op :PutObject
:request {:Bucket "pod-babashka-aws"
:Key "logo.png"
:Body (io/input-stream
(io/file "resources" "babashka.png"))}}))
_ (is (not (:Error put2)))
get2 (aws/invoke s3 {:op :GetObject
:request {:Bucket "pod-babashka-aws"
:Key "logo.png"}})
bytes (read-bytes (:Body get2))
_ (is (= (count png) (count bytes)))]
:the-end))
(println "Skipping credential test")))
(deftest no-such-service-test
(is (thrown-with-msg?
Exception #"api :some-typo not available"
(aws/client {:api :some-typo}))))
(def services (edn/read-string (slurp "resources/aws-services.edn")))
(deftest all-services-test
(testing "all clients of all available services"
(doseq [service services]
(is (= service (do (aws/client {:api service})
service))))))
(when-not (= "executable" (System/getProperty "org.graalvm.nativeimage.kind"))
(shutdown-agents))
(let [{:keys [:fail :error]} (t/run-tests)]
(System/exit (+ fail error)))