Skip to content

Commit 3d6a531

Browse files
authored
test: add e2e test for com.docker.network.bridge.enable_icc option (runfinch#104)
Signed-off-by: Swagat Bora <[email protected]>
1 parent 46df1b6 commit 3d6a531

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

e2e/tests/network_create.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,17 @@ func NetworkCreate(opt *option.Option) {
6464
}
6565
}
6666

67+
cleanupNetworkWithHTTP := func(network string) func() {
68+
return func() {
69+
relativeUrl := fmt.Sprintf("/networks/%s", network)
70+
apiUrl := client.ConvertToFinchUrl(version, relativeUrl)
71+
req, err := http.NewRequest(http.MethodDelete, apiUrl, nil)
72+
Expect(err).ShouldNot(HaveOccurred())
73+
_, err = uclient.Do(req)
74+
Expect(err).Should(BeNil())
75+
}
76+
}
77+
6778
When("a create network request is received with required configuration", func() {
6879
It("should return 201 Created and the network ID", func() {
6980
request := types.NewCreateNetworkRequest(testNetwork)
@@ -172,6 +183,54 @@ func NetworkCreate(opt *option.Option) {
172183
Expect(httpResponse).Should(HaveHTTPStatus(http.StatusNotFound))
173184
})
174185
})
186+
187+
When("a network create request is made with network option com.docker.network.bridge.enable_icc set to false", func() {
188+
It("should return 201 Created and the network ID", func() {
189+
testBridge := "br-test"
190+
request := types.NewCreateNetworkRequest(testNetwork, withEnableICCdNetworkOptions("false", testBridge)...)
191+
192+
httpResponse := createNetwork(*request)
193+
Expect(httpResponse).Should(HaveHTTPStatus(http.StatusCreated))
194+
195+
response := unmarshallHTTPResponse(httpResponse)
196+
Expect(response.ID).ShouldNot(BeEmpty())
197+
Expect(response.Warning).Should(BeEmpty())
198+
199+
DeferCleanup(cleanupNetworkWithHTTP(testNetwork))
200+
201+
stdout := command.Stdout(opt, "network", "inspect", testNetwork)
202+
Expect(stdout).To(ContainSubstring(`"finch.network.bridge.enable_icc.ipv4": "false"`))
203+
204+
// check iptables rules exists
205+
iptOpt, _ := option.New([]string{"iptables"})
206+
command.Run(iptOpt, "-C", "FINCH-ISOLATE-CHAIN",
207+
"-i", testBridge, "-o", testBridge, "-j", "DROP")
208+
})
209+
})
210+
211+
When("a network create request is made with network option com.docker.network.bridge.enable_icc set to true", func() {
212+
It("should create the network without the enable_icc label", func() {
213+
testBridge := "br-test"
214+
request := types.NewCreateNetworkRequest(testNetwork, withEnableICCdNetworkOptions("true", testBridge)...)
215+
216+
httpResponse := createNetwork(*request)
217+
Expect(httpResponse).Should(HaveHTTPStatus(http.StatusCreated))
218+
219+
DeferCleanup(cleanupNetworkWithHTTP(testNetwork))
220+
221+
response := unmarshallHTTPResponse(httpResponse)
222+
Expect(response.ID).ShouldNot(BeEmpty())
223+
Expect(response.Warning).Should(BeEmpty())
224+
225+
stdout := command.Stdout(opt, "network", "inspect", testNetwork)
226+
Expect(stdout).ShouldNot(ContainSubstring(`"finch.network.bridge.enable_icc.ipv4"`))
227+
228+
// check iptables rules does not exist
229+
iptOpt, _ := option.New([]string{"iptables"})
230+
command.RunWithoutSuccessfulExit(iptOpt, "-C", "FINCH-ISOLATE-CHAIN",
231+
"-i", testBridge, "-o", testBridge, "-j", "DROP")
232+
})
233+
})
175234
})
176235
}
177236

@@ -245,3 +304,20 @@ func withUnsupportedNetworkOptions() []types.NetworkCreateOption {
245304
}),
246305
}
247306
}
307+
308+
func withEnableICCdNetworkOptions(enableICC string, bridgeName string) []types.NetworkCreateOption {
309+
return []types.NetworkCreateOption{
310+
types.WithIPAM(types.IPAM{
311+
Driver: "default",
312+
Config: []map[string]string{
313+
{
314+
"Subnet": "240.11.0.0/24",
315+
},
316+
},
317+
}),
318+
types.WithOptions(map[string]string{
319+
"com.docker.network.bridge.enable_icc": enableICC,
320+
"com.docker.network.bridge.name": bridgeName,
321+
}),
322+
}
323+
}

0 commit comments

Comments
 (0)