mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-06 16:06:51 +00:00
Merge pull request #24090 from AdoHe/expose_rc
Automatic merge from submit-queue fix expose multi protocols issue Please refer #23882 for more detail. @bprashanth @bgrant0607 ptal. <!-- Reviewable:start --> --- This change is [<img src="http://reviewable.k8s.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](http://reviewable.k8s.io/reviews/kubernetes/kubernetes/24090) <!-- Reviewable:end -->
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user