libnetwork: TestUserChain: re-use IPTables instances
The test already creates instances for each ip-version, so let's re-use them. While changing, also use assert.Check to not fail early. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
c471255153
commit
4e709e75da
1 changed files with 8 additions and 9 deletions
|
@ -11,6 +11,7 @@ import (
|
|||
"github.com/docker/docker/libnetwork/options"
|
||||
"github.com/docker/docker/libnetwork/testutils"
|
||||
"gotest.tools/v3/assert"
|
||||
is "gotest.tools/v3/assert/cmp"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -63,8 +64,8 @@ func TestUserChain(t *testing.T) {
|
|||
defer c.Stop()
|
||||
|
||||
// init. condition, FORWARD chain empty DOCKER-USER not exist
|
||||
assert.DeepEqual(t, getRules(t, iptables.IPv4, fwdChainName), []string{"-P FORWARD ACCEPT"})
|
||||
assert.DeepEqual(t, getRules(t, iptables.IPv6, fwdChainName), []string{"-P FORWARD ACCEPT"})
|
||||
assert.Check(t, is.DeepEqual(getRules(t, iptable4, fwdChainName), []string{"-P FORWARD ACCEPT"}))
|
||||
assert.Check(t, is.DeepEqual(getRules(t, iptable6, fwdChainName), []string{"-P FORWARD ACCEPT"}))
|
||||
|
||||
if tc.insert {
|
||||
_, err = iptable4.Raw("-A", fwdChainName, "-j", "DROP")
|
||||
|
@ -74,11 +75,11 @@ func TestUserChain(t *testing.T) {
|
|||
}
|
||||
arrangeUserFilterRule()
|
||||
|
||||
assert.DeepEqual(t, getRules(t, iptables.IPv4, fwdChainName), tc.fwdChain)
|
||||
assert.DeepEqual(t, getRules(t, iptables.IPv6, fwdChainName), tc.fwdChain)
|
||||
assert.Check(t, is.DeepEqual(getRules(t, iptable4, fwdChainName), tc.fwdChain))
|
||||
assert.Check(t, is.DeepEqual(getRules(t, iptable6, fwdChainName), tc.fwdChain))
|
||||
if tc.userChain != nil {
|
||||
assert.DeepEqual(t, getRules(t, iptables.IPv4, usrChainName), tc.userChain)
|
||||
assert.DeepEqual(t, getRules(t, iptables.IPv6, usrChainName), tc.userChain)
|
||||
assert.Check(t, is.DeepEqual(getRules(t, iptable4, usrChainName), tc.userChain))
|
||||
assert.Check(t, is.DeepEqual(getRules(t, iptable6, usrChainName), tc.userChain))
|
||||
} else {
|
||||
_, err := iptable4.Raw("-S", usrChainName)
|
||||
assert.Assert(t, err != nil, "ipv4 chain %v: created unexpectedly", usrChainName)
|
||||
|
@ -89,9 +90,7 @@ func TestUserChain(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func getRules(t *testing.T, ipVer iptables.IPVersion, chain string) []string {
|
||||
iptable := iptables.GetIptable(ipVer)
|
||||
|
||||
func getRules(t *testing.T, iptable *iptables.IPTable, chain string) []string {
|
||||
t.Helper()
|
||||
output, err := iptable.Raw("-S", chain)
|
||||
assert.NilError(t, err, "chain %s: failed to get rules", chain)
|
||||
|
|
Loading…
Add table
Reference in a new issue