Allow for provision of a Testcontainer instance
Testcontainers provides many different container implementations that can be very useful. This simple change allows callers to provide their own, premade container instance so consumers can flexibly choose their container type. If no container instance is supplied, then clj-test-containers falls back to its original behavior.
This commit is contained in:
parent
a3fda15a49
commit
ea848bc9c5
3 changed files with 18 additions and 5 deletions
|
|
@ -9,5 +9,6 @@
|
||||||
:plugins [[metosin/bat-test "0.4.4"]]
|
:plugins [[metosin/bat-test "0.4.4"]]
|
||||||
:bat-test {:report [:pretty {:type :junit
|
:bat-test {:report [:pretty {:type :junit
|
||||||
:output-to "target/junit.xml"}]}
|
:output-to "target/junit.xml"}]}
|
||||||
|
:profiles {:dev {:dependencies [[org.testcontainers/postgresql "1.14.3"]]}}
|
||||||
:target-path "target/%s")
|
:target-path "target/%s")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,8 @@
|
||||||
|
|
||||||
(defn create
|
(defn create
|
||||||
"Sets the properties for a testcontainer instance"
|
"Sets the properties for a testcontainer instance"
|
||||||
[{:keys [image-name exposed-ports env-vars command]}]
|
[{:keys [container image-name exposed-ports env-vars command]}]
|
||||||
(let [container (GenericContainer. image-name)]
|
(let [container (or container (GenericContainer. image-name))]
|
||||||
(.setExposedPorts container (map int exposed-ports))
|
(.setExposedPorts container (map int exposed-ports))
|
||||||
|
|
||||||
(if (some? env-vars)
|
(if (some? env-vars)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
(ns clj-test-containers.core-test
|
(ns clj-test-containers.core-test
|
||||||
(:require [clojure.test :refer :all]
|
(:require [clojure.test :refer :all]
|
||||||
[clj-test-containers.core :refer :all]))
|
[clj-test-containers.core :refer :all])
|
||||||
|
(:import [org.testcontainers.containers
|
||||||
|
PostgreSQLContainer]))
|
||||||
|
|
||||||
(deftest init-test
|
(deftest init-test
|
||||||
(testing "Testing basic testcontainer generic image initialisation"
|
(testing "Testing basic testcontainer generic image initialisation"
|
||||||
|
|
@ -25,6 +27,16 @@
|
||||||
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)))))
|
||||||
|
|
||||||
|
(testing "Executing a command in the running Docker container with a custom container"
|
||||||
|
(let [container (create {:container (PostgreSQLContainer. "postgres:12.2")
|
||||||
|
:exposed-ports [5432]
|
||||||
|
:env-vars {"POSTGRES_PASSWORD" "pw"}})
|
||||||
|
initialized-container (start! container)
|
||||||
|
result (execute-command! initialized-container ["whoami"])
|
||||||
|
stopped-container (stop! container)]
|
||||||
|
(is (= 0 (:exit-code result)))
|
||||||
(is (= "root\n" (:stdout result))))))
|
(is (= "root\n" (:stdout result))))))
|
||||||
|
|
||||||
(deftest init-volume-test
|
(deftest init-volume-test
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue