diff options
author | Paul Holzinger <pholzing@redhat.com> | 2021-11-01 18:17:39 +0100 |
---|---|---|
committer | Paul Holzinger <pholzing@redhat.com> | 2021-11-11 16:49:28 +0100 |
commit | b2f7430b6751e4a8177ee0088ea8e09675703828 (patch) | |
tree | 571cef5a65157a98184f2a22dbec584d811c42e3 /libpod/network/netavark/netavark_suite_test.go | |
parent | 1c88f741a7a15a7c8ff666c080a325ef0056af02 (diff) | |
download | podman-b2f7430b6751e4a8177ee0088ea8e09675703828.tar.gz podman-b2f7430b6751e4a8177ee0088ea8e09675703828.tar.bz2 podman-b2f7430b6751e4a8177ee0088ea8e09675703828.zip |
Add more netavark tests
Signed-off-by: Paul Holzinger <pholzing@redhat.com>
Diffstat (limited to 'libpod/network/netavark/netavark_suite_test.go')
-rw-r--r-- | libpod/network/netavark/netavark_suite_test.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/libpod/network/netavark/netavark_suite_test.go b/libpod/network/netavark/netavark_suite_test.go index 4d0c04634..6063a54e3 100644 --- a/libpod/network/netavark/netavark_suite_test.go +++ b/libpod/network/netavark/netavark_suite_test.go @@ -3,14 +3,19 @@ package netavark_test import ( + "fmt" + "net" "os" "path/filepath" + "reflect" "testing" "github.com/containers/podman/v3/libpod/network/netavark" "github.com/containers/podman/v3/libpod/network/types" + "github.com/containers/podman/v3/libpod/network/util" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + gomegaTypes "github.com/onsi/gomega/types" ) func TestNetavark(t *testing.T) { @@ -36,3 +41,35 @@ func getNetworkInterface(confDir string, machine bool) (types.ContainerNetwork, LockFile: filepath.Join(confDir, "netavark.lock"), }) } + +// EqualSubnet is a custom GomegaMatcher to match a subnet +// This makes sure to not use the 16 bytes ip representation. +func EqualSubnet(subnet *net.IPNet) gomegaTypes.GomegaMatcher { + return &equalSubnetMatcher{ + expected: subnet, + } +} + +type equalSubnetMatcher struct { + expected *net.IPNet +} + +func (m *equalSubnetMatcher) Match(actual interface{}) (bool, error) { + util.NormalizeIP(&m.expected.IP) + + subnet, ok := actual.(*net.IPNet) + if !ok { + return false, fmt.Errorf("EqualSubnet expects a *net.IPNet") + } + util.NormalizeIP(&subnet.IP) + + return reflect.DeepEqual(subnet, m.expected), nil +} + +func (m *equalSubnetMatcher) FailureMessage(actual interface{}) string { + return fmt.Sprintf("Expected subnet %#v to equal subnet %#v", actual, m.expected) +} + +func (m *equalSubnetMatcher) NegatedFailureMessage(actual interface{}) string { + return fmt.Sprintf("Expected subnet %#v not to equal subnet %#v", actual, m.expected) +} |