Merge branch 'master' of github.com:javahippie/clj-test-containers

This commit is contained in:
Tim Zöller 2021-08-18 10:53:06 +02:00
commit 0b1031c083
2 changed files with 14 additions and 15 deletions

View file

@ -1,7 +1,5 @@
# clj-test-containers # clj-test-containers
[![javahippie](https://circleci.com/gh/javahippie/clj-test-containers.svg?style=svg)](<LINK>)
[![Clojars Project](http://clojars.org/clj-test-containers/latest-version.svg)](http://clojars.org/clj-test-containers) [![Clojars Project](http://clojars.org/clj-test-containers/latest-version.svg)](http://clojars.org/clj-test-containers)
## What it is ## What it is
@ -24,7 +22,7 @@ The library provides a set of functions to interact with the testcontainers. A s
(tc/bind-filesystem! {:host-path "/tmp" (tc/bind-filesystem! {:host-path "/tmp"
:container-path "/opt" :container-path "/opt"
:mode :read-only}) :mode :read-only})
(tc/start!)) (tc/start!)))
(do-database-testing (:host container) (do-database-testing (:host container)
(get (:mapped-ports container) 5432)) (get (:mapped-ports container) 5432))
@ -41,7 +39,7 @@ If you'd rather create a container from a Dockerfile in your project, it could l
(def container (-> (tc/create-from-docker-file {:env-vars {"FOO" "bar"} (def container (-> (tc/create-from-docker-file {:env-vars {"FOO" "bar"}
:exposed-ports [80] :exposed-ports [80]
:docker-file "resources/Dockerfile"}) :docker-file "resources/Dockerfile"})
(tc/start!)) (tc/start!)))
``` ```
If you prefer to use prebuilt containers from the Testcontainers project, you can do it like this If you prefer to use prebuilt containers from the Testcontainers project, you can do it like this
@ -52,7 +50,7 @@ If you prefer to use prebuilt containers from the Testcontainers project, you ca
(def container (-> (tc/init {:container (PostgreSQLContainer. "postgres:12.2") (def container (-> (tc/init {:container (PostgreSQLContainer. "postgres:12.2")
:exposed-ports [5432]}) :exposed-ports [5432]})
(tc/start!)) (tc/start!)))
``` ```
## Functions and Properties ## Functions and Properties
@ -229,7 +227,7 @@ Starts the Testcontainer, which was defined by `create`
```clojure ```clojure
(def container (create {:image-name "alpine:3.2" (def container (create {:image-name "alpine:3.2"
:exposed-ports [80] :exposed-ports [80]
:env-vars {"MAGIC_NUMBER" "42"}) :env-vars {"MAGIC_NUMBER" "42"}}))
(start! container) (start! container)
``` ```
@ -255,7 +253,7 @@ The `container-config`
```clojure ```clojure
(def container (create {:image-name "alpine:3.2" (def container (create {:image-name "alpine:3.2"
:exposed-ports [80] :exposed-ports [80]
:env-vars {"MAGIC_NUMBER" "42"}) :env-vars {"MAGIC_NUMBER" "42"}}))
(start! container) (start! container)
(stop! container) (stop! container)
@ -404,7 +402,7 @@ Creates a network. The optional map accepts config values for enabling ipv6 and
```clojure ```clojure
;;Create with config ;;Create with config
(create-network {:ipv6 false (create-network {:ipv6 false
:driver "overlay") :driver "overlay"})
;;Create with default config ;;Create with default config
(create-network) (create-network)

View file

@ -17,7 +17,8 @@
(org.testcontainers.images.builder (org.testcontainers.images.builder
ImageFromDockerfile) ImageFromDockerfile)
(org.testcontainers.utility (org.testcontainers.utility
MountableFile))) MountableFile
ResourceReaper)))
(defn- resolve-bind-mode (defn- resolve-bind-mode
(^BindMode [bind-mode] (^BindMode [bind-mode]
@ -27,7 +28,7 @@
(defn- reaper-instance (defn- reaper-instance
[] []
(org.testcontainers.utility.ResourceReaper/instance)) (ResourceReaper/instance))
(defmulti wait (defmulti wait
"Sets a wait strategy to the container. Supports :http, :health and :log as "Sets a wait strategy to the container. Supports :http, :health and :log as
@ -278,10 +279,10 @@
[port] [port]
[port (.getMappedPort container port)]) [port (.getMappedPort container port)])
mapped-ports (into {} (map map-port) exposed-ports) mapped-ports (into {} (map map-port) exposed-ports)
container-id (.getContainerId container) container-id ^String (.getContainerId container)
image-name (.getDockerImageName container) image-name ^String (.getDockerImageName container)
logger (log log-to container)] logger (log log-to container)]
(.registerContainerForCleanup (reaper-instance) (.registerContainerForCleanup ^ResourceReaper (reaper-instance)
container-id container-id
image-name) image-name)
(-> container-config (-> container-config
@ -317,7 +318,7 @@
(let [network (.build builder) (let [network (.build builder)
network-name (.getName network)] network-name (.getName network)]
(.registerNetworkIdForCleanup (reaper-instance) network-name) (.registerNetworkIdForCleanup ^ResourceReaper (reaper-instance) network-name)
{:network network {:network network
:name network-name :name network-name
:ipv6 (.getEnableIpv6 network) :ipv6 (.getEnableIpv6 network)
@ -328,7 +329,7 @@
(defn perform-cleanup! (defn perform-cleanup!
"Stops and removes all container instances which were created in the active JVM or REPL session" "Stops and removes all container instances which were created in the active JVM or REPL session"
[] []
(.performCleanup (reaper-instance))) (.performCleanup ^ResourceReaper (reaper-instance)))
;;; REPL Helpers ;;; REPL Helpers