From 544fa209d56f1ce079d80443359769b14c243e71 Mon Sep 17 00:00:00 2001 From: Roberto Santalla Date: Thu, 14 Sep 2023 17:37:29 +0200 Subject: [PATCH] fixtures: add fixtures for building pods without probes --- e2e/disruptors/pod_e2e_test.go | 19 ++++++++++--------- e2e/disruptors/service_e2e_test.go | 10 +++++----- pkg/testutils/e2e/fixtures/fixtures.go | 16 ++++++++++++++++ 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/e2e/disruptors/pod_e2e_test.go b/e2e/disruptors/pod_e2e_test.go index 86d5a828..21974248 100644 --- a/e2e/disruptors/pod_e2e_test.go +++ b/e2e/disruptors/pod_e2e_test.go @@ -70,11 +70,12 @@ func Test_PodDisruptor(t *testing.T) { check checks.Check }{ { - title: "Inject Http error 500", - pod: fixtures.BuildHttpbinPod(), + + title: "Inject Http error 500", + pod: fixtures.BuildHttpbinPodWithoutProbes(), replicas: 1, - service: fixtures.BuildHttpbinService(), - port: 80, + service: fixtures.BuildHttpbinService(), + port: 80, injector: func(d disruptors.PodDisruptor) error { fault := disruptors.HTTPFault{ Port: intstr.FromInt32(80), @@ -97,11 +98,11 @@ func Test_PodDisruptor(t *testing.T) { }, }, { - title: "Inject Grpc error", - pod: fixtures.BuildGrpcpbinPod(), + title: "Inject Grpc error", + pod: fixtures.BuildGrpcpbinPod(), replicas: 1, - service: fixtures.BuildGrpcbinService(), - port: 9000, + service: fixtures.BuildGrpcbinService(), + port: 9000, injector: func(d disruptors.PodDisruptor) error { fault := disruptors.GrpcFault{ Port: intstr.FromInt32(9000), @@ -231,7 +232,7 @@ func Test_PodDisruptor(t *testing.T) { err = deploy.ExposeApp( k8s, namespace, - fixtures.BuildHttpbinPod(), + fixtures.BuildHttpbinPodWithoutProbes(), // Probes generate requests, invalidating the test. 1, service, k8sintstr.FromInt(80), diff --git a/e2e/disruptors/service_e2e_test.go b/e2e/disruptors/service_e2e_test.go index a2d827f0..9f38024d 100644 --- a/e2e/disruptors/service_e2e_test.go +++ b/e2e/disruptors/service_e2e_test.go @@ -63,11 +63,11 @@ func Test_ServiceDisruptor(t *testing.T) { check checks.Check }{ { - title: "Inject Http error 500", - pod: fixtures.BuildHttpbinPod(), - replicas: 1, - service: fixtures.BuildHttpbinService(), - port: 80, + + title: "Inject Http error 500", + pod: fixtures.BuildHttpbinPodWithoutProbes(), + service: fixtures.BuildHttpbinService(), + port: 80, injector: func(d disruptors.ServiceDisruptor) error { fault := disruptors.HTTPFault{ Port: intstr.FromInt32(80), diff --git a/pkg/testutils/e2e/fixtures/fixtures.go b/pkg/testutils/e2e/fixtures/fixtures.go index 6d4dc07c..fdcb5784 100644 --- a/pkg/testutils/e2e/fixtures/fixtures.go +++ b/pkg/testutils/e2e/fixtures/fixtures.go @@ -23,6 +23,14 @@ func BuildHttpbinPod() corev1.Pod { Build() } +// BuildHttpbinPodWithoutProbes returns the same pod as BuildHttpbinPod would, but without any probes. +func BuildHttpbinPodWithoutProbes() corev1.Pod { + pod := BuildHttpbinPod() + pod.Spec.Containers[0].ReadinessProbe = nil + + return pod +} + // BuildGrpcpbinPod returns the definition for deploying grpcbin as a Pod func BuildGrpcpbinPod() corev1.Pod { c := builders.NewContainerBuilder("grpcbin"). @@ -97,6 +105,14 @@ func BuildNginxPod() corev1.Pod { Build() } +// BuildNginxPodWithoutProbes returns the same pod as BuildNginxPod would, but without any probes. +func BuildNginxPodWithoutProbes() corev1.Pod { + pod := BuildNginxPod() + pod.Spec.Containers[0].ReadinessProbe = nil + + return pod +} + // BuildNginxService returns the definition of a Service that exposes the nginx pod(s) func BuildNginxService() corev1.Service { return builders.NewServiceBuilder("nginx").