Extract function
This commit is contained in:
parent
ea848bc9c5
commit
d9e9b9724d
2 changed files with 21 additions and 17 deletions
|
|
@ -11,23 +11,27 @@
|
|||
BindMode/READ_WRITE
|
||||
BindMode/READ_ONLY))
|
||||
|
||||
(defn create
|
||||
(defn init
|
||||
"Sets the properties for a testcontainer instance"
|
||||
[{:keys [container image-name exposed-ports env-vars command]}]
|
||||
(let [container (or container (GenericContainer. image-name))]
|
||||
(.setExposedPorts container (map int exposed-ports))
|
||||
[{:keys [container exposed-ports env-vars command]}]
|
||||
(.setExposedPorts container (map int exposed-ports))
|
||||
|
||||
(if (some? env-vars)
|
||||
(doseq [pair env-vars]
|
||||
(.addEnv container (first pair) (second pair))))
|
||||
(when (some? env-vars)
|
||||
(doseq [pair env-vars]
|
||||
(.addEnv container (first pair) (second pair))))
|
||||
|
||||
(if (some? command)
|
||||
(.setCommand container command))
|
||||
(when (some? command)
|
||||
(.setCommand container command))
|
||||
|
||||
{:container container
|
||||
:exposed-ports (.getExposedPorts container)
|
||||
:env-vars (.getEnvMap container)
|
||||
:host (.getHost container)}))
|
||||
{:container container
|
||||
:exposed-ports (.getExposedPorts container)
|
||||
:env-vars (.getEnvMap container)
|
||||
:host (.getHost container)})
|
||||
|
||||
(defn create
|
||||
"Creates a generic testcontainer and sets its properties"
|
||||
[{:keys [image-name] :as options}]
|
||||
(init (assoc options :container (GenericContainer. image-name))))
|
||||
|
||||
(defn map-classpath-resource!
|
||||
"Maps a resource in the classpath to the given container path. Should be called before starting the container!"
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
(:import [org.testcontainers.containers
|
||||
PostgreSQLContainer]))
|
||||
|
||||
(deftest init-test
|
||||
(deftest create-test
|
||||
(testing "Testing basic testcontainer generic image initialisation"
|
||||
(let [container (create {:image-name "postgres:12.2"
|
||||
:exposed-ports [5432]
|
||||
|
|
@ -30,9 +30,9 @@
|
|||
(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"}})
|
||||
(let [container (init {: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)]
|
||||
|
|
|
|||
Loading…
Reference in a new issue