Liking cljdoc? Tell your friends :D

clj-test-containers.core


bind-filesystem!clj

(bind-filesystem! {:keys [container] :as container-config}
                  {:keys [host-path container-path mode]})

Binds a source from the filesystem to the given container path. Should be called before starting the container!

Binds a source from the filesystem to the given container path. Should be
called before starting the container!
sourceraw docstring

copy-file-to-container!clj

(copy-file-to-container! {:keys [container id] :as container-config}
                         {:keys [container-path path type]})

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.

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.
sourceraw docstring

createclj

(create {:keys [image-name] :as options})

Creates a generic testcontainer and sets its properties

Creates a generic testcontainer and sets its properties
sourceraw docstring

create-from-docker-fileclj

(create-from-docker-file {:keys [docker-file] :as options})

Creates a testcontainer from a provided Dockerfile

Creates a testcontainer from a provided Dockerfile
sourceraw docstring

create-networkclj

(create-network)
(create-network {:keys [ipv6 driver]})

Creates a network. The optional map accepts config values for enabling ipv6 and setting the driver

Creates a network. The optional map accepts config values for enabling ipv6
and setting the driver
sourceraw docstring

dump-logsclj

(dump-logs container-config)

Dumps the logs found by invoking the function on the :string-log key

Dumps the logs found by invoking the function on the :string-log key
sourceraw docstring

execute-command!clj

(execute-command! {:keys [container]} command)

Executes a command in the container, and returns the result

Executes a command in the container, and returns the result
sourceraw docstring

initclj

(init {:keys [container exposed-ports env-vars command network network-aliases
              wait-for]
       :as init-options})

Sets the properties for a testcontainer instance

Sets the properties for a testcontainer instance
sourceraw docstring

init-networkcljdeprecated

source

logcljmultimethod

Sets a log strategy on the container as a means of accessing the container logs.

String Strategy

The :string strategy sets up a function in the returned map, under the string-log key. This function enables the dumping of the logs when passed to the dump-logs function.

Example:

{:log-strategy :string}

Then, later in your program, you can access the logs thus:

(def container-config (tc/start! container))
(tc/dump-logs container-config)

Function Strategy

The :fn strategy accepts an additional parameter :function in the configuration map, which allows you to pass a function to the Testcontainers log mechanism which accepts a single String parameter and gets called for every log line. This way you can pass the container logging on to the logging library of your choice.

Example:

{:log-strategy :fn
 :function (fn [log-line] (println "From Container: " log-line)}
Sets a log strategy on the container as a means of accessing the container logs.

## String Strategy
The `:string` strategy sets up a function in the returned map, under the
`string-log` key. This function enables the dumping of the logs when passed to
the `dump-logs` function.

Example:

```clojure
{:log-strategy :string}
```

Then, later in your program, you can access the logs thus:

```clojure
(def container-config (tc/start! container))
(tc/dump-logs container-config)
```

## Function Strategy
The `:fn` strategy accepts an additional parameter `:function` in the configuration
map, which allows you to pass a function to the Testcontainers log mechanism
which accepts a single String parameter and gets called for every log line. This
way you can pass the container logging on to the logging library of your choice.

Example:
```clojure
{:log-strategy :fn
 :function (fn [log-line] (println "From Container: " log-line)}
```
 
sourceraw docstring

map-classpath-resource!clj

(map-classpath-resource! {:keys [container] :as container-config}
                         {:keys [resource-path container-path mode]})

Maps a resource in the classpath to the given container path. Should be called before starting the container!

Maps a resource in the classpath to the given container path. Should be
called before starting the container!
sourceraw docstring

perform-cleanup!clj

(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
sourceraw docstring

start!clj

(start! {:keys [container log-to exposed-ports] :as container-config})

Starts the underlying testcontainer instance and adds new values to the response map, e.g. :id and :first-mapped-port

Starts the underlying testcontainer instance and adds new values to the
response map, e.g. :id and :first-mapped-port
sourceraw docstring

started-instancesclj

source

stop!clj

(stop! {:keys [container] :as container-config})

Stops the underlying container

Stops the underlying container
sourceraw docstring

waitcljmultimethod

Sets a wait strategy to the container. Supports :http, :health and :log as strategies.

HTTP Strategy

The :http strategy will only accept the container as initialized if it can be accessed via HTTP. It accepts a path, a port, a vector of status codes, a boolean that specifies if TLS is enabled, a read timeout in seconds and a map with basic credentials, containing username and password. Only the path is required, all others are optional.

Example:

(wait {:wait-strategy :http
       :port 80
       :path "/"
       :status-codes [200 201]
       :tls true
       :read-timeout 5
       :basic-credentials {:username "user"
                           :password "password"
       :startup-timeout 60}}
      container)

Health Strategy

The :health strategy enables support for Docker's healthcheck feature, whereby you can directly leverage the healthy state of your container as your wait condition.

Example:

(wait {:wait-strategy :health
       :startup-timeout 60} container)

Log Strategy

The :log strategy accepts a message which simply causes the output of your container's log to be used in determining if the container is ready or not. The output is grepped against the log message.

Example:

(wait {:wait-strategy :log
       :message "accept connections"
       :startup-timeout 60} container)

Port Strategy

The port strategy waits for the first of the mapped ports to be opened. It only accepts the startup-timeout value as a parameter.

Example:

(wait {:wait-strategy :port
       :startup-timeout 60} container
Sets a wait strategy to the container.  Supports :http, :health and :log as
strategies.

## HTTP Strategy
The :http strategy will only accept the container as initialized if it can be
accessed via HTTP. It accepts a path, a port, a vector of status codes, a
boolean that specifies if TLS is enabled, a read timeout in seconds and a map
with basic credentials, containing username and password. Only the path is
required, all others are optional.

Example:

```clojure
(wait {:wait-strategy :http
       :port 80
       :path "/"
       :status-codes [200 201]
       :tls true
       :read-timeout 5
       :basic-credentials {:username "user"
                           :password "password"
       :startup-timeout 60}}
      container)
```

## Health Strategy
The :health strategy enables support for Docker's healthcheck feature,
whereby you can directly leverage the healthy state of your container as your wait condition.

Example:

```clojure
(wait {:wait-strategy :health
       :startup-timeout 60} container)
```

## Log Strategy
The :log strategy accepts a message which simply causes the output of your
container's log to be used in determining if the container is ready or not.
The output is `grepped` against the log message.

Example:

```clojure
(wait {:wait-strategy :log
       :message "accept connections"
       :startup-timeout 60} container)
```

## Port Strategy
The port strategy waits for the first of the mapped ports to be opened. It only accepts the startup-timeout
value as a parameter.

Example:

```clojure
(wait {:wait-strategy :port
       :startup-timeout 60} container
```
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close