Compare commits

...

43 commits
0.4.0 ... main

Author SHA1 Message Date
Eddú Meléndez Gonzales
802f18af55
Update GHA versions (#80)
* actions/setup-java@v4
* actions/cache@v4
* actions/checkout@v4
2024-04-16 07:53:09 -05:00
Tim Zöller
1297054b77 Updated dependency versions 2024-04-13 09:32:57 +02:00
Tim Zöller
233c3883eb
Make config clearer in log-strategies.md (#73) (#77)
This wasn't working for me because nothing in here says it all needs to be the value a `:log-to` key in the container config map. Reading the code and adding that made it work. Figured it might be nice to clarify that for others too.

Co-authored-by: Wes Morgan <github@wesmorgan.me>
2024-04-13 09:08:45 +02:00
Ukpono Nnah
49f547585e
tutorial.md: Fix let bindings (#75)
Fix let bindings uneven form
2024-04-13 09:06:01 +02:00
Eddú Meléndez
874d5756af
Update branch to main 2023-08-24 15:57:19 -06:00
Eddú Meléndez Gonzales
9bf75d6387
Add release workflow (#70) 2023-08-24 14:47:48 -06:00
Tim Zöller
8c807a8750
Update testcontainers version to 1.19.0 (#69) 2023-08-23 18:10:26 -06:00
Tim Zöller
390563ac1d Updated project dependencies (#67) 2022-11-16 22:56:32 +01:00
Tim Zöller
667a2d0850 Refactored cleanup to not use deprecated methods anymore (#66) 2022-11-16 22:50:44 +01:00
Tim Zöller
94e582a1aa Upgraded to latest testcontainers-java version (#65) 2022-11-16 15:10:17 +01:00
Brendon Wong
100a938250
The parameter for copy-file-to-container! is container-path not host-path. (#64) 2022-10-06 11:44:46 +02:00
Tim Zöller
25d1ba491b Prepare Release 0.7.3 2022-09-30 12:30:57 +02:00
Tim Zöller
35454d3fd2 Upgrade to testcontainers-java 1.17.4 (#63) 2022-09-30 12:23:59 +02:00
Tim Zöller
1bf2c205c1 Applied automatic styling 2022-07-03 17:22:00 +02:00
Tim Zöller
5464fc35fa Bumped to testcontainers-java 1.17.3 2022-07-03 17:20:21 +02:00
Tim Zöller
d9a42decb2 Fixed deps.edn versios 2022-06-12 14:00:15 +02:00
Tim Zöller
dd517094ce Fixed changelog, set release version 2022-06-12 11:33:45 +02:00
Tim Zöller
fffb398918 Use nginx Docker image for HTTP wait status test 2022-06-12 11:30:56 +02:00
Tim Zöller
e57261ce12 Added allow-insecure flag (#58) 2022-05-25 09:08:32 +02:00
Tim Zöller
ba77335753 Dependency update to Testcontainers 1.17.2 (#57) 2022-05-25 09:00:21 +02:00
Tim Zöller
d246351551 Dependency update to Testcontainers 1.17.1 (#56) 2022-04-23 09:43:15 +02:00
Tim Zöller
a635113b7e Prepare Release 2022-03-26 12:04:53 +01:00
Tim Zöller
fd06f2fe6c Changelog 2022-03-26 11:59:50 +01:00
Tim Zöller
dad4ddbd0f Corrected Markdown links 2022-03-26 11:56:58 +01:00
Tim Zöller
c42886ba56 Added :fn log strategy (#41) 2022-03-26 11:54:28 +01:00
Tim Zöller
a53cf9e271 Documentation for 0.6.0 2022-03-25 22:59:14 +01:00
Tim Zöller
791708bf51 Minor changes, release preparations 2022-03-21 19:24:33 +01:00
Tim Zöller
28b0183339 Applied autoformatter 2022-03-18 14:05:20 +01:00
Tim Zöller
71af11f503 Extended config for wait strategies (#42) 2022-03-18 14:03:42 +01:00
Tim Zöller
6e94e86745 Resolved dependency issues 2022-03-18 11:48:59 +01:00
Tim Zöller
fc70760de7 Bumped TC dependency to 1.16.3 2022-03-17 13:10:48 +01:00
Tim Zöller
d1036e1ff3 Set version to 0.6.0-SNAPSHOT 2021-08-18 11:07:34 +02:00
Tim Zöller
1dacbe6e78 Prepared Release 0.5.0 2021-08-18 10:59:35 +02:00
Tim Zöller
0b1031c083 Merge branch 'master' of github.com:javahippie/clj-test-containers 2021-08-18 10:53:06 +02:00
Tim Zöller
5c6dbed46e Updated Testcontainers version to 1.16.0 2021-08-18 10:51:33 +02:00
Gilles Philippart
b13499bc7c
Fix unbalanced parens and braces (#52) 2021-06-01 19:52:04 +02:00
Andrea Richiardi
12c4b6c1e9
[Fix #50] Add type hints for ResourceReaper (#51) 2021-03-09 09:26:47 +01:00
Tim Zöller
ff1215e710
Removed CircleCI badge 2021-03-04 15:43:37 +01:00
Tim Zöller
d6e4b065cd Removed Circle CI from builds 2021-03-04 15:43:00 +01:00
Tim Zöller
7be77af93b Merge branch 'master' of https://github.com/javahippie/clj-test-containers into master 2021-03-04 15:42:26 +01:00
Tim Zöller
2b8d4a911e #49 - Bumped to Testcontainers 1.15.2 2021-03-04 15:42:08 +01:00
Tim Zöller
51314ae2e7
Set up GitHub Action 2021-02-28 15:31:39 +01:00
Tim Zöller
13c859dee2 New Snapshot version 2020-12-16 10:43:12 +01:00
16 changed files with 804 additions and 419 deletions

View file

@ -1,49 +0,0 @@
# Clojure CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-clojure/ for more details
#
version: 2
jobs:
build:
machine:
image: ubuntu-1604:202004-01
working_directory: ~/repo
environment:
# Customize the JVM maximum heap limit
JVM_OPTS: -Xmx3200m
steps:
- checkout
# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "project.clj" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- run:
name: Install Leiningen
command: wget https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein && chmod a+x lein && lein --version
- run: lein deps
- save_cache:
paths:
- ~/.lein
- ~/.m2
key: v1-dependencies-{{ checksum "project.clj" }}
# check syntax and warn on reflection
- run: lein check
# run tests!
- run: lein test
# check style
- run: lein cljstyle check --report
- store_test_results:
path: target

18
.github/actions/setup-build/action.yml vendored Normal file
View file

@ -0,0 +1,18 @@
name: Set up Build
description: Sets up Build
runs:
using: "composite"
steps:
- uses: actions/setup-java@v4
with:
java-version: '8'
distribution: temurin
- name: Cache dependencies
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-lein-${{ hashFiles('**/project.clj') }}
restore-keys: ${{ runner.os }}-lein-
- name: Clear existing docker image cache
shell: bash
run: docker image prune -af

22
.github/workflows/clojure.yml vendored Normal file
View file

@ -0,0 +1,22 @@
name: Clojure CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Build
uses: ./.github/actions/setup-build
- name: Install dependencies
run: lein deps
- name: Run tests
run: lein test

28
.github/workflows/release.yml vendored Normal file
View file

@ -0,0 +1,28 @@
name: Release
on:
release:
types: [published]
permissions:
contents: read
jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Build
uses: ./.github/actions/setup-build
- name: Set version
run: |
lein change version set '"${{github.event.release.tag_name}}"'
- name: Release ${{github.event.release.tag_name}}
run: lein with-profile release deploy maven
env:
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}

3
.gitignore vendored
View file

@ -8,8 +8,11 @@ pom.xml.asc
/.lein-*
/.nrepl-history
/.nrepl-port
.clj-kondo/
.hgignore
.hg/
.DS_Store
.lsp
.cpcache
/.idea/
/clj-test-containers.iml

View file

@ -1,6 +1,46 @@
# Change Log
All notable changes to this project will be documented in this file. This change log follows the conventions of [keepachangelog.com](http://keepachangelog.com/).
## [0.7.4] - 2022-11-16
### Changed
- [#64](https://github.com/javahippie/clj-test-containers/pull/64): Fix container path parameter for copy-file-to-container! in README
- [#65](https://github.com/javahippie/clj-test-containers/issues/65): Upgrade to testcontainers-java 1.17.6
- [#66](https://github.com/javahippie/clj-test-containers/issues/66): Remove usage of deprecated API calls for cleanup
- [#67](https://github.com/javahippie/clj-test-containers/issues/67): Update Dependencies
## [0.7.3] - 2202-09-30
### Changed
- [#63](https://github.com/javahippie/clj-test-containers/issues/63): Upgrade to testcontainers-java 1.17.4
## [0.7.2] - 2202-07-03
### Changed
- [#61](https://github.com/javahippie/clj-test-containers/issues/61): Upgrade to testcontainers-java 1.17.3
## [0.7.1] - 2202-06-12
### Added
- [#58](https://github.com/javahippie/clj-test-containers/issues/58): Add new `allowInsecure` flag to the HTTP wait strategy
### Changed
- [#57](https://github.com/javahippie/clj-test-containers/issues/57): Upgrade to testcontainers-java 1.17.2
## [0.7.0] - 2022-04-23
### Changed
- [#56](https://github.com/javahippie/clj-test-containers/issues/56): Update to Testcontainers 1.17.1
## [0.6.0] - 2022-03-26
### Changed
- [#55](https://github.com/javahippie/clj-test-containers/issues/55): Upgrade to latest Testcontainers version
### Added
- [#42](https://github.com/javahippie/clj-test-containers/issues/42): Extend wait strategies
- [#41](https://github.com/javahippie/clj-test-containers/issues/41): Complete logging mechanisms
## [0.5.0] - 2021-08-18
### Changed
- [#49](https://github.com/javahippie/clj-test-containers/issues/49): Updated to latest Testcontainers version
- [#50](https://github.com/javahippie/clj-test-containers/issues/50): supress Reflection warnings
- [#52](https://github.com/javahippie/clj-test-containers/pull/52): Fix unbalanced parens and braces
## [0.4.0] - 2020-12-16
### Added
- [#43](https://github.com/javahippie/clj-test-containers/issues/43): Provide a way to remove all running testcontainers instances in a REPL session
@ -12,7 +52,7 @@ All notable changes to this project will be documented in this file. This change
## [0.3.0] - 2020-10-23
### Added
- [#25](https://github.com/javahippie/clj-test-containers/issues/25): Add support for a container wait stategy
- [#25](https://github.com/javahippie/clj-test-containers/issues/25): Add support for a container wait strategy
- [#35](https://github.com/javahippie/clj-test-containers/issues/35): Add support for docker version 2.4.0 - upgrading testcontainers-java version
- [#27](https://github.com/javahippie/clj-test-containers/issues/27): Add support for accessing container logs
- [#38](https://github.com/javahippie/clj-test-containers/pull/38): Add type hints to silence reflection warnings

View file

@ -1,19 +1,24 @@
# 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)
## What it is
This library is a lightweight wrapper around the [Testcontainers Java library](https://www.testcontainers.org/).
## What it isn't
This library does not provide tools to include testcontainers in your testing lifecycle. As there are many different test tools with different approaches to testing in the clojure world, handling the lifecycle is up to you.
This library does not provide tools to include testcontainers in your testing lifecycle. As there are many different
test tools with different approaches to testing in the clojure world, handling the lifecycle is up to you.
## Integration with test runners
There is an [experimental kaocha plugin](https://github.com/lambdaschmiede/kaocha-testcontainers-plugin) you can try out
## Usage
The library provides a set of functions to interact with the testcontainers. A simple example, how to create a container with a Docker label, could look like this:
The library provides a set of functions to interact with the testcontainers. A simple example, how to create a container
with a Docker label, could look like this:
```clojure
(require '[clj-test-containers.core :as tc])
@ -24,7 +29,7 @@ The library provides a set of functions to interact with the testcontainers. A s
(tc/bind-filesystem! {:host-path "/tmp"
:container-path "/opt"
:mode :read-only})
(tc/start!))
(tc/start!)))
(do-database-testing (:host container)
(get (:mapped-ports container) 5432))
@ -41,7 +46,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"}
:exposed-ports [80]
: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
@ -52,26 +57,27 @@ If you prefer to use prebuilt containers from the Testcontainers project, you ca
(def container (-> (tc/init {:container (PostgreSQLContainer. "postgres:12.2")
:exposed-ports [5432]})
(tc/start!))
(tc/start!)))
```
## Functions and Properties
### create
Creates a testcontainers instance from a given Docker label and returns them
#### Config parameters:
| Key | Type | Description |
| ------------- | :------------- | :----- |
| ------------- | :------------- |:----------------------------------------------------------------------------------------------------|
| `:image-name` | String, mandatory | The name and label of an image, e.g. `postgres:12.2` |
| `:exposed-ports` | Vector with ints, mandatory | All ports which should be exposed and mapped to a local port |
| `:env-vars` | Map | A map with environment variables |
| `:command` | Vector with strings | The start command of the container |
| `:network` | Map | A map containing the configuration of a Docker Network (see: `create-network`) |
| `:network-aliases` | Map | A list of alias names for the container on the network |
| `:wait-for` | Map | A map containing the wait strategy to use and the condition to check for |
| `:log-to` | Map | A map containing the log strategy to use, e.g. {:log-strategy string} |
| `:wait-for` | Map | A map containing the [wait strategy](doc/wait-strategies.md) to use and the condition to check for |
| `:log-to` | Map | A map containing the [log strategy](doc/log-strategies.md) to use, e.g. {:log-strategy string} |
#### Result:
@ -112,25 +118,27 @@ Creates a testcontainers instance from a given Docker label and returns them
```
### init
Initializes a given Testcontainer, which was e.g. provided by a library
#### Config parameters:
| Key | Type | Description |
| ------------- | :------------- | :----- |
| ------------- | :------------- |:----------------------------------------------------------------------------------------------------|
| `:container` | `org.testcontainers.containers.GenericContainer`, mandatory | The name and label of an image, e.g. `postgres:12.2` |
| `:exposed-ports` | Vector with ints, mandatory | All ports which should be exposed and mapped to a local port |
| `:env-vars` | Map | A map with environment variables |
| `:command` | Vector with strings | The start command of the container |
| `:network` | Map | A map containing the configuration of a Docker Network (see: `create-network`) |
| `:network-aliases` | Map | A list of alias names for the container on the network |
| `:wait-for` | Map | A map containing the wait strategy to use and the condition to check for |
| `:log-to` | Map | A map containing the log strategy to use, e.g. {:log-strategy string} |
| `:wait-for` | Map | A map containing the [wait strategy](doc/wait-strategies.md) to use and the condition to check for |
| `:log-to` | Map | A map containing the [log strategy](doc/log-strategies.md) to use, e.g. {:log-strategy string} |
| | | |
#### Result:
| Key | Type | Description |
| ------------- | :------------- | :----- |
| ------------- | :------------- |:------------------------------------------------------------------------------------------|
| `:container` | `org.testcontainers.containers.Container` | The Testcontainers instance, accessible for everything this library doesn't provide (yet) |
| `:exposed-ports` | Vector with ints | Value of the same input parameter |
| `:env-vars` | Map | Value of the same input parameter |
@ -164,6 +172,7 @@ Initializes a given Testcontainer, which was e.g. provided by a library
```
### create-from-docker-file
Creates a testcontainer from a Dockerfile
#### Config parameters:
@ -176,9 +185,10 @@ Creates a testcontainer from a Dockerfile
| `:command` | Vector with strings | The start command of the container |
| `:network` | Map | A map containing the configuration of a Docker Network (see: `create-network`) |
| `:network-aliases` | Map | A list of alias names for the container on the network |
| `:wait-for` | Map | A map containing the wait strategy to use and the condition to check for |
| `:log-to` | Map | A map containing the log strategy to use, e.g. {:log-strategy string} |
| `:wait-for` | Map | A map containing the [wait strategy](doc/wait-strategies.md) to use and the condition to check for |
| `:log-to` | Map | A map containing the [log strategy](doc/log-strategies.md) to use, e.g. {:log-strategy string} |
| | | |
#### Result:
| Key | Type | Description |
@ -204,6 +214,7 @@ Creates a testcontainer from a Dockerfile
---
### start!
Starts the Testcontainer, which was defined by `create`
#### Config parameters:
@ -215,6 +226,7 @@ Starts the Testcontainer, which was defined by `create`
| | | |
#### Result:
| Key | Type | Description |
| ------------- | :------------- | :----- |
| `:container` | `org.testcontainers.containers.Container` | The Testcontainers instance, accessible for everything this library doesn't provide (yet) |
@ -229,15 +241,15 @@ Starts the Testcontainer, which was defined by `create`
```clojure
(def container (create {:image-name "alpine:3.2"
:exposed-ports [80]
:env-vars {"MAGIC_NUMBER" "42"})
:env-vars {"MAGIC_NUMBER" "42"}}))
(start! container)
```
---
### stop!
Stops the Testcontainer, which was defined by `create`
#### Config parameters:
@ -248,6 +260,7 @@ Stops the Testcontainer, which was defined by `create`
| `container-config` | Map, mandatory | Return value of the `create` function |
#### Result:
The `container-config`
#### Example:
@ -255,7 +268,7 @@ The `container-config`
```clojure
(def container (create {:image-name "alpine:3.2"
:exposed-ports [80]
:env-vars {"MAGIC_NUMBER" "42"})
:env-vars {"MAGIC_NUMBER" "42"}}))
(start! container)
(stop! container)
@ -263,8 +276,8 @@ The `container-config`
---
### map-classpath-resource!
Maps a resource from your classpath into the containers file system
#### Config parameters:
@ -278,8 +291,8 @@ Maps a resource from your classpath into the containers file system
| `:container-path` | String, mandatory | Path, to which the resource should be mapped |
| `:mode` | Keyword, mandatory | `:read-only` or `:read-write` |
#### Result:
The `container-config`
#### Example:
@ -292,8 +305,8 @@ The `container-config`
---
### bind-filesystem!
Binds a path from your local filesystem into the Docker container as a volume
#### Config parameters:
@ -307,8 +320,8 @@ Binds a path from your local filesystem into the Docker container as a volume
| `:container-path` | String, mandatory | Path, to which the resource should be mapped |
| `:mode` | Keyword, mandatory | `:read-only` or `:read-write` |
#### Result:
The `container-config`
#### Example:
@ -321,8 +334,8 @@ The `container-config`
---
### copy-file-to-container!
Copies a file from your filesystem or classpath into the running container
#### Config parameters:
@ -333,11 +346,11 @@ Copies a file from your filesystem or classpath into the running container
| `container-config`| Map, mandatory | Return value of the `create` function |
| Second parameter: | | |
| `:path` | String, mandatory | Path to a classpath resource *or* file on your filesystem |
| `:host-path` | String, mandatory | Path, to which the file should be copied |
| `:container-path` | String, mandatory | Path, to which the file should be copied |
| `:type` | Keyword, mandatory | `:classpath-resource` or `:host-path` |
#### Result:
The `container-config`
#### Example:
@ -350,8 +363,8 @@ The `container-config`
---
### execute-command!
Executes a command in the running container, and returns the result
#### Config parameters:
@ -363,9 +376,8 @@ Executes a command in the running container, and returns the result
| Second parameter: |   |   |
| `command` | Vector with Strings, mandatory | A vector containing the command and its parameters |
#### Result:
| Key | Type | Description |
| ------------- | :------------- | :----- |
| `:exit-code` | int | Exit code of the executed command |
@ -379,8 +391,8 @@ Executes a command in the running container, and returns the result
```
### create-network
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
#### Config parameters:
@ -389,9 +401,8 @@ Creates a network. The optional map accepts config values for enabling ipv6 and
| `:ipv6` | boolean | Should the network enable IPv6? |
| `:driver` | String | The network driver used by Docker, e.g. `bridge` or `host` |
#### Result:
| Key | Type | Description |
| ------------- | :------------- | :----- |
| `:network` | `org.testcontainers.containers.Network` | The instance of the network |
@ -404,34 +415,41 @@ Creates a network. The optional map accepts config values for enabling ipv6 and
```clojure
;;Create with config
(create-network {:ipv6 false
:driver "overlay")
:driver "overlay"})
;;Create with default config
(create-network)
```
### perform-cleanup!
Stops and removes all containers which were created in the JVM, including the REPL session you are in. This is helpful, if you are exploring functionality with containers in the REPL, and create lots of instances on the fly without stopping them. Testcontainers will remove all containers upon JVM shutdown, but the REPL keeps the JVM alive for a long time.
Stops and removes all containers which were created in the JVM, including the REPL session you are in. This is helpful,
if you are exploring functionality with containers in the REPL, and create lots of instances on the fly without stopping
them. Testcontainers will remove all containers upon JVM shutdown, but the REPL keeps the JVM alive for a long time.
#### Config parameters:
None
#### Result:
None
#### Example:
```clojure
(perform-cleanup!)
```
### dump-logs
Call on a started container.
Provided logging was enabled for a container, returns the given log presentation, e.g. as a string
Call on a started container. Provided logging was enabled for a container, returns the given log presentation, e.g. as a
string
| Key | Type | Description |
| ------------- | :------------- | :----- |
| `container-config` | Map, mandatory | The configuration describing the container for which the log should be retrieved |
## License
Distributed under the Eclipse Public License either version 1.0 or (at
your option) any later version.
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

View file

@ -1,26 +1,27 @@
{:paths ["src" "resources"]
:deps {org.clojure/clojure {:mvn/version "1.10.1"}
org.testcontainers/testcontainers {:mvn/version "1.15.0"}}
:deps {org.clojure/clojure {:mvn/version "1.10.3"}
org.testcontainers/testcontainers {:mvn/version "1.19.7"}}
:aliases {:dev {:extra-paths "dev-src"}
:test {:extra-paths ["test" "test/resources"]
:extra-deps {expound/expound {:mvn/version "0.8.5"}
lambdaisland/kaocha {:mvn/version "1.0.700"}
lambdaisland/kaocha-cloverage {:mvn/version "1.0.63"}
lambdaisland/kaocha-junit-xml {:mvn/version "0.0.76"}
org.clojure/test.check {:mvn/version "1.1.0"}
org.testcontainers/postgresql {:mvn/version "1.14.3"}}}
:extra-deps {expound/expound {:mvn/version "0.9.0"}
lambdaisland/kaocha {:mvn/version "1.88.1376"}
lambdaisland/kaocha-cloverage {:mvn/version "1.1.89"}
lambdaisland/kaocha-junit-xml {:mvn/version "1.17.101"}
org.clojure/test.check {:mvn/version "1.1.1"}
org.testcontainers/postgresql {:mvn/version "1.19.7"}}}
:test-runner {:extra-paths ["test" "test/resources"]
:extra-deps {expound/expound {:mvn/version "0.8.5"}
lambdaisland/kaocha {:mvn/version "1.0.700"}
lambdaisland/kaocha-cloverage {:mvn/version "1.0.63"}
lambdaisland/kaocha-junit-xml {:mvn/version "0.0.76"}
org.clojure/test.check {:mvn/version "1.1.0"}
org.testcontainers/postgresql {:mvn/version "1.14.3"}}
:extra-deps {expound/expound {:mvn/version "0.9.0"}
lambdaisland/kaocha {:mvn/version "1.88.1376"}
lambdaisland/kaocha-cloverage {:mvn/version "1.1.89"}
lambdaisland/kaocha-junit-xml {:mvn/version "1.17.101"}
org.clojure/test.check {:mvn/version "1.1.1"}
orchestra {:mvn/version "2021.01.01-1"}
org.testcontainers/postgresql {:mvn/version "1.19.7"}}
:main-opts ["-m" "kaocha.runner" "--reporter" "kaocha.report/documentation"]}
:cljstyle {:extra-deps {mvxcvi/cljstyle {:mvn/version "0.13.0"
:cljstyle {:extra-deps {mvxcvi/cljstyle {:mvn/version "0.16.630"
:exclusions [org.clojure/clojure]}}
:main-opts ["-m" "cljstyle.main" "check"]}}}

View file

@ -1,15 +1,26 @@
# Introduction
## Who is this library for?
This library is meant for Clojure developers who want to write integration tests without having to worry about the infrastructure of the application.
This library is meant for Clojure developers who want to write integration tests without having to worry about the
infrastructure of the application.
## What are Testcontainers?
Depending on the complexity of your application, setting up the infrastructure for integration tests is not a simple task. Even if you only need a single database for the integration tests, you need to make it available to every system that executes the tests. But often, one database is not enough and you need to integrate with Webservices, Message Queues, Search Indexes, Caches… Testcontainers try to solve this problem: Very simply put, the testcontainers Java library provides an interface to interact with Docker and enables developers to easily bring up Docker containers for executing tests, and tearing them down again, afterwards. See more at [https://www.testcontainers.org/](https://www.testcontainers.org/)
Depending on the complexity of your application, setting up the infrastructure for integration tests is not a simple
task. Even if you only need a single database for the integration tests, you need to make it available to every system
that executes the tests. But often, one database is not enough and you need to integrate with Webservices, Message
Queues, Search Indexes, Caches… Testcontainers try to solve this problem: Very simply put, the testcontainers Java
library provides an interface to interact with Docker and enables developers to easily bring up Docker containers for
executing tests, and tearing them down again, afterwards. See more
at [https://www.testcontainers.org/](https://www.testcontainers.org/)
## Why do we need a Clojure wrapper?
As Testcontainers is a Java library, we do not *need* a Clojure wrapper to work with it. It is completely possible to use it directly via Java interop code:
```java
As Testcontainers is a Java library, we do not *need* a Clojure wrapper to work with it. It is completely possible to
use it directly via Java interop code:
```clojure
(-> (org.testcontainers.containers.GenericContainer. "postgres:12.2")
(.withExposedPorts (into-array Integer [(int 5432)]))
(.withEnv "POSTGRES_PASSSWORD" pw)

34
doc/log-strategies.md Normal file
View file

@ -0,0 +1,34 @@
# Log strategies
This library offers two ways to access the logs of the running container: The :string strategy and the :fn strategy.
## String Strategy
The `:string` strategy sets up a function in the returned map, under the `:log` key. This function enables the
dumping of the logs when passed to the `dump-logs` function.
Example:
```clojure
{:log-to {: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-to {:log-strategy :fn
:function (fn [log-line] (println "From Container: " log-line))}}
```

View file

@ -2,7 +2,8 @@
The list of functions included in the library until now is as following:
* `create`: Creates a new Testcontainers instance, accepts parameters for mapped ports, environment variables and a start command
* `create`: Creates a new Testcontainers instance, accepts parameters for mapped ports, environment variables and a
start command
* `map-classpath-resource!`: Maps a resource from your classpath into the containers file system
* `bind-filesystem!`: Binds a path from your local filesystem into the Docker container as a volume
* `start!`: Starts the container
@ -10,7 +11,8 @@ The list of functions included in the library until now is as following:
* `copy-file-to-container!`: Copies a file from your filesystem or classpath into the running container
* `execute-command!`: Executes a command in the running container, and returns the result
The functions accept and return a map structure, which enables us to operate them on the same data structure in a consistent way. The example shown with Java Interop above would look like this, when using the wrapped functions:
The functions accept and return a map structure, which enables us to operate them on the same data structure in a
consistent way. The example shown with Java Interop above would look like this, when using the wrapped functions:
```clojure
(require '[clj-test-containers.core :as tc])
@ -35,7 +37,9 @@ The functions accept and return a map structure, which enables us to operate the
## Executing commands inside the container
The `execute-command` function enables us to run commands inside the container. The function accepts a container and a vector of strings as parameters, with the first string being the command, followed by potential parameters. The function returns a map with an `:exit-code`, `:stdout` and `:stderr`:
The `execute-command` function enables us to run commands inside the container. The function accepts a container and a
vector of strings as parameters, with the first string being the command, followed by potential parameters. The function
returns a map with an `:exit-code`, `:stdout` and `:stderr`:
```clojure
(execute-command! container ["whoami"])
@ -46,7 +50,9 @@ The `execute-command` function enables us to run commands inside the container.
## Mounting files into the container
For some test scenarios it can be helpful to mount files from your filesystem or the resource path of your application into the container, before it is started. This could be helpful if you want to load a dumpfile into your database, before executing the tests. You can do this with the functions `map-classpath-resource!` and `bind-filesystem!`:
For some test scenarios it can be helpful to mount files from your filesystem or the resource path of your application
into the container, before it is started. This could be helpful if you want to load a dumpfile into your database,
before executing the tests. You can do this with the functions `map-classpath-resource!` and `bind-filesystem!`:
```clojure
(map-classpath-resource! container
@ -70,20 +76,23 @@ It is also possible to copy files into a running container instance:
```
# Fixtures for Clojure Test
The above example creates a Testcontainers instance in the test function itself. If we did this for all of our integration tests, this would spin up a docker image for every test function, and tear it down again, afterwards. If we want to create one image for all tests in the same namespace, we can use Clojures [`use-fixtures`](https://clojuredocs.org/clojure.test/use-fixtures) function, which is described like this:
> Wrap test runs in a fixture function to perform setup and
teardown. Using a fixture-type of :each wraps every test
individually, while :once wraps the whole run in a single function.
The above example creates a Testcontainers instance in the test function itself. If we did this for all of our
integration tests, this would spin up a docker image for every test function, and tear it down again, afterwards. If we
want to create one image for all tests in the same namespace, we can use
Clojures [`use-fixtures`](https://clojuredocs.org/clojure.test/use-fixtures) function, which is described like this:
Assuming we have a function `initialize-db!` in our application which sets up a JDBC connection and stores it in an atom, a fixture for Testcontainers could look like this:
> Wrap test runs in a fixture function to perform setup and teardown. Using a fixture-type of :each wraps every test individually, while :once wraps the whole run in a single function.
Assuming we have a function `initialize-db!` in our application which sets up a JDBC connection and stores it in an
atom, a fixture for Testcontainers could look like this:
```clojure
(use-fixtures :once (fn [f]
(let [{pw "apassword"
(let [pw "apassword"
postgres (tc/start! (tc/create {:image-name "postgres:12.2"
:exposed-ports [5432]
:env-vars {"POSTGRES_PASSWORD" pw}}))}]
:env-vars {"POSTGRES_PASSWORD" pw}}))]
(my-app/initialize-db! {:dbtype "postgresql"
:dbname "postgres"
:user "postgres"

97
doc/wait-strategies.md Normal file
View file

@ -0,0 +1,97 @@
# Wait strategies
Testcontainers provides a set of wait strategies which help us determine if and when a container is ready to accept
requests. Wait strategies are defined for the `:wait-for` key in the container configuration with the
key `:wait-strategy` determining which strategy to select. The `start!` function will block until the container is ready
and continue processing afterwards.
## HTTP Wait Strategy
The HTTP wait strategy will perform an HTTP call according to the following configuration and only continue if the
criteria is met.
| Parameter | Type | Description |
|-------------------|------------|---------------------------------------------------------|
| wait-strategy | Keyword | :http |
| path | String | The HTTP path to access |
| port | int | The HTTP port to access |
| method | String | The HTTP method to use (get, post, put...) |
| status-codes | seq of int | The status codes which mark a successful request |
| tls | boolean | Should TLS be used? |
| allow-insecure | boolean | Should insecure HTTP endpoints be trusted? |
| read-timeout | long | The duration in seconds the HTTP may take |
| basic-credentials | Map | {:username "User" :password "Password"} |
| headers | Map | HTTP Headers, e.g. {"Accept" "application/json"} |
| startup-timeout | long | The duration in seconds the container may take to start |
Example:
```clojure
(tc/create {:image-name "alpine:3.5"
:command ["/bin/sh"
"-c"
"while true ; do printf 'HTTP/1.1 200 OK\\n\\nyay' | nc -l -p 8080; done"]
:exposed-ports [8080]
:wait-for {:wait-strategy :http
:path "/"
:port 8080
:method "GET"
:status-codes [200]
:tls false
:read-timout 5
:headers {"Accept" "text/plain"}
:startup-timeout 20}})
```
## Health Wait Strategy
The Health Wait Strategy uses a health check defined in the Dockerfile to determine if the container is ready.
| Parameter | Type | Description |
|-----------------|---------|---------------------------------------------------------|
| wait-strategy | Keyword | :port |
| startup-timeout | long | The duration in seconds the container may take to start |
```clojure
(tc/create {:image-name "alpine:3.5"
:exposed-ports [8080]
:wait-for {:wait-strategy :health
:startup-timeout 20}})
```
## Log Wait Strategy
The Log Wait Strategy waits until a certain phrase appears in the Docker containers' log.
| Parameter | Type | Description |
|-----------------|---------|---------------------------------------------------------|
| wait-strategy | Keyword | :log |
| message | String | A substring of an expected line in the containers log |
| times | int | The number of times the predicate has to match |
| startup-timeout | long | The duration in seconds the container may take to start |
```clojure
(tc/create {:image-name "postgres:12.2"
:exposed-ports [5432]
:env-vars {"POSTGRES_PASSWORD" "pw"}
:wait-for {:wait-strategy :log
:message "accept connections"
:startup-timeout 10}})
```
## Port Wait Strategy
This strategy is the default selcted by Testcontainers if no wait strategy was defined. It waits for the first port in
the containers port mapping to be opened. It does not accept any parameters beside the `startup-timeout`
| Parameter | Type | Description |
|-----------------|---------|---------------------------------------------------------|
| wait-strategy | Keyword | :port |
| startup-timeout | long | The duration in seconds the container may take to start |
```clojure
(tc/create {:image-name "postgres:12.2"
:exposed-ports [5432]
:env-vars {"POSTGRES_PASSWORD" "pw"}
:wait-for {:wait-strategy :port}})
```

View file

@ -1,29 +1,34 @@
(defproject clj-test-containers "0.4.0"
:description "A lightweight, unofficial wrapper around the Testcontainers Java library"
(defproject testcontainers-clj "unspecified"
:description "A lightweight, official wrapper around the Testcontainers Java library"
:url "https://github.com/javahippie/clj-test-containers"
:url "https://github.com/testcontainers/testcontainers-clj"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.10.1"]
[org.testcontainers/testcontainers "1.15.1"]]
:dependencies [[org.clojure/clojure "1.10.3"]
[org.testcontainers/testcontainers "1.19.7"]]
:aliases {"test" ["run" "-m" "kaocha.runner"]
"cljstyle" ["run" "-m" "cljstyle.main"]}
:plugins [[jainsahab/lein-githooks "1.0.0"]]
:profiles {:dev {:dependencies [[expound "0.8.5"]
[lambdaisland/kaocha "1.0.641"]
[lambdaisland/kaocha-cloverage "1.0-45"]
[lambdaisland/kaocha-junit-xml "0.0.76"]
[lambdaisland/kaocha-junit-xml "0.0.76"]
[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.1"]
[com.fzakaria/slf4j-timbre "0.3.20"]]
:source-paths ["dev-src"]}}
:profiles {:dev {:dependencies [[expound "0.9.0"]
[lambdaisland/kaocha "1.88.1376"]
[lambdaisland/kaocha-cloverage "1.1.89"]
[lambdaisland/kaocha-junit-xml "1.17.101"]
[mvxcvi/cljstyle "0.16.630" :exclusions [org.clojure/clojure]]
[org.clojure/test.check "1.1.1"]
[orchestra "2021.01.01-1"]
[org.clojure/tools.namespace "1.5.0"]
[org.testcontainers/postgresql "1.19.7"]
[com.fzakaria/slf4j-timbre "0.4.1"]
[nrepl "1.0.0"]]
:source-paths ["dev-src"]}
:release {:deploy-repositories [["maven" {:url "https://oss.sonatype.org/service/local/staging/deploy/maven2"
:username :env/ossrh_username
:password :env/ossrh_password
:sign-releases false}]]}}
:target-path "target/%s")

View file

@ -6,11 +6,16 @@
(:import
(java.nio.file
Paths)
(java.time
Duration)
(org.testcontainers DockerClientFactory)
(org.testcontainers.containers
BindMode
GenericContainer
Network)
(org.testcontainers.containers.output
BaseConsumer
OutputFrame
ToStringConsumer)
(org.testcontainers.containers.wait.strategy
Wait)
@ -25,9 +30,7 @@
BindMode/READ_WRITE
BindMode/READ_ONLY)))
(defn- reaper-instance
[]
(org.testcontainers.utility.ResourceReaper/instance))
(defonce started-instances (atom #{}))
(defmulti wait
"Sets a wait strategy to the container. Supports :http, :health and :log as
@ -50,19 +53,20 @@
:tls true
:read-timeout 5
:basic-credentials {:username \"user\"
:password \"password\"}}
:password \"password\"
:startup-timeout 60}}
container)
```
## Health Strategy
The :health strategy only accepts a true or false value. This enables support
for Docker's healthcheck feature, whereby you can directly leverage the
healthy state of your container as your wait condition.
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 :true} container)
(wait {:wait-strategy :health
:startup-timeout 60} container)
```
## Log Strategy
@ -74,50 +78,101 @@
```clojure
(wait {:wait-strategy :log
:message \"accept connections\"} container)
: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
```"
:wait-strategy)
(defmethod wait :http
[{:keys [path
port
method
status-codes
tls
allow-insecure
read-timeout
basic-credentials] :as options}
basic-credentials
headers
startup-timeout] :as options}
^GenericContainer container]
(let [for-http (Wait/forHttp path)]
(when port
(.forPort for-http port))
(when method
(.withMethod for-http method))
(doseq [status-code status-codes]
(.forStatusCode for-http status-code))
(when tls
(.usingTls for-http))
(when allow-insecure
(.allowInsecure for-http))
(when read-timeout
(.withReadTimeout for-http (java.time.Duration/ofSeconds read-timeout)))
(.withReadTimeout for-http (Duration/ofSeconds read-timeout)))
(when basic-credentials
(let [{username :username password :password} basic-credentials]
(let [{:keys [username password]} basic-credentials]
(.withBasicCredentials for-http username password)))
(when headers
(.withHeaders for-http headers))
(when startup-timeout
(.withStartupTimeout for-http (Duration/ofSeconds startup-timeout)))
(.waitingFor container for-http)
{:wait-for-http (dissoc options :strategy)}))
(defmethod wait :health
[_ ^GenericContainer container]
(.waitingFor container (Wait/forHealthcheck))
[{:keys [startup-timeout]} ^GenericContainer container]
(let [strategy (Wait/forHealthcheck)]
(when startup-timeout
(.withStartupTimeout strategy (Duration/ofSeconds startup-timeout)))
(.waitingFor container strategy))
{:wait-for-healthcheck true})
(defmethod wait :log
[{:keys [message]} ^GenericContainer container]
(let [log-message (str ".*" message ".*\\n")]
(.waitingFor container (Wait/forLogMessage log-message 1))
[{:keys [message times startup-timeout]} ^GenericContainer container]
(let [log-message (str ".*" message ".*\\n")
strategy (Wait/forLogMessage log-message 1)]
(when times
(.withTimes strategy times))
(when startup-timeout
(.withStartupTimeout strategy (Duration/ofSeconds startup-timeout)))
(.waitingFor container strategy)
{:wait-for-log-message log-message}))
(defmethod wait :port
[{:keys [startup-timeout]} ^GenericContainer container]
(let [strategy (Wait/forListeningPort)]
(when startup-timeout
(.withStartupTimeout strategy (Duration/ofSeconds startup-timeout)))
(.waitingFor container strategy))
{:wait-for-port true})
(defmethod wait :default [_ _] nil)
(s/fdef init
@ -227,11 +282,10 @@
:stderr (.getStderr result)}))
(defmulti log
"Sets a log strategy on the container as a means of accessing the container
logs. It currently only supports a :string as the strategy to use.
"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
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.
@ -246,6 +300,18 @@
```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)}
```
"
:log-strategy)
@ -258,14 +324,20 @@
(-> (.toUtf8String to-string-consumer)
(clojure.string/replace #"\n+" "\n")))}))
(defmethod log :slf4j [_ _] nil) ;; Not yet implemented
(defmethod log :fn [{:keys [function]} ^GenericContainer container]
(.followOutput container (proxy [BaseConsumer] []
(^void accept [^OutputFrame frame]
(function (.getUtf8String frame))))))
(defmethod log :default [_ _] nil) ;; Not yet implemented
(defmethod log :default [_ _] nil)
(defn dump-logs
"Dumps the logs found by invoking the function on the :string-log key"
[container-config]
((:log container-config)))
(let [log-fn (:log container-config)]
(if (some? log-fn)
(log-fn)
(throw (IllegalStateException. "You are trying to access the container logs, but have not configured a log configuration with :log-to")))))
(defn start!
"Starts the underlying testcontainer instance and adds new values to the
@ -278,12 +350,10 @@
[port]
[port (.getMappedPort container port)])
mapped-ports (into {} (map map-port) exposed-ports)
container-id (.getContainerId container)
image-name (.getDockerImageName container)
container-id ^String (.getContainerId container)
image-name ^String (.getDockerImageName container)
logger (log log-to container)]
(.registerContainerForCleanup (reaper-instance)
container-id
image-name)
(swap! started-instances conj {:type :container :id container-id})
(-> container-config
(merge {:id container-id
:mapped-ports mapped-ports
@ -317,7 +387,7 @@
(let [network (.build builder)
network-name (.getName network)]
(.registerNetworkIdForCleanup (reaper-instance) network-name)
(swap! started-instances conj {:type :network :id :network-name})
{:network network
:name network-name
:ipv6 (.getEnableIpv6 network)
@ -325,13 +395,35 @@
(def ^:deprecated init-network create-network)
(defn- remove-network! [instance]
(-> (DockerClientFactory/instance)
(.client)
(.removeNetworkCmd (:id instance))
(.exec))
instance)
(defn- stop-and-remove-container! [instance]
(let [docker-client (DockerClientFactory/instance)]
(-> docker-client
(.client)
(.stopContainerCmd (:id instance))
(.exec))
(-> docker-client
(.client)
(.removeContainerCmd (:id instance))
(.exec)))
instance)
(defn perform-cleanup!
"Stops and removes all container instances which were created in the active JVM or REPL session"
[]
(.performCleanup (reaper-instance)))
(for [instance @started-instances]
(swap! started-instances disj (case (:type instance)
:container (stop-and-remove-container! instance)
:network (remove-network! instance)))))
;;; REPL Helpers
;; REPL Helpers
(comment
(start! (create {:image-name "postgres:12.1"}))
(perform-cleanup!))

View file

@ -35,7 +35,7 @@
(s/def ::log
keyword?)
(s/def ::wait-strategy #{:http :health :log})
(s/def ::wait-strategy #{:http :health :port :log})
(s/def ::log-strategy #{:string})

View file

@ -9,7 +9,7 @@
(deftest create-test
(testing "Testing basic testcontainer generic image initialisation"
(let [container (sut/create {:image-name "postgres:12.2"
(let [container (sut/create {:image-name "postgres:15.3"
:exposed-ports [5432]
:env-vars {"POSTGRES_PASSWORD" "pw"}})
initialized-container (sut/start! container)
@ -20,18 +20,35 @@
(is (nil? (:id stopped-container)))
(is (nil? (:mapped-ports stopped-container)))))
(testing "Testing log access to the container"
(let [container (sut/init {:container (PostgreSQLContainer. "postgres:12.2")
(testing "Testing log access to the container with string logs"
(let [container (sut/create {:image-name "postgres:15.3"
:exposed-ports [5432]
:env-vars {"POSTGRES_PASSWORD" "pw"}
:log-to {:log-strategy :string}})
initialized-container (sut/start! container)]
(Thread/sleep 500)
(is (includes? (sut/dump-logs initialized-container) "database system is ready to accept connections"))))
(testing "Testing log access to the container with function logs"
(let [logs (atom [])]
(sut/start! (sut/init {:container (PostgreSQLContainer. "postgres:15.3")
:exposed-ports [5432]
:log-to {:log-strategy :fn
:function #(swap! logs conj %)}}))
(is (filter #(includes? "database system is ready to accept connections" %) @logs))))
(testing "Testing log access to the container with unconfigured logger"
(let [container (sut/start! (sut/init {:container (PostgreSQLContainer. "postgres:15.3")
:exposed-ports [5432]}))]
(is (thrown? IllegalStateException (sut/dump-logs container)))))
(testing "Testing basic testcontainer generic image initialisation with wait for log message"
(let [container (sut/create {:image-name "postgres:12.2"
(let [container (sut/create {:image-name "postgres:15.3"
:exposed-ports [5432]
:env-vars {"POSTGRES_PASSWORD" "pw"}
:wait-for {:wait-strategy :log :message "accept connections"}})
:wait-for {:wait-strategy :log
:message "accept connections"
:startup-timeout 10}})
initialized-container (sut/start! container)
stopped-container (sut/stop! container)]
(is (some? (:id initialized-container)))
@ -41,6 +58,44 @@
(is (nil? (:id stopped-container)))
(is (nil? (:mapped-ports stopped-container)))))
(testing "Testing basic testcontainer generic image initialisation with wait for host port"
(let [container (sut/create {:image-name "postgres:15.3"
:exposed-ports [5432]
:env-vars {"POSTGRES_PASSWORD" "pw"}
:wait-for {:wait-strategy :port}})
initialized-container (sut/start! container)
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 (= (:wait-for-port initialized-container) true))
(is (nil? (:id stopped-container)))
(is (nil? (:mapped-ports stopped-container)))))
(testing "Testing basic testcontainer generic image initialisation with wait for http"
(let [container (sut/create {:image-name "bitnami/nginx:1.22"
:network-aliases ["foo"]
:exposed-ports [8080]
:wait-for {:wait-strategy :http
:path "/"
:port 8080
:method "GET"
:status-codes [200]
:headers {"Accept" "text/plain"}}})
initialized-container (sut/start! container)
stopped-container (sut/stop! container)]
(is (some? (:id initialized-container)))
(is (some? (:mapped-ports initialized-container)))
(is (some? (get (:mapped-ports initialized-container) 8080)))
(is (= (:wait-for-http initialized-container) {:headers {"Accept" "text/plain"}
:method "GET"
:path "/"
:port 8080
:status-codes [200]
:wait-strategy :http}))
(is (nil? (:id stopped-container)))
(is (nil? (:mapped-ports stopped-container)))))
(testing "Testing basic testcontainer image creation from docker file"
(let [container (sut/create-from-docker-file {:exposed-ports [80]
:docker-file "test/resources/Dockerfile"})
@ -54,7 +109,8 @@
(testing "Executing a command in the running Docker container with a custom container"
(let [container (sut/init {:container (PostgreSQLContainer. "postgres:12.2")})
(let [container (sut/init {:container (PostgreSQLContainer. "postgres:15.3")
:exposed-ports [5432]})
initialized-container (sut/start! container)
result (sut/execute-command! initialized-container ["whoami"])
_stopped-container (sut/stop! container)]
@ -64,7 +120,7 @@
(deftest execute-command-in-container
(testing "Executing a command in the running Docker container"
(let [container (sut/create {:image-name "postgres:12.2"
(let [container (sut/create {:image-name "postgres:15.3"
:exposed-ports [5432]
:env-vars {"POSTGRES_PASSWORD" "pw"}})
initialized-container (sut/start! container)
@ -76,7 +132,7 @@
(deftest init-volume-test
(testing "Testing mapping of a classpath resource"
(let [container (-> (sut/create {:image-name "postgres:12.2"
(let [container (-> (sut/create {:image-name "postgres:15.3"
:exposed-ports [5432]
:env-vars {"POSTGRES_PASSWORD" "pw"}})
(sut/map-classpath-resource! {:resource-path "test.sql"
@ -93,7 +149,7 @@
(is (nil? (:mapped-ports stopped-container)))))
(testing "Testing mapping of a filesystem-binding"
(let [container (-> (sut/create {:image-name "postgres:12.2"
(let [container (-> (sut/create {:image-name "postgres:15.3"
:exposed-ports [5432]
:env-vars {"POSTGRES_PASSWORD" "pw"}})
(sut/bind-filesystem! {:host-path "."
@ -110,7 +166,7 @@
(is (nil? (:mapped-ports stopped-container)))))
(testing "Copying a file from the host into the container"
(let [container (-> (sut/create {:image-name "postgres:12.2"
(let [container (-> (sut/create {:image-name "postgres:15.3"
:exposed-ports [5432]
:env-vars {"POSTGRES_PASSWORD" "pw"}})
(sut/copy-file-to-container! {:path "test.sql"
@ -128,7 +184,7 @@
(testing "Copying a file from the classpath into the container"
(let [container (-> (sut/create {:image-name "postgres:12.2"
(let [container (-> (sut/create {:image-name "postgres:15.3"
:exposed-ports [5432]
:env-vars {"POSTGRES_PASSWORD" "pw"}})
(sut/copy-file-to-container! {:path "test.sql"
@ -145,7 +201,7 @@
(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"
(let [container (sut/create {:image-name "postgres:15.3"
:exposed-ports [5432]
:env-vars {"POSTGRES_PASSWORD" "pw"}})
initialized-container (sut/start! container)
@ -164,7 +220,7 @@
(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"
(let [container (sut/create {:image-name "postgres:15.3"
:exposed-ports [5432]
:env-vars {"POSTGRES_PASSWORD" "pw"}})
initialized-container (sut/start! container)