diff --git a/libnetwork/drivers/bridge/bridge_test.go b/libnetwork/drivers/bridge/bridge_test.go index 02dbbda67a..525a22d3a8 100644 --- a/libnetwork/drivers/bridge/bridge_test.go +++ b/libnetwork/drivers/bridge/bridge_test.go @@ -148,19 +148,57 @@ func compareConnConfig(a, b *connectivityConfiguration) bool { } } for i := 0; i < len(a.PortBindings); i++ { - if !a.PortBindings[i].Equal(&b.PortBindings[i]) { + if !comparePortBinding(&a.PortBindings[i], &b.PortBindings[i]) { return false } } return true } +// comparePortBinding returns whether the given PortBindings are equal. +func comparePortBinding(p *types.PortBinding, o *types.PortBinding) bool { + if p == o { + return true + } + + if o == nil { + return false + } + + if p.Proto != o.Proto || p.Port != o.Port || + p.HostPort != o.HostPort || p.HostPortEnd != o.HostPortEnd { + return false + } + + if p.IP != nil { + if !p.IP.Equal(o.IP) { + return false + } + } else { + if o.IP != nil { + return false + } + } + + if p.HostIP != nil { + if !p.HostIP.Equal(o.HostIP) { + return false + } + } else { + if o.HostIP != nil { + return false + } + } + + return true +} + func compareBindings(a, b []types.PortBinding) bool { if len(a) != len(b) { return false } for i := 0; i < len(a); i++ { - if !a[i].Equal(&b[i]) { + if !comparePortBinding(&a[i], &b[i]) { return false } } @@ -674,7 +712,7 @@ func testQueryEndpointInfo(t *testing.T, ulPxyEnabled bool) { t.Fatal("Incomplete data for port mapping in endpoint operational data") } for i, pb := range ep.portMapping { - if !pb.Equal(&pm[i]) { + if !comparePortBinding(&pb, &pm[i]) { t.Fatal("Unexpected data for port mapping in endpoint operational data") } } diff --git a/libnetwork/types/types.go b/libnetwork/types/types.go index c4d4a5a9fc..83031e7b29 100644 --- a/libnetwork/types/types.go +++ b/libnetwork/types/types.go @@ -130,44 +130,6 @@ func (p *PortBinding) String() string { return ret } -// Equal checks if this instance of PortBinding is equal to the passed one -func (p *PortBinding) Equal(o *PortBinding) bool { - if p == o { - return true - } - - if o == nil { - return false - } - - if p.Proto != o.Proto || p.Port != o.Port || - p.HostPort != o.HostPort || p.HostPortEnd != o.HostPortEnd { - return false - } - - if p.IP != nil { - if !p.IP.Equal(o.IP) { - return false - } - } else { - if o.IP != nil { - return false - } - } - - if p.HostIP != nil { - if !p.HostIP.Equal(o.HostIP) { - return false - } - } else { - if o.HostIP != nil { - return false - } - } - - return true -} - // ErrInvalidProtocolBinding is returned when the port binding protocol is not valid. type ErrInvalidProtocolBinding string