fix expose multi protocols issue

This commit is contained in:
AdoHe
2016-05-12 00:07:07 -04:00
parent def7639457
commit ad97cddb3e
11 changed files with 293 additions and 8 deletions

View File

@@ -102,6 +102,48 @@ func TestPortsForObject(t *testing.T) {
}
}
func TestProtocolsForObject(t *testing.T) {
f := NewFactory(nil)
pod := &api.Pod{
ObjectMeta: api.ObjectMeta{Name: "baz", Namespace: "test", ResourceVersion: "12"},
Spec: api.PodSpec{
Containers: []api.Container{
{
Ports: []api.ContainerPort{
{
ContainerPort: 101,
Protocol: api.ProtocolTCP,
},
{
ContainerPort: 102,
Protocol: api.ProtocolUDP,
},
},
},
},
},
}
expected := "101/TCP,102/UDP"
protocolsMap, err := f.ProtocolsForObject(pod)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
got := kubectl.MakeProtocols(protocolsMap)
expectedSlice := strings.Split(expected, ",")
gotSlice := strings.Split(got, ",")
sort.Strings(expectedSlice)
sort.Strings(gotSlice)
for i, protocol := range gotSlice {
if protocol != expectedSlice[i] {
t.Fatalf("Protocols mismatch! Expected %s, got %s", expectedSlice[i], protocol)
}
}
}
func TestLabelsForObject(t *testing.T) {
f := NewFactory(nil)