Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
change: tests
Browse files Browse the repository at this point in the history
Signed-off-by: Thorsten Klein <[email protected]>
  • Loading branch information
iwilltry42 committed Feb 12, 2024
1 parent 517b43a commit 2e98387
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
24 changes: 24 additions & 0 deletions pkg/ports/ports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,30 @@ func TestCollectPorts(t *testing.T) {
{TargetPort: 7070, Port: 7000, Hostname: "myapp3.local"},
},
},
// same port mappings on different hostnames
{
name: "same target ports, same ports, different hostnames",
ports: []v1.PortDef{
{TargetPort: 8080, Port: 8080, Hostname: "myapp.local"},
{TargetPort: 8080, Port: 8080, Hostname: "myapp2.local"},
},
expected: []v1.PortDef{
{TargetPort: 8080, Port: 8080, Hostname: "myapp.local"},
{TargetPort: 8080, Port: 8080, Hostname: "myapp2.local"},
},
},
{
name: "same target ports, same ports, different protocols, different hostnames - tcp twice ",
ports: []v1.PortDef{
{TargetPort: 8080, Port: 8080, Protocol: v1.ProtocolTCP, Hostname: "myapp.local"},
{TargetPort: 8080, Port: 8080, Protocol: v1.ProtocolUDP, Hostname: "myapp2.local"},
{TargetPort: 8080, Port: 8080, Protocol: v1.ProtocolHTTP2, Hostname: "myapp3.local"},
},
expected: []v1.PortDef{
{TargetPort: 8080, Port: 8080, Protocol: v1.ProtocolTCP, Hostname: "myapp.local"},
{TargetPort: 8080, Port: 8080, Protocol: v1.ProtocolUDP, Hostname: "myapp2.local"},
},
},
{
name: "same target ports, same ports, different protocols - tcp twice",
ports: []v1.PortDef{
Expand Down
3 changes: 1 addition & 2 deletions pkg/ports/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,7 @@ func collectPorts(seen map[int32][]v1.PortDef, seenHostnames map[string]struct{}
// OK: Same port and target port (and potentially protocol) but different hostnames, so keep both
break
}
if !(port.Protocol == v1.ProtocolUDP && p.Protocol != v1.ProtocolUDP ||
port.Protocol != v1.ProtocolUDP && p.Protocol == v1.ProtocolUDP) {
if (port.Protocol != v1.ProtocolUDP && p.Protocol != v1.ProtocolUDP) || (port.Protocol == v1.ProtocolUDP && p.Protocol == v1.ProtocolUDP) {
// NOT OK: Same port, target port, and protocol (variants of TCP are considered the same, i.e. TCP/HTTP/HTTP2)
// The only case that's OK is if one is UDP and the other is not (some variant of TCP)
discard = true
Expand Down

0 comments on commit 2e98387

Please sign in to comment.