This commit is contained in:
Ryan R Sundberg 2024-04-30 18:31:20 +00:00 committed by GitHub
commit e055b96675
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 31 additions and 0 deletions

View file

@ -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,

View file

@ -30,6 +30,8 @@
BindMode/READ_WRITE
BindMode/READ_ONLY)))
(def ^:dynamic *network* nil)
(defonce started-instances (atom #{}))
(defmulti wait
@ -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