From c8ba10a9dcfe8b44bcdb61c262cf4282379f40b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Z=C3=B6ller?= Date: Sat, 6 Jun 2020 15:18:31 +0200 Subject: [PATCH] #5 - Set up dependencies for Clojars Deployment --- build.boot | 5 ++- src/clj_test_containers/core.clj | 8 ++--- test/clj_test_containers/core_test.clj | 48 +++++++++++++------------- 3 files changed, 32 insertions(+), 29 deletions(-) diff --git a/build.boot b/build.boot index 323833e..1f4bf56 100644 --- a/build.boot +++ b/build.boot @@ -5,7 +5,8 @@ :source-paths #{"test"} :dependencies '[[org.clojure/clojure "1.10.1"] [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! pom {:project project @@ -22,3 +23,5 @@ (comp (pom) (jar) (install))) (require '[metosin.bat-test :refer (bat-test)]) +(require '[adzerk.bootlaces :refer :all]) +(bootlaces! version) diff --git a/src/clj_test_containers/core.clj b/src/clj_test_containers/core.clj index b88c399..a679254 100644 --- a/src/clj_test_containers/core.clj +++ b/src/clj_test_containers/core.clj @@ -29,7 +29,7 @@ :host (.getHost container)})) -(defn configure-volume [container-config +(defn configure-volume! [container-config {classpath-resource-mapping :classpath-resource-mapping file-system-bind :file-system-bind}] @@ -51,7 +51,7 @@ container-config) -(defn copy-file-to-container +(defn copy-file-to-container! "Copies a file into the running container" [container-conf {container-path :container-path path :path @@ -76,7 +76,7 @@ :stdout (.getStdout 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" [container-conf] (let [container (:container container-conf)] @@ -87,7 +87,7 @@ (.getMappedPort container port)]) (:exposed-ports container-conf))))))) -(defn stop +(defn stop! "Stops the underlying container" [container-conf] (.stop (:container container-conf)) diff --git a/test/clj_test_containers/core_test.clj b/test/clj_test_containers/core_test.clj index d526737..cfd65d7 100644 --- a/test/clj_test_containers/core_test.clj +++ b/test/clj_test_containers/core_test.clj @@ -7,8 +7,8 @@ (let [container (create {:image-name "postgres:12.2" :exposed-ports [5432] :env-vars {"POSTGRES_PASSWORD" "pw"}}) - initialized-container (start container) - stopped-container (stop container)] + initialized-container (start! container) + stopped-container (stop! container)] (is (some? (:id initialized-container))) (is (some? (:mapped-ports initialized-container))) (is (some? (get (:mapped-ports initialized-container) 5432))) @@ -21,9 +21,9 @@ (let [container (create {:image-name "postgres:12.2" :exposed-ports [5432] :env-vars {"POSTGRES_PASSWORD" "pw"}}) - initialized-container (start container) + initialized-container (start! container) result (execute-command initialized-container ["whoami"]) - stopped-container (stop container)] + stopped-container (stop! container)] (is (= 0 (:exit-code result))) (is (= "root\n" (:stdout result)))))) @@ -33,12 +33,12 @@ (let [container (-> (create {:image-name "postgres:12.2" :exposed-ports [5432] :env-vars {"POSTGRES_PASSWORD" "pw"}}) - (configure-volume {:classpath-resource-mapping {:resource-path "test.sql" - :container-path "/opt/test.sql" - :mode :read-only}})) - initialized-container (start container) + (configure-volume! {:classpath-resource-mapping {:resource-path "test.sql" + :container-path "/opt/test.sql" + :mode :read-only}})) + initialized-container (start! container) 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? (:mapped-ports initialized-container))) (is (some? (get (:mapped-ports initialized-container) 5432))) @@ -50,12 +50,12 @@ (let [container (-> (create {:image-name "postgres:12.2" :exposed-ports [5432] :env-vars {"POSTGRES_PASSWORD" "pw"}}) - (configure-volume {:file-system-bind {:host-path "." - :container-path "/opt" - :mode :read-only}})) - initialized-container (start container) + (configure-volume! {:file-system-bind {:host-path "." + :container-path "/opt" + :mode :read-only}})) + initialized-container (start! container) 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? (:mapped-ports initialized-container))) (is (some? (get (:mapped-ports initialized-container) 5432))) @@ -67,12 +67,12 @@ (let [container (-> (create {:image-name "postgres:12.2" :exposed-ports [5432] :env-vars {"POSTGRES_PASSWORD" "pw"}}) - (copy-file-to-container {:path "test.sql" - :container-path "/opt/test.sql" - :type :host-path})) - initialized-container (start container) + (copy-file-to-container! {:path "test.sql" + :container-path "/opt/test.sql" + :type :host-path})) + initialized-container (start! container) 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? (:mapped-ports initialized-container))) (is (some? (get (:mapped-ports initialized-container) 5432))) @@ -84,12 +84,12 @@ (let [container (-> (create {:image-name "postgres:12.2" :exposed-ports [5432] :env-vars {"POSTGRES_PASSWORD" "pw"}}) - (copy-file-to-container {:path "test.sql" - :container-path "/opt/test.sql" - :type :classpath-resource})) - initialized-container (start container) + (copy-file-to-container! {:path "test.sql" + :container-path "/opt/test.sql" + :type :classpath-resource})) + initialized-container (start! container) 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? (:mapped-ports initialized-container))) (is (some? (get (:mapped-ports initialized-container) 5432)))