From 8c807a8750d1ff9816a92f205e53e4f21d6a2b2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Z=C3=B6ller?= Date: Thu, 24 Aug 2023 02:10:26 +0200 Subject: [PATCH] Update testcontainers version to 1.19.0 (#69) --- project.clj | 6 ++--- src/clj_test_containers/core.clj | 5 +++- test/clj_test_containers/core_test.clj | 37 ++++++++++++++++---------- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/project.clj b/project.clj index 53c0e9b..6159c99 100644 --- a/project.clj +++ b/project.clj @@ -7,7 +7,7 @@ :url "http://www.eclipse.org/legal/epl-v10.html"} :dependencies [[org.clojure/clojure "1.10.3"] - [org.testcontainers/testcontainers "1.17.6"]] + [org.testcontainers/testcontainers "1.19.0"]] :aliases {"test" ["run" "-m" "kaocha.runner"] "cljstyle" ["run" "-m" "cljstyle.main"]} @@ -15,14 +15,14 @@ :plugins [[jainsahab/lein-githooks "1.0.0"]] :profiles {:dev {:dependencies [[expound "0.9.0"] - [lambdaisland/kaocha "1.71.1119"] + [lambdaisland/kaocha "1.85.1342"] [lambdaisland/kaocha-cloverage "1.1.89"] [lambdaisland/kaocha-junit-xml "1.17.101"] [mvxcvi/cljstyle "0.15.0" :exclusions [org.clojure/clojure]] [org.clojure/test.check "1.1.1"] [orchestra "2021.01.01-1"] [org.clojure/tools.namespace "1.3.0"] - [org.testcontainers/postgresql "1.17.6"] + [org.testcontainers/postgresql "1.19.0"] [com.fzakaria/slf4j-timbre "0.3.21"] [nrepl "1.0.0"]] :source-paths ["dev-src"]}} diff --git a/src/clj_test_containers/core.clj b/src/clj_test_containers/core.clj index 79d1d93..b43cc12 100644 --- a/src/clj_test_containers/core.clj +++ b/src/clj_test_containers/core.clj @@ -334,7 +334,10 @@ (defn dump-logs "Dumps the logs found by invoking the function on the :string-log key" [container-config] - ((:log container-config))) + (let [log-fn (:log container-config)] + (if (some? log-fn) + (log-fn) + (throw (IllegalStateException. "You are trying to access the container logs, but have not configured a log configuration with :log-to"))))) (defn start! "Starts the underlying testcontainer instance and adds new values to the diff --git a/test/clj_test_containers/core_test.clj b/test/clj_test_containers/core_test.clj index 40d6ba0..ec80794 100644 --- a/test/clj_test_containers/core_test.clj +++ b/test/clj_test_containers/core_test.clj @@ -9,7 +9,7 @@ (deftest create-test (testing "Testing basic testcontainer generic image initialisation" - (let [container (sut/create {:image-name "postgres:12.2" + (let [container (sut/create {:image-name "postgres:15.3" :exposed-ports [5432] :env-vars {"POSTGRES_PASSWORD" "pw"}}) initialized-container (sut/start! container) @@ -21,21 +21,29 @@ (is (nil? (:mapped-ports stopped-container))))) (testing "Testing log access to the container with string logs" - (let [container (sut/init {:container (PostgreSQLContainer. "postgres:12.2") - :log-to {:log-strategy :string}}) + (let [container (sut/create {:image-name "postgres:15.3" + :exposed-ports [5432] + :env-vars {"POSTGRES_PASSWORD" "pw"} + :log-to {:log-strategy :string}}) initialized-container (sut/start! container)] (Thread/sleep 500) (is (includes? (sut/dump-logs initialized-container) "database system is ready to accept connections")))) (testing "Testing log access to the container with function logs" (let [logs (atom [])] - (sut/start! (sut/init {:container (PostgreSQLContainer. "postgres:12.2") + (sut/start! (sut/init {:container (PostgreSQLContainer. "postgres:15.3") + :exposed-ports [5432] :log-to {:log-strategy :fn :function #(swap! logs conj %)}})) (is (filter #(includes? "database system is ready to accept connections" %) @logs)))) + (testing "Testing log access to the container with unconfigured logger" + (let [container (sut/start! (sut/init {:container (PostgreSQLContainer. "postgres:15.3") + :exposed-ports [5432]}))] + (is (thrown? IllegalStateException (sut/dump-logs container))))) + (testing "Testing basic testcontainer generic image initialisation with wait for log message" - (let [container (sut/create {:image-name "postgres:12.2" + (let [container (sut/create {:image-name "postgres:15.3" :exposed-ports [5432] :env-vars {"POSTGRES_PASSWORD" "pw"} :wait-for {:wait-strategy :log @@ -51,7 +59,7 @@ (is (nil? (:mapped-ports stopped-container))))) (testing "Testing basic testcontainer generic image initialisation with wait for host port" - (let [container (sut/create {:image-name "postgres:12.2" + (let [container (sut/create {:image-name "postgres:15.3" :exposed-ports [5432] :env-vars {"POSTGRES_PASSWORD" "pw"} :wait-for {:wait-strategy :port}}) @@ -101,7 +109,8 @@ (testing "Executing a command in the running Docker container with a custom container" - (let [container (sut/init {:container (PostgreSQLContainer. "postgres:12.2")}) + (let [container (sut/init {:container (PostgreSQLContainer. "postgres:15.3") + :exposed-ports [5432]}) initialized-container (sut/start! container) result (sut/execute-command! initialized-container ["whoami"]) _stopped-container (sut/stop! container)] @@ -111,7 +120,7 @@ (deftest execute-command-in-container (testing "Executing a command in the running Docker container" - (let [container (sut/create {:image-name "postgres:12.2" + (let [container (sut/create {:image-name "postgres:15.3" :exposed-ports [5432] :env-vars {"POSTGRES_PASSWORD" "pw"}}) initialized-container (sut/start! container) @@ -123,7 +132,7 @@ (deftest init-volume-test (testing "Testing mapping of a classpath resource" - (let [container (-> (sut/create {:image-name "postgres:12.2" + (let [container (-> (sut/create {:image-name "postgres:15.3" :exposed-ports [5432] :env-vars {"POSTGRES_PASSWORD" "pw"}}) (sut/map-classpath-resource! {:resource-path "test.sql" @@ -140,7 +149,7 @@ (is (nil? (:mapped-ports stopped-container))))) (testing "Testing mapping of a filesystem-binding" - (let [container (-> (sut/create {:image-name "postgres:12.2" + (let [container (-> (sut/create {:image-name "postgres:15.3" :exposed-ports [5432] :env-vars {"POSTGRES_PASSWORD" "pw"}}) (sut/bind-filesystem! {:host-path "." @@ -157,7 +166,7 @@ (is (nil? (:mapped-ports stopped-container))))) (testing "Copying a file from the host into the container" - (let [container (-> (sut/create {:image-name "postgres:12.2" + (let [container (-> (sut/create {:image-name "postgres:15.3" :exposed-ports [5432] :env-vars {"POSTGRES_PASSWORD" "pw"}}) (sut/copy-file-to-container! {:path "test.sql" @@ -175,7 +184,7 @@ (testing "Copying a file from the classpath into the container" - (let [container (-> (sut/create {:image-name "postgres:12.2" + (let [container (-> (sut/create {:image-name "postgres:15.3" :exposed-ports [5432] :env-vars {"POSTGRES_PASSWORD" "pw"}}) (sut/copy-file-to-container! {:path "test.sql" @@ -192,7 +201,7 @@ (is (nil? (:mapped-ports stopped-container))))) (testing "Copying a file from the host into a running container" - (let [container (sut/create {:image-name "postgres:12.2" + (let [container (sut/create {:image-name "postgres:15.3" :exposed-ports [5432] :env-vars {"POSTGRES_PASSWORD" "pw"}}) initialized-container (sut/start! container) @@ -211,7 +220,7 @@ (is (nil? (:mapped-ports stopped-container))))) (testing "Copying a file from the classpath into a running container" - (let [container (sut/create {:image-name "postgres:12.2" + (let [container (sut/create {:image-name "postgres:15.3" :exposed-ports [5432] :env-vars {"POSTGRES_PASSWORD" "pw"}}) initialized-container (sut/start! container)