Use .copyFileToContainer when the container is already started (#44)
This commit is contained in:
parent
f7befdf86d
commit
43d573e6f5
5 changed files with 59 additions and 11 deletions
|
|
@ -1,3 +1,5 @@
|
|||
{:file-pattern #"\.(clj[sc]?|edn|cljstyle)$"
|
||||
:list-indent-size 1
|
||||
:padding-lines 1}
|
||||
{:files {:pattern #"\.(clj[sc]?|edn|cljstyle)$"},
|
||||
:rules
|
||||
{:indentation {:list-indent 1},
|
||||
:blank-lines {:padding-lines 1},
|
||||
:namespaces {:indent-size 1}}}
|
||||
|
|
|
|||
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -12,3 +12,4 @@ pom.xml.asc
|
|||
.hg/
|
||||
.DS_Store
|
||||
.lsp
|
||||
.cpcache
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
[lambdaisland/kaocha-cloverage "1.0-45"]
|
||||
[lambdaisland/kaocha-junit-xml "0.0.76"]
|
||||
[lambdaisland/kaocha-junit-xml "0.0.76"]
|
||||
[mvxcvi/cljstyle "0.13.0" :exclusions [org.clojure/clojure]]
|
||||
[mvxcvi/cljstyle "0.14.0" :exclusions [org.clojure/clojure]]
|
||||
[org.clojure/test.check "1.1.0"]
|
||||
[org.clojure/tools.namespace "1.0.0"]
|
||||
[org.testcontainers/postgresql "1.15.0-rc2"]]
|
||||
|
|
|
|||
|
|
@ -195,18 +195,24 @@
|
|||
(resolve-bind-mode mode))))
|
||||
|
||||
(defn copy-file-to-container!
|
||||
"Copies a file into the running container"
|
||||
[{:keys [^GenericContainer container] :as container-config}
|
||||
"If a container is not yet started, adds a mapping from mountable file to
|
||||
container path that will be copied to the container on startup. If the
|
||||
container is already running, copy the file to the running container."
|
||||
[{:keys [^GenericContainer container id] :as container-config}
|
||||
{:keys [^String container-path ^String path type]}]
|
||||
(let [^MountableFile mountable-file
|
||||
(case type
|
||||
:classpath-resource (MountableFile/forClasspathResource path)
|
||||
:host-path (MountableFile/forHostPath path))]
|
||||
(assoc container-config
|
||||
:container
|
||||
(.withCopyFileToContainer container
|
||||
mountable-file
|
||||
container-path))))
|
||||
(if id
|
||||
(do
|
||||
(.copyFileToContainer container mountable-file container-path)
|
||||
container-config)
|
||||
(assoc container-config
|
||||
:container
|
||||
(.withCopyFileToContainer container
|
||||
mountable-file
|
||||
container-path)))))
|
||||
|
||||
(defn execute-command!
|
||||
"Executes a command in the container, and returns the result"
|
||||
|
|
|
|||
|
|
@ -126,6 +126,7 @@
|
|||
(is (nil? (:id stopped-container)))
|
||||
(is (nil? (:mapped-ports stopped-container)))))
|
||||
|
||||
|
||||
(testing "Copying a file from the classpath into the container"
|
||||
(let [container (-> (sut/create {:image-name "postgres:12.2"
|
||||
:exposed-ports [5432]
|
||||
|
|
@ -141,6 +142,44 @@
|
|||
(is (some? (get (:mapped-ports initialized-container) 5432)))
|
||||
(is (= 0 (:exit-code file-check)))
|
||||
(is (nil? (:id stopped-container)))
|
||||
(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"
|
||||
:exposed-ports [5432]
|
||||
:env-vars {"POSTGRES_PASSWORD" "pw"}})
|
||||
initialized-container (sut/start! container)
|
||||
_ (sut/copy-file-to-container! initialized-container
|
||||
{:path "test.sql"
|
||||
:container-path "/opt/test.sql"
|
||||
:type :host-path})
|
||||
file-check (sut/execute-command! initialized-container
|
||||
["tail" "/opt/test.sql"])
|
||||
stopped-container (sut/stop! container)]
|
||||
(is (some? (:id initialized-container)))
|
||||
(is (some? (:mapped-ports initialized-container)))
|
||||
(is (some? (get (:mapped-ports initialized-container) 5432)))
|
||||
(is (= 0 (:exit-code file-check)))
|
||||
(is (nil? (:id stopped-container)))
|
||||
(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"
|
||||
:exposed-ports [5432]
|
||||
:env-vars {"POSTGRES_PASSWORD" "pw"}})
|
||||
initialized-container (sut/start! container)
|
||||
_ (sut/copy-file-to-container! initialized-container
|
||||
{:path "test.sql"
|
||||
:container-path "/opt/test.sql"
|
||||
:type :classpath-resource})
|
||||
file-check (sut/execute-command! initialized-container
|
||||
["tail" "/opt/test.sql"])
|
||||
stopped-container (sut/stop! container)]
|
||||
(is (some? (:id initialized-container)))
|
||||
(is (some? (:mapped-ports initialized-container)))
|
||||
(is (some? (get (:mapped-ports initialized-container) 5432)))
|
||||
(is (= 0 (:exit-code file-check)))
|
||||
(is (nil? (:id stopped-container)))
|
||||
(is (nil? (:mapped-ports stopped-container))))))
|
||||
|
||||
(deftest networking-test
|
||||
|
|
|
|||
Loading…
Reference in a new issue