mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-06 07:57:35 +00:00
kubectl: move printObjectSpecificMessage in factory
This commit is contained in:
@@ -623,3 +623,94 @@ func TestGetFirstPod(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrintObjectSpecificMessage(t *testing.T) {
|
||||
f := NewFactory(nil)
|
||||
tests := []struct {
|
||||
obj runtime.Object
|
||||
expectOutput bool
|
||||
}{
|
||||
{
|
||||
obj: &api.Service{},
|
||||
expectOutput: false,
|
||||
},
|
||||
{
|
||||
obj: &api.Pod{},
|
||||
expectOutput: false,
|
||||
},
|
||||
{
|
||||
obj: &api.Service{Spec: api.ServiceSpec{Type: api.ServiceTypeLoadBalancer}},
|
||||
expectOutput: false,
|
||||
},
|
||||
{
|
||||
obj: &api.Service{Spec: api.ServiceSpec{Type: api.ServiceTypeNodePort}},
|
||||
expectOutput: true,
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
buff := &bytes.Buffer{}
|
||||
f.PrintObjectSpecificMessage(test.obj, buff)
|
||||
if test.expectOutput && buff.Len() == 0 {
|
||||
t.Errorf("Expected output, saw none for %v", test.obj)
|
||||
}
|
||||
if !test.expectOutput && buff.Len() > 0 {
|
||||
t.Errorf("Expected no output, saw %s for %v", buff.String(), test.obj)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMakePortsString(t *testing.T) {
|
||||
tests := []struct {
|
||||
ports []api.ServicePort
|
||||
useNodePort bool
|
||||
expectedOutput string
|
||||
}{
|
||||
{ports: nil, expectedOutput: ""},
|
||||
{ports: []api.ServicePort{}, expectedOutput: ""},
|
||||
{ports: []api.ServicePort{
|
||||
{
|
||||
Port: 80,
|
||||
Protocol: "TCP",
|
||||
},
|
||||
},
|
||||
expectedOutput: "tcp:80",
|
||||
},
|
||||
{ports: []api.ServicePort{
|
||||
{
|
||||
Port: 80,
|
||||
Protocol: "TCP",
|
||||
},
|
||||
{
|
||||
Port: 8080,
|
||||
Protocol: "UDP",
|
||||
},
|
||||
{
|
||||
Port: 9000,
|
||||
Protocol: "TCP",
|
||||
},
|
||||
},
|
||||
expectedOutput: "tcp:80,udp:8080,tcp:9000",
|
||||
},
|
||||
{ports: []api.ServicePort{
|
||||
{
|
||||
Port: 80,
|
||||
NodePort: 9090,
|
||||
Protocol: "TCP",
|
||||
},
|
||||
{
|
||||
Port: 8080,
|
||||
NodePort: 80,
|
||||
Protocol: "UDP",
|
||||
},
|
||||
},
|
||||
useNodePort: true,
|
||||
expectedOutput: "tcp:9090,udp:80",
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
output := makePortsString(test.ports, test.useNodePort)
|
||||
if output != test.expectedOutput {
|
||||
t.Errorf("expected: %s, saw: %s.", test.expectedOutput, output)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user