Rename init-network, remove .getId call (#30)
* Rename init-network, remove .getId call - Should be called `create-network` to match the existing `create` function - Network#getId oddly has a side effect, which made generative testing impossible. Removing this defers network creation until `start!` is called - Mark init-network as deprecated * just use def instead of defn * Fix indentation in README
This commit is contained in:
parent
3d4a5a7ce8
commit
76359eec37
4 changed files with 17 additions and 18 deletions
17
README.md
17
README.md
|
|
@ -68,7 +68,7 @@ Creates a testcontainers instance from a given Docker label and returns them
|
||||||
| `:exposed-ports` | Vector with ints, mandatory | All ports which should be exposed and mapped to a local port |
|
| `: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|
|
| `:env-vars` | Map | A map with environment variables|
|
||||||
| `:command` | Vector with strings | The start command of the container|
|
| `:command` | Vector with strings | The start command of the container|
|
||||||
| `:network` | Map | A map containing the configuration of a Docker Network (see: `init-network`)|
|
| `: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 |
|
| `:network-aliases` | Map | A list of alias names for the container on the network |
|
||||||
|
|
||||||
#### Result:
|
#### Result:
|
||||||
|
|
@ -87,7 +87,7 @@ Creates a testcontainers instance from a given Docker label and returns them
|
||||||
(create {:image-name "alpine:3.2"
|
(create {:image-name "alpine:3.2"
|
||||||
:exposed-ports [80]
|
:exposed-ports [80]
|
||||||
:env-vars {"MAGIC_NUMBER" "42"}
|
:env-vars {"MAGIC_NUMBER" "42"}
|
||||||
:network (init-network)
|
:network (create-network)
|
||||||
:network-aliases ["api-server"]
|
:network-aliases ["api-server"]
|
||||||
:command ["/bin/sh"
|
:command ["/bin/sh"
|
||||||
"-c"
|
"-c"
|
||||||
|
|
@ -105,7 +105,7 @@ Initializes a given Testcontainer, which was e.g. provided by a library
|
||||||
| `:exposed-ports` | Vector with ints, mandatory | All ports which should be exposed and mapped to a local port |
|
| `: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|
|
| `:env-vars` | Map | A map with environment variables|
|
||||||
| `:command` | Vector with strings | The start command of the container|
|
| `:command` | Vector with strings | The start command of the container|
|
||||||
| `:network` | Map | A map containing the configuration of a Docker Network (see: `init-network`)|
|
| `: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 |
|
| `:network-aliases` | Map | A list of alias names for the container on the network |
|
||||||
#### Result:
|
#### Result:
|
||||||
|
|
||||||
|
|
@ -140,7 +140,7 @@ Creates a testcontainer from a Dockerfile
|
||||||
| `:exposed-ports` | Vector with ints, mandatory | All ports which should be exposed and mapped to a local port |
|
| `: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|
|
| `:env-vars` | Map | A map with environment variables|
|
||||||
| `:command` | Vector with strings | The start command of the container|
|
| `:command` | Vector with strings | The start command of the container|
|
||||||
| `:network` | Map | A map containing the configuration of a Docker Network (see: `init-network`)|
|
| `: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 |
|
| `:network-aliases` | Map | A list of alias names for the container on the network |
|
||||||
#### Result:
|
#### Result:
|
||||||
|
|
||||||
|
|
@ -339,7 +339,7 @@ Executes a command in the running container, and returns the result
|
||||||
(execute-command! container ["tail" "/opt/test.sql"])
|
(execute-command! container ["tail" "/opt/test.sql"])
|
||||||
```
|
```
|
||||||
|
|
||||||
### init-network
|
### 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
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -356,7 +356,6 @@ Creates a network. The optional map accepts config values for enabling ipv6 and
|
||||||
| Key | Type | Description |
|
| Key | Type | Description |
|
||||||
| ------------- |:------------- | :-----|
|
| ------------- |:------------- | :-----|
|
||||||
| `:network` | `org.testcontainers.containers.Network` | The instance of the network |
|
| `:network` | `org.testcontainers.containers.Network` | The instance of the network |
|
||||||
| `:id` | String | The identifier of the network |
|
|
||||||
| `:name` | String | The name of the network |
|
| `:name` | String | The name of the network |
|
||||||
| `:ipv6` | boolean | Does the network enable IPv6? |
|
| `:ipv6` | boolean | Does the network enable IPv6? |
|
||||||
| `:driver` | String | The network driver used |
|
| `:driver` | String | The network driver used |
|
||||||
|
|
@ -365,11 +364,11 @@ Creates a network. The optional map accepts config values for enabling ipv6 and
|
||||||
|
|
||||||
```clojure
|
```clojure
|
||||||
;;Create with config
|
;;Create with config
|
||||||
(init-network {:ipv6 false
|
(create-network {:ipv6 false
|
||||||
:driver "overlay")
|
:driver "overlay")
|
||||||
|
|
||||||
;;Create with default config
|
;;Create with default config
|
||||||
(init-network)
|
(create-network)
|
||||||
```
|
```
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
|
||||||
|
|
@ -132,16 +132,16 @@
|
||||||
(dissoc :id)
|
(dissoc :id)
|
||||||
(dissoc :mapped-ports)))
|
(dissoc :mapped-ports)))
|
||||||
|
|
||||||
(s/fdef init-network
|
(s/fdef create-network
|
||||||
:args (s/alt :nullary (s/cat)
|
:args (s/alt :nullary (s/cat)
|
||||||
:unary (s/cat :init-network-options
|
:unary (s/cat :create-network-options
|
||||||
::cs/init-network-options))
|
::cs/create-network-options))
|
||||||
:ret ::cs/network)
|
:ret ::cs/network)
|
||||||
|
|
||||||
(defn ^:no-gen init-network
|
(defn 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"
|
||||||
([]
|
([]
|
||||||
(init-network {}))
|
(create-network {}))
|
||||||
([{:keys [ipv6 driver]}]
|
([{:keys [ipv6 driver]}]
|
||||||
(let [builder (Network/builder)]
|
(let [builder (Network/builder)]
|
||||||
(when ipv6
|
(when ipv6
|
||||||
|
|
@ -152,7 +152,8 @@
|
||||||
|
|
||||||
(let [network (.build builder)]
|
(let [network (.build builder)]
|
||||||
{:network network
|
{:network network
|
||||||
:id (.getId network)
|
|
||||||
:name (.getName network)
|
:name (.getName network)
|
||||||
:ipv6 (.getEnableIpv6 network)
|
:ipv6 (.getEnableIpv6 network)
|
||||||
:driver (.getDriver network)}))))
|
:driver (.getDriver network)}))))
|
||||||
|
|
||||||
|
(def ^:deprecated init-network create-network)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@
|
||||||
|
|
||||||
(s/def ::network
|
(s/def ::network
|
||||||
(s/nilable (s/keys :req-un [::csn/network
|
(s/nilable (s/keys :req-un [::csn/network
|
||||||
::csn/id
|
|
||||||
::csn/name
|
::csn/name
|
||||||
::csn/ipv6
|
::csn/ipv6
|
||||||
::csn/driver])))
|
::csn/driver])))
|
||||||
|
|
@ -34,6 +33,6 @@
|
||||||
::network
|
::network
|
||||||
::csc/network-aliases]))
|
::csc/network-aliases]))
|
||||||
|
|
||||||
(s/def ::init-network-options
|
(s/def ::create-network-options
|
||||||
(s/keys :opt-un [::csn/ipv6
|
(s/keys :opt-un [::csn/ipv6
|
||||||
::csn/driver]))
|
::csn/driver]))
|
||||||
|
|
|
||||||
|
|
@ -123,7 +123,7 @@
|
||||||
|
|
||||||
(deftest networking-test
|
(deftest networking-test
|
||||||
(testing "Putting two containers into the same network and check their communication"
|
(testing "Putting two containers into the same network and check their communication"
|
||||||
(let [network (sut/init-network)
|
(let [network (sut/create-network)
|
||||||
server-container (sut/create {:image-name "alpine:3.5"
|
server-container (sut/create {:image-name "alpine:3.5"
|
||||||
:network network
|
:network network
|
||||||
:network-aliases ["foo"]
|
:network-aliases ["foo"]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue