libnetwork/types: remove PortBinding.Equal

It was only used in tests, so move it to a utility in the tests.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-07-29 02:27:31 +02:00
parent 4269712d06
commit 4445169cb5
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
2 changed files with 41 additions and 41 deletions

View file

@ -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")
}
}

View file

@ -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