From 97e2576750dffd01df9eae103722d0b33a8a4603 Mon Sep 17 00:00:00 2001 From: Guangming Wang Date: Sun, 29 Sep 2019 22:02:22 +0800 Subject: [PATCH] hostport return error when claim SCTP type port revert last changes, just modify typos in unit test, and remove failed assert sub count of sctp port when assert of len compare --- .../network/hostport/hostport_manager_test.go | 42 +++++++++++-------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/pkg/kubelet/dockershim/network/hostport/hostport_manager_test.go b/pkg/kubelet/dockershim/network/hostport/hostport_manager_test.go index 9a9e151f52e..bee60dc8237 100644 --- a/pkg/kubelet/dockershim/network/hostport/hostport_manager_test.go +++ b/pkg/kubelet/dockershim/network/hostport/hostport_manager_test.go @@ -45,9 +45,9 @@ func TestOpenCloseHostports(t *testing.T) { Namespace: "ns1", Name: "n1", PortMappings: []*PortMapping{ - {HostPort: 80, Protocol: v1.Protocol("TCP")}, - {HostPort: 8080, Protocol: v1.Protocol("TCP")}, - {HostPort: 443, Protocol: v1.Protocol("TCP")}, + {HostPort: 80, Protocol: v1.ProtocolTCP}, + {HostPort: 8080, Protocol: v1.ProtocolTCP}, + {HostPort: 443, Protocol: v1.ProtocolTCP}, }, }, false, @@ -57,7 +57,7 @@ func TestOpenCloseHostports(t *testing.T) { Namespace: "ns1", Name: "n2", PortMappings: []*PortMapping{ - {HostPort: 80, Protocol: v1.Protocol("TCP")}, + {HostPort: 80, Protocol: v1.ProtocolTCP}, }, }, true, @@ -67,8 +67,8 @@ func TestOpenCloseHostports(t *testing.T) { Namespace: "ns1", Name: "n3", PortMappings: []*PortMapping{ - {HostPort: 8081, Protocol: v1.Protocol("TCP")}, - {HostPort: 8080, Protocol: v1.Protocol("TCP")}, + {HostPort: 8081, Protocol: v1.ProtocolTCP}, + {HostPort: 8080, Protocol: v1.ProtocolTCP}, }, }, true, @@ -78,7 +78,7 @@ func TestOpenCloseHostports(t *testing.T) { Namespace: "ns1", Name: "n3", PortMappings: []*PortMapping{ - {HostPort: 8081, Protocol: v1.Protocol("TCP")}, + {HostPort: 8081, Protocol: v1.ProtocolTCP}, }, }, false, @@ -88,7 +88,7 @@ func TestOpenCloseHostports(t *testing.T) { Namespace: "ns1", Name: "n4", PortMappings: []*PortMapping{ - {HostPort: 7777, Protocol: v1.Protocol("STCP")}, + {HostPort: 7777, Protocol: v1.ProtocolSCTP}, }, }, false, @@ -111,7 +111,13 @@ func TestOpenCloseHostports(t *testing.T) { continue } assert.NoError(t, err) - assert.EqualValues(t, len(mapping), len(tc.podPortMapping.PortMappings)) + countSctp := 0 + for _, pm := range tc.podPortMapping.PortMappings { + if pm.Protocol == v1.ProtocolSCTP { + countSctp += 1 + } + } + assert.EqualValues(t, len(mapping), len(tc.podPortMapping.PortMappings)-countSctp) } // We have 4 ports: 80, 443, 8080, 8081 open now. @@ -125,36 +131,36 @@ func TestOpenCloseHostports(t *testing.T) { { portMappings: []*PortMapping{ - {HostPort: 80, Protocol: v1.Protocol("TCP")}, - {HostPort: 8080, Protocol: v1.Protocol("TCP")}, - {HostPort: 443, Protocol: v1.Protocol("TCP")}, + {HostPort: 80, Protocol: v1.ProtocolTCP}, + {HostPort: 8080, Protocol: v1.ProtocolTCP}, + {HostPort: 443, Protocol: v1.ProtocolTCP}, }, }, { portMappings: []*PortMapping{ - {HostPort: 80, Protocol: v1.Protocol("TCP")}, + {HostPort: 80, Protocol: v1.ProtocolTCP}, }, }, { portMappings: []*PortMapping{ - {HostPort: 8081, Protocol: v1.Protocol("TCP")}, - {HostPort: 8080, Protocol: v1.Protocol("TCP")}, + {HostPort: 8081, Protocol: v1.ProtocolTCP}, + {HostPort: 8080, Protocol: v1.ProtocolTCP}, }, }, { portMappings: []*PortMapping{ - {HostPort: 8081, Protocol: v1.Protocol("TCP")}, + {HostPort: 8081, Protocol: v1.ProtocolTCP}, }, }, { portMappings: []*PortMapping{ - {HostPort: 7070, Protocol: v1.Protocol("TCP")}, + {HostPort: 7070, Protocol: v1.ProtocolTCP}, }, }, { portMappings: []*PortMapping{ - {HostPort: 7777, Protocol: v1.Protocol("SCTP")}, + {HostPort: 7777, Protocol: v1.ProtocolSCTP}, }, }, }