kubectl/describe/svc: refactor TestDescribeService
Signed-off-by: Daman Arora <aroradaman@gmail.com> Kubernetes-commit: df417aa9b8813d0e5e1208e9039f140edeff39db
This commit is contained in:
parent
771a13a844
commit
5aca4630e4
|
@ -25,6 +25,9 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
|
"github.com/lithammer/dedent"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
appsv1 "k8s.io/api/apps/v1"
|
appsv1 "k8s.io/api/apps/v1"
|
||||||
autoscalingv1 "k8s.io/api/autoscaling/v1"
|
autoscalingv1 "k8s.io/api/autoscaling/v1"
|
||||||
autoscalingv2 "k8s.io/api/autoscaling/v2"
|
autoscalingv2 "k8s.io/api/autoscaling/v2"
|
||||||
|
@ -654,7 +657,7 @@ func TestDescribeService(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
service *corev1.Service
|
service *corev1.Service
|
||||||
expect []string
|
expected string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "test1",
|
name: "test1",
|
||||||
|
@ -676,24 +679,31 @@ func TestDescribeService(t *testing.T) {
|
||||||
ClusterIP: "1.2.3.4",
|
ClusterIP: "1.2.3.4",
|
||||||
IPFamilies: []corev1.IPFamily{corev1.IPv4Protocol},
|
IPFamilies: []corev1.IPFamily{corev1.IPv4Protocol},
|
||||||
LoadBalancerIP: "5.6.7.8",
|
LoadBalancerIP: "5.6.7.8",
|
||||||
SessionAffinity: "None",
|
SessionAffinity: corev1.ServiceAffinityNone,
|
||||||
ExternalTrafficPolicy: "Local",
|
ExternalTrafficPolicy: corev1.ServiceExternalTrafficPolicyLocal,
|
||||||
HealthCheckNodePort: 32222,
|
HealthCheckNodePort: 32222,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expect: []string{
|
expected: dedent.Dedent(`
|
||||||
"Name", "bar",
|
Name: bar
|
||||||
"Namespace", "foo",
|
Namespace: foo
|
||||||
"Selector", "blah=heh",
|
Labels: <none>
|
||||||
"Type", "LoadBalancer",
|
Annotations: <none>
|
||||||
"IP", "1.2.3.4",
|
Selector: blah=heh
|
||||||
"Port", "port-tcp", "8080/TCP",
|
Type: LoadBalancer
|
||||||
"TargetPort", "9527/TCP",
|
IP Families: IPv4
|
||||||
"NodePort", "port-tcp", "31111/TCP",
|
IP: 1.2.3.4
|
||||||
"Session Affinity", "None",
|
IPs: <none>
|
||||||
"External Traffic Policy", "Local",
|
IP: 5.6.7.8
|
||||||
"HealthCheck NodePort", "32222",
|
Port: port-tcp 8080/TCP
|
||||||
},
|
TargetPort: 9527/TCP
|
||||||
|
NodePort: port-tcp 31111/TCP
|
||||||
|
Endpoints: <none>
|
||||||
|
Session Affinity: None
|
||||||
|
External Traffic Policy: Local
|
||||||
|
HealthCheck NodePort: 32222
|
||||||
|
Events: <none>
|
||||||
|
`)[1:],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "test2",
|
name: "test2",
|
||||||
|
@ -715,24 +725,31 @@ func TestDescribeService(t *testing.T) {
|
||||||
ClusterIP: "1.2.3.4",
|
ClusterIP: "1.2.3.4",
|
||||||
IPFamilies: []corev1.IPFamily{corev1.IPv4Protocol},
|
IPFamilies: []corev1.IPFamily{corev1.IPv4Protocol},
|
||||||
LoadBalancerIP: "5.6.7.8",
|
LoadBalancerIP: "5.6.7.8",
|
||||||
SessionAffinity: "None",
|
SessionAffinity: corev1.ServiceAffinityNone,
|
||||||
ExternalTrafficPolicy: "Local",
|
ExternalTrafficPolicy: corev1.ServiceExternalTrafficPolicyLocal,
|
||||||
HealthCheckNodePort: 32222,
|
HealthCheckNodePort: 32222,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expect: []string{
|
expected: dedent.Dedent(`
|
||||||
"Name", "bar",
|
Name: bar
|
||||||
"Namespace", "foo",
|
Namespace: foo
|
||||||
"Selector", "blah=heh",
|
Labels: <none>
|
||||||
"Type", "LoadBalancer",
|
Annotations: <none>
|
||||||
"IP", "1.2.3.4",
|
Selector: blah=heh
|
||||||
"Port", "port-tcp", "8080/TCP",
|
Type: LoadBalancer
|
||||||
"TargetPort", "targetPort/TCP",
|
IP Families: IPv4
|
||||||
"NodePort", "port-tcp", "31111/TCP",
|
IP: 1.2.3.4
|
||||||
"Session Affinity", "None",
|
IPs: <none>
|
||||||
"External Traffic Policy", "Local",
|
IP: 5.6.7.8
|
||||||
"HealthCheck NodePort", "32222",
|
Port: port-tcp 8080/TCP
|
||||||
},
|
TargetPort: targetPort/TCP
|
||||||
|
NodePort: port-tcp 31111/TCP
|
||||||
|
Endpoints: <none>
|
||||||
|
Session Affinity: None
|
||||||
|
External Traffic Policy: Local
|
||||||
|
HealthCheck NodePort: 32222
|
||||||
|
Events: <none>
|
||||||
|
`)[1:],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "test-ServiceIPFamily",
|
name: "test-ServiceIPFamily",
|
||||||
|
@ -754,25 +771,31 @@ func TestDescribeService(t *testing.T) {
|
||||||
ClusterIP: "1.2.3.4",
|
ClusterIP: "1.2.3.4",
|
||||||
IPFamilies: []corev1.IPFamily{corev1.IPv4Protocol},
|
IPFamilies: []corev1.IPFamily{corev1.IPv4Protocol},
|
||||||
LoadBalancerIP: "5.6.7.8",
|
LoadBalancerIP: "5.6.7.8",
|
||||||
SessionAffinity: "None",
|
SessionAffinity: corev1.ServiceAffinityNone,
|
||||||
ExternalTrafficPolicy: "Local",
|
ExternalTrafficPolicy: corev1.ServiceExternalTrafficPolicyLocal,
|
||||||
HealthCheckNodePort: 32222,
|
HealthCheckNodePort: 32222,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expect: []string{
|
expected: dedent.Dedent(`
|
||||||
"Name", "bar",
|
Name: bar
|
||||||
"Namespace", "foo",
|
Namespace: foo
|
||||||
"Selector", "blah=heh",
|
Labels: <none>
|
||||||
"Type", "LoadBalancer",
|
Annotations: <none>
|
||||||
"IP", "1.2.3.4",
|
Selector: blah=heh
|
||||||
"IP Families", "IPv4",
|
Type: LoadBalancer
|
||||||
"Port", "port-tcp", "8080/TCP",
|
IP Families: IPv4
|
||||||
"TargetPort", "targetPort/TCP",
|
IP: 1.2.3.4
|
||||||
"NodePort", "port-tcp", "31111/TCP",
|
IPs: <none>
|
||||||
"Session Affinity", "None",
|
IP: 5.6.7.8
|
||||||
"External Traffic Policy", "Local",
|
Port: port-tcp 8080/TCP
|
||||||
"HealthCheck NodePort", "32222",
|
TargetPort: targetPort/TCP
|
||||||
},
|
NodePort: port-tcp 31111/TCP
|
||||||
|
Endpoints: <none>
|
||||||
|
Session Affinity: None
|
||||||
|
External Traffic Policy: Local
|
||||||
|
HealthCheck NodePort: 32222
|
||||||
|
Events: <none>
|
||||||
|
`)[1:],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "test-ServiceIPFamilyPolicy+ClusterIPs",
|
name: "test-ServiceIPFamilyPolicy+ClusterIPs",
|
||||||
|
@ -796,43 +819,45 @@ func TestDescribeService(t *testing.T) {
|
||||||
IPFamilyPolicy: &singleStack,
|
IPFamilyPolicy: &singleStack,
|
||||||
ClusterIPs: []string{"1.2.3.4"},
|
ClusterIPs: []string{"1.2.3.4"},
|
||||||
LoadBalancerIP: "5.6.7.8",
|
LoadBalancerIP: "5.6.7.8",
|
||||||
SessionAffinity: "None",
|
SessionAffinity: corev1.ServiceAffinityNone,
|
||||||
ExternalTrafficPolicy: "Local",
|
ExternalTrafficPolicy: corev1.ServiceExternalTrafficPolicyLocal,
|
||||||
HealthCheckNodePort: 32222,
|
HealthCheckNodePort: 32222,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expect: []string{
|
expected: dedent.Dedent(`
|
||||||
"Name", "bar",
|
Name: bar
|
||||||
"Namespace", "foo",
|
Namespace: foo
|
||||||
"Selector", "blah=heh",
|
Labels: <none>
|
||||||
"Type", "LoadBalancer",
|
Annotations: <none>
|
||||||
"IP", "1.2.3.4",
|
Selector: blah=heh
|
||||||
"IP Families", "IPv4",
|
Type: LoadBalancer
|
||||||
"IP Family Policy", "SingleStack",
|
IP Family Policy: SingleStack
|
||||||
"IPs", "1.2.3.4",
|
IP Families: IPv4
|
||||||
"Port", "port-tcp", "8080/TCP",
|
IP: 1.2.3.4
|
||||||
"TargetPort", "targetPort/TCP",
|
IPs: 1.2.3.4
|
||||||
"NodePort", "port-tcp", "31111/TCP",
|
IP: 5.6.7.8
|
||||||
"Session Affinity", "None",
|
Port: port-tcp 8080/TCP
|
||||||
"External Traffic Policy", "Local",
|
TargetPort: targetPort/TCP
|
||||||
"HealthCheck NodePort", "32222",
|
NodePort: port-tcp 31111/TCP
|
||||||
},
|
Endpoints: <none>
|
||||||
|
Session Affinity: None
|
||||||
|
External Traffic Policy: Local
|
||||||
|
HealthCheck NodePort: 32222
|
||||||
|
Events: <none>
|
||||||
|
`)[1:],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, testCase := range testCases {
|
for _, tc := range testCases {
|
||||||
t.Run(testCase.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
fake := fake.NewSimpleClientset(testCase.service)
|
fakeClient := fake.NewSimpleClientset(tc.service)
|
||||||
c := &describeClient{T: t, Namespace: "foo", Interface: fake}
|
c := &describeClient{T: t, Namespace: "foo", Interface: fakeClient}
|
||||||
d := ServiceDescriber{c}
|
d := ServiceDescriber{c}
|
||||||
out, err := d.Describe("foo", "bar", DescriberSettings{ShowEvents: true})
|
out, err := d.Describe("foo", "bar", DescriberSettings{ShowEvents: true})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
for _, expected := range testCase.expect {
|
|
||||||
if !strings.Contains(out, expected) {
|
assert.Equal(t, tc.expected, out)
|
||||||
t.Errorf("expected to find %q in output: %q", expected, out)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue