File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -421,6 +421,25 @@ Creates a network. The optional map accepts config values for enabling ipv6 and
421421(create-network )
422422```
423423
424+ ### with-network
425+
426+ Create and bind a network to * network* and run ` test-fn ` . The network is removed after the function executes.
427+
428+ #### Config parameters:
429+
430+ ` with-network ` takes an optional map of options, equivalent to ` create-network ` .
431+
432+
433+ #### Example:
434+
435+ ``` clojure
436+ ; ; Run tests within an ephemeral network
437+ (use-fixtures :once (tc/with-network {:ipv6? true }))
438+
439+ (deftest test-network-loaded
440+ (is (some? tc/*network*)))
441+ ```
442+
424443### perform-cleanup!
425444
426445Stops and removes all containers which were created in the JVM, including the REPL session you are in. This is helpful,
Original file line number Diff line number Diff line change 3030 BindMode/READ_WRITE
3131 BindMode/READ_ONLY)))
3232
33+ (def ^:dynamic *network* nil )
34+
3335(defonce started-instances (atom #{}))
3436
3537(defmulti wait
402404 (.exec ))
403405 instance )
404406
407+ (defn with-network
408+ ([] (with-network {}))
409+ ([network-options]
410+ (fn [test-fn]
411+ (binding [*network* (create-network network-options)]
412+ (try
413+ (test-fn )
414+ (finally
415+ (remove-network! *network*)))))))
416+
405417(defn- stop-and-remove-container! [instance]
406418 (let [docker-client (DockerClientFactory/instance )]
407419 (-> docker-client
You can’t perform that action at this time.
0 commit comments