#5 - Set up dependencies for Clojars Deployment

This commit is contained in:
Tim Zöller 2020-06-06 15:18:31 +02:00
parent 8d86894f71
commit c8ba10a9dc
3 changed files with 32 additions and 29 deletions

View file

@ -5,7 +5,8 @@
:source-paths #{"test"} :source-paths #{"test"}
:dependencies '[[org.clojure/clojure "1.10.1"] :dependencies '[[org.clojure/clojure "1.10.1"]
[org.testcontainers/testcontainers "1.14.3"] [org.testcontainers/testcontainers "1.14.3"]
[metosin/bat-test "0.4.4" :scope "test"]]) [metosin/bat-test "0.4.4" :scope "test"]
[adzerk/bootlaces "0.2.0" :scope "test"]])
(task-options! (task-options!
pom {:project project pom {:project project
@ -22,3 +23,5 @@
(comp (pom) (jar) (install))) (comp (pom) (jar) (install)))
(require '[metosin.bat-test :refer (bat-test)]) (require '[metosin.bat-test :refer (bat-test)])
(require '[adzerk.bootlaces :refer :all])
(bootlaces! version)

View file

@ -29,7 +29,7 @@
:host (.getHost container)})) :host (.getHost container)}))
(defn configure-volume [container-config (defn configure-volume! [container-config
{classpath-resource-mapping :classpath-resource-mapping {classpath-resource-mapping :classpath-resource-mapping
file-system-bind :file-system-bind}] file-system-bind :file-system-bind}]
@ -51,7 +51,7 @@
container-config) container-config)
(defn copy-file-to-container (defn copy-file-to-container!
"Copies a file into the running container" "Copies a file into the running container"
[container-conf {container-path :container-path [container-conf {container-path :container-path
path :path path :path
@ -76,7 +76,7 @@
:stdout (.getStdout result) :stdout (.getStdout result)
:stderr (.getStderr result)})) :stderr (.getStderr result)}))
(defn start (defn start!
"Starts the underlying testcontainer instance and adds new values to the response map, e.g. :id and :first-mapped-port" "Starts the underlying testcontainer instance and adds new values to the response map, e.g. :id and :first-mapped-port"
[container-conf] [container-conf]
(let [container (:container container-conf)] (let [container (:container container-conf)]
@ -87,7 +87,7 @@
(.getMappedPort container port)]) (.getMappedPort container port)])
(:exposed-ports container-conf))))))) (:exposed-ports container-conf)))))))
(defn stop (defn stop!
"Stops the underlying container" "Stops the underlying container"
[container-conf] [container-conf]
(.stop (:container container-conf)) (.stop (:container container-conf))

View file

@ -7,8 +7,8 @@
(let [container (create {:image-name "postgres:12.2" (let [container (create {:image-name "postgres:12.2"
:exposed-ports [5432] :exposed-ports [5432]
:env-vars {"POSTGRES_PASSWORD" "pw"}}) :env-vars {"POSTGRES_PASSWORD" "pw"}})
initialized-container (start container) initialized-container (start! container)
stopped-container (stop container)] stopped-container (stop! container)]
(is (some? (:id initialized-container))) (is (some? (:id initialized-container)))
(is (some? (:mapped-ports initialized-container))) (is (some? (:mapped-ports initialized-container)))
(is (some? (get (:mapped-ports initialized-container) 5432))) (is (some? (get (:mapped-ports initialized-container) 5432)))
@ -21,9 +21,9 @@
(let [container (create {:image-name "postgres:12.2" (let [container (create {:image-name "postgres:12.2"
:exposed-ports [5432] :exposed-ports [5432]
:env-vars {"POSTGRES_PASSWORD" "pw"}}) :env-vars {"POSTGRES_PASSWORD" "pw"}})
initialized-container (start container) initialized-container (start! container)
result (execute-command initialized-container ["whoami"]) result (execute-command initialized-container ["whoami"])
stopped-container (stop container)] stopped-container (stop! container)]
(is (= 0 (:exit-code result))) (is (= 0 (:exit-code result)))
(is (= "root\n" (:stdout result)))))) (is (= "root\n" (:stdout result))))))
@ -33,12 +33,12 @@
(let [container (-> (create {:image-name "postgres:12.2" (let [container (-> (create {:image-name "postgres:12.2"
:exposed-ports [5432] :exposed-ports [5432]
:env-vars {"POSTGRES_PASSWORD" "pw"}}) :env-vars {"POSTGRES_PASSWORD" "pw"}})
(configure-volume {:classpath-resource-mapping {:resource-path "test.sql" (configure-volume! {:classpath-resource-mapping {:resource-path "test.sql"
:container-path "/opt/test.sql" :container-path "/opt/test.sql"
:mode :read-only}})) :mode :read-only}}))
initialized-container (start container) initialized-container (start! container)
file-check (execute-command initialized-container ["tail" "/opt/test.sql"]) file-check (execute-command initialized-container ["tail" "/opt/test.sql"])
stopped-container (stop container)] stopped-container (stop! container)]
(is (some? (:id initialized-container))) (is (some? (:id initialized-container)))
(is (some? (:mapped-ports initialized-container))) (is (some? (:mapped-ports initialized-container)))
(is (some? (get (:mapped-ports initialized-container) 5432))) (is (some? (get (:mapped-ports initialized-container) 5432)))
@ -50,12 +50,12 @@
(let [container (-> (create {:image-name "postgres:12.2" (let [container (-> (create {:image-name "postgres:12.2"
:exposed-ports [5432] :exposed-ports [5432]
:env-vars {"POSTGRES_PASSWORD" "pw"}}) :env-vars {"POSTGRES_PASSWORD" "pw"}})
(configure-volume {:file-system-bind {:host-path "." (configure-volume! {:file-system-bind {:host-path "."
:container-path "/opt" :container-path "/opt"
:mode :read-only}})) :mode :read-only}}))
initialized-container (start container) initialized-container (start! container)
file-check (execute-command initialized-container ["tail" "/opt/README.md"]) file-check (execute-command initialized-container ["tail" "/opt/README.md"])
stopped-container (stop container)] stopped-container (stop! container)]
(is (some? (:id initialized-container))) (is (some? (:id initialized-container)))
(is (some? (:mapped-ports initialized-container))) (is (some? (:mapped-ports initialized-container)))
(is (some? (get (:mapped-ports initialized-container) 5432))) (is (some? (get (:mapped-ports initialized-container) 5432)))
@ -67,12 +67,12 @@
(let [container (-> (create {:image-name "postgres:12.2" (let [container (-> (create {:image-name "postgres:12.2"
:exposed-ports [5432] :exposed-ports [5432]
:env-vars {"POSTGRES_PASSWORD" "pw"}}) :env-vars {"POSTGRES_PASSWORD" "pw"}})
(copy-file-to-container {:path "test.sql" (copy-file-to-container! {:path "test.sql"
:container-path "/opt/test.sql" :container-path "/opt/test.sql"
:type :host-path})) :type :host-path}))
initialized-container (start container) initialized-container (start! container)
file-check (execute-command initialized-container ["tail" "/opt/test.sql"]) file-check (execute-command initialized-container ["tail" "/opt/test.sql"])
stopped-container (stop container)] stopped-container (stop! container)]
(is (some? (:id initialized-container))) (is (some? (:id initialized-container)))
(is (some? (:mapped-ports initialized-container))) (is (some? (:mapped-ports initialized-container)))
(is (some? (get (:mapped-ports initialized-container) 5432))) (is (some? (get (:mapped-ports initialized-container) 5432)))
@ -84,12 +84,12 @@
(let [container (-> (create {:image-name "postgres:12.2" (let [container (-> (create {:image-name "postgres:12.2"
:exposed-ports [5432] :exposed-ports [5432]
:env-vars {"POSTGRES_PASSWORD" "pw"}}) :env-vars {"POSTGRES_PASSWORD" "pw"}})
(copy-file-to-container {:path "test.sql" (copy-file-to-container! {:path "test.sql"
:container-path "/opt/test.sql" :container-path "/opt/test.sql"
:type :classpath-resource})) :type :classpath-resource}))
initialized-container (start container) initialized-container (start! container)
file-check (execute-command initialized-container ["tail" "/opt/test.sql"]) file-check (execute-command initialized-container ["tail" "/opt/test.sql"])
stopped-container (stop container)] stopped-container (stop! container)]
(is (some? (:id initialized-container))) (is (some? (:id initialized-container)))
(is (some? (:mapped-ports initialized-container))) (is (some? (:mapped-ports initialized-container)))
(is (some? (get (:mapped-ports initialized-container) 5432))) (is (some? (get (:mapped-ports initialized-container) 5432)))