Commit 25f37007 authored by Saad Ali's avatar Saad Ali

Merge pull request #24846 from pmorie/kubelet-test-loc

Reduce LOC in kubelet tests
parents 19169889 d1e0e726
...@@ -674,37 +674,29 @@ func TestFindContainersByPod(t *testing.T) { ...@@ -674,37 +674,29 @@ func TestFindContainersByPod(t *testing.T) {
} }
func TestMakePortsAndBindings(t *testing.T) { func TestMakePortsAndBindings(t *testing.T) {
portMapping := func(container, host int, protocol api.Protocol, ip string) kubecontainer.PortMapping {
return kubecontainer.PortMapping{
ContainerPort: container,
HostPort: host,
Protocol: protocol,
HostIP: ip,
}
}
portBinding := func(port, ip string) dockernat.PortBinding {
return dockernat.PortBinding{
HostPort: port,
HostIP: ip,
}
}
ports := []kubecontainer.PortMapping{ ports := []kubecontainer.PortMapping{
{ portMapping(80, 8080, "", "127.0.0.1"),
ContainerPort: 80, portMapping(443, 443, "tcp", ""),
HostPort: 8080, portMapping(444, 444, "udp", ""),
HostIP: "127.0.0.1", portMapping(445, 445, "foobar", ""),
}, portMapping(443, 446, "tcp", ""),
{ portMapping(443, 446, "udp", ""),
ContainerPort: 443,
HostPort: 443,
Protocol: "tcp",
},
{
ContainerPort: 444,
HostPort: 444,
Protocol: "udp",
},
{
ContainerPort: 445,
HostPort: 445,
Protocol: "foobar",
},
{
ContainerPort: 443,
HostPort: 446,
Protocol: "tcp",
},
{
ContainerPort: 443,
HostPort: 446,
Protocol: "udp",
},
} }
exposedPorts, bindings := makePortsAndBindings(ports) exposedPorts, bindings := makePortsAndBindings(ports)
...@@ -725,38 +717,20 @@ func TestMakePortsAndBindings(t *testing.T) { ...@@ -725,38 +717,20 @@ func TestMakePortsAndBindings(t *testing.T) {
// Construct expected bindings // Construct expected bindings
expectPortBindings := map[string][]dockernat.PortBinding{ expectPortBindings := map[string][]dockernat.PortBinding{
"80/tcp": { "80/tcp": {
dockernat.PortBinding{ portBinding("8080", "127.0.0.1"),
HostPort: "8080",
HostIP: "127.0.0.1",
},
}, },
"443/tcp": { "443/tcp": {
dockernat.PortBinding{ portBinding("443", ""),
HostPort: "443", portBinding("446", ""),
HostIP: "",
},
dockernat.PortBinding{
HostPort: "446",
HostIP: "",
},
}, },
"443/udp": { "443/udp": {
dockernat.PortBinding{ portBinding("446", ""),
HostPort: "446",
HostIP: "",
},
}, },
"444/udp": { "444/udp": {
dockernat.PortBinding{ portBinding("444", ""),
HostPort: "444",
HostIP: "",
},
}, },
"445/tcp": { "445/tcp": {
dockernat.PortBinding{ portBinding("445", ""),
HostPort: "445",
HostIP: "",
},
}, },
} }
......
...@@ -229,36 +229,12 @@ func TestFakePodWorkers(t *testing.T) { ...@@ -229,36 +229,12 @@ func TestFakePodWorkers(t *testing.T) {
&api.Pod{}, &api.Pod{},
}, },
{ {
&api.Pod{ podWithUidNameNs("12345678", "foo", "new"),
ObjectMeta: api.ObjectMeta{ podWithUidNameNs("12345678", "fooMirror", "new"),
UID: "12345678",
Name: "foo",
Namespace: "new",
},
},
&api.Pod{
ObjectMeta: api.ObjectMeta{
UID: "12345678",
Name: "fooMirror",
Namespace: "new",
},
},
}, },
{ {
&api.Pod{ podWithUidNameNs("98765", "bar", "new"),
ObjectMeta: api.ObjectMeta{ podWithUidNameNs("98765", "barMirror", "new"),
UID: "98765",
Name: "bar",
Namespace: "new",
},
},
&api.Pod{
ObjectMeta: api.ObjectMeta{
UID: "98765",
Name: "barMirror",
Namespace: "new",
},
},
}, },
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment