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 @@ -438,6 +438,25 @@ Creates a network. The optional map accepts config values for enabling ipv6 and
438438(create-network )
439439```
440440
441+ ### with-network
442+
443+ Create and bind a network to * network* and run ` test-fn ` . The network is removed after the function executes.
444+
445+ #### Config parameters:
446+
447+ ` with-network ` takes an optional map of options, equivalent to ` create-network ` .
448+
449+
450+ #### Example:
451+
452+ ``` clojure
453+ ; ; Run tests within an ephemeral network
454+ (use-fixtures :once (tc/with-network {:ipv6? true }))
455+
456+ (deftest test-network-loaded
457+ (is (some? tc/*network*)))
458+ ```
459+
441460### perform-cleanup!
442461
443462Stops 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
408410 (.exec ))
409411 instance )
410412
413+ (defn with-network
414+ ([] (with-network {}))
415+ ([network-options]
416+ (fn [test-fn]
417+ (binding [*network* (create-network network-options)]
418+ (try
419+ (test-fn )
420+ (finally
421+ (remove-network! *network*)))))))
422+
411423(defn- stop-and-remove-container! [instance]
412424 (let [docker-client (DockerClientFactory/instance )]
413425 (-> docker-client
You can’t perform that action at this time.
0 commit comments