Skip to content

Commit

Permalink
test: add e2e test for com.docker.network.bridge.enable_icc option (#104
Browse files Browse the repository at this point in the history
)

Signed-off-by: Swagat Bora <[email protected]>
  • Loading branch information
swagatbora90 authored Nov 26, 2024
1 parent 46df1b6 commit 3d6a531
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions e2e/tests/network_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ func NetworkCreate(opt *option.Option) {
}
}

cleanupNetworkWithHTTP := func(network string) func() {
return func() {
relativeUrl := fmt.Sprintf("/networks/%s", network)
apiUrl := client.ConvertToFinchUrl(version, relativeUrl)
req, err := http.NewRequest(http.MethodDelete, apiUrl, nil)
Expect(err).ShouldNot(HaveOccurred())
_, err = uclient.Do(req)
Expect(err).Should(BeNil())
}
}

When("a create network request is received with required configuration", func() {
It("should return 201 Created and the network ID", func() {
request := types.NewCreateNetworkRequest(testNetwork)
Expand Down Expand Up @@ -172,6 +183,54 @@ func NetworkCreate(opt *option.Option) {
Expect(httpResponse).Should(HaveHTTPStatus(http.StatusNotFound))
})
})

When("a network create request is made with network option com.docker.network.bridge.enable_icc set to false", func() {
It("should return 201 Created and the network ID", func() {
testBridge := "br-test"
request := types.NewCreateNetworkRequest(testNetwork, withEnableICCdNetworkOptions("false", testBridge)...)

httpResponse := createNetwork(*request)
Expect(httpResponse).Should(HaveHTTPStatus(http.StatusCreated))

response := unmarshallHTTPResponse(httpResponse)
Expect(response.ID).ShouldNot(BeEmpty())
Expect(response.Warning).Should(BeEmpty())

DeferCleanup(cleanupNetworkWithHTTP(testNetwork))

stdout := command.Stdout(opt, "network", "inspect", testNetwork)
Expect(stdout).To(ContainSubstring(`"finch.network.bridge.enable_icc.ipv4": "false"`))

// check iptables rules exists
iptOpt, _ := option.New([]string{"iptables"})
command.Run(iptOpt, "-C", "FINCH-ISOLATE-CHAIN",
"-i", testBridge, "-o", testBridge, "-j", "DROP")
})
})

When("a network create request is made with network option com.docker.network.bridge.enable_icc set to true", func() {
It("should create the network without the enable_icc label", func() {
testBridge := "br-test"
request := types.NewCreateNetworkRequest(testNetwork, withEnableICCdNetworkOptions("true", testBridge)...)

httpResponse := createNetwork(*request)
Expect(httpResponse).Should(HaveHTTPStatus(http.StatusCreated))

DeferCleanup(cleanupNetworkWithHTTP(testNetwork))

response := unmarshallHTTPResponse(httpResponse)
Expect(response.ID).ShouldNot(BeEmpty())
Expect(response.Warning).Should(BeEmpty())

stdout := command.Stdout(opt, "network", "inspect", testNetwork)
Expect(stdout).ShouldNot(ContainSubstring(`"finch.network.bridge.enable_icc.ipv4"`))

// check iptables rules does not exist
iptOpt, _ := option.New([]string{"iptables"})
command.RunWithoutSuccessfulExit(iptOpt, "-C", "FINCH-ISOLATE-CHAIN",
"-i", testBridge, "-o", testBridge, "-j", "DROP")
})
})
})
}

Expand Down Expand Up @@ -245,3 +304,20 @@ func withUnsupportedNetworkOptions() []types.NetworkCreateOption {
}),
}
}

func withEnableICCdNetworkOptions(enableICC string, bridgeName string) []types.NetworkCreateOption {
return []types.NetworkCreateOption{
types.WithIPAM(types.IPAM{
Driver: "default",
Config: []map[string]string{
{
"Subnet": "240.11.0.0/24",
},
},
}),
types.WithOptions(map[string]string{
"com.docker.network.bridge.enable_icc": enableICC,
"com.docker.network.bridge.name": bridgeName,
}),
}
}

0 comments on commit 3d6a531

Please sign in to comment.