Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,25 @@ Creates a network. The optional map accepts config values for enabling ipv6 and
(create-network)
```

### with-network

Create and bind a network to *network* and run `test-fn`. The network is removed after the function executes.

#### Config parameters:

`with-network` takes an optional map of options, equivalent to `create-network`.


#### Example:

```clojure
;; Run tests within an ephemeral network
(use-fixtures :once (tc/with-network {:ipv6? true}))

(deftest test-network-loaded
(is (some? tc/*network*)))
```

### perform-cleanup!

Stops and removes all containers which were created in the JVM, including the REPL session you are in. This is helpful,
Expand Down
12 changes: 12 additions & 0 deletions src/clj_test_containers/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
BindMode/READ_WRITE
BindMode/READ_ONLY)))

(def ^:dynamic *network* nil)

(defonce started-instances (atom #{}))

(defmulti wait
Expand Down Expand Up @@ -402,6 +404,16 @@
(.exec))
instance)

(defn with-network
([] (with-network {}))
([network-options]
(fn [test-fn]
(binding [*network* (create-network network-options)]
(try
(test-fn)
(finally
(remove-network! *network*)))))))

(defn- stop-and-remove-container! [instance]
(let [docker-client (DockerClientFactory/instance)]
(-> docker-client
Expand Down