Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverMKing committed Apr 1, 2024
1 parent 37f99f0 commit 49187f4
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/manifests/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func withTypicalReadinessProbe(port int, contain *corev1.Container) *corev1.Cont
func withLivenessProbeMatchingReadinessNewFailureThresh(contain *corev1.Container, failureThresh int32) *corev1.Container {
copy := withLivenessProbeMatchingReadiness(contain)

if copy.LivenessProbe != nil {
if copy != nil && copy.LivenessProbe != nil {
copy.LivenessProbe.FailureThreshold = failureThresh
}

Expand Down
92 changes: 92 additions & 0 deletions pkg/manifests/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,98 @@ func TestHasTopLevelLabels(t *testing.T) {
}
}

func TestWithLivenessProbeMatchingReadinessNewFailureThresh(t *testing.T) {
cases := []struct {
name string
inputContainer *corev1.Container
failureThresh int32
expected corev1.Container
}{
{
name: "empty readiness",
inputContainer: &corev1.Container{
Name: "name",
},
failureThresh: 2,
expected: corev1.Container{
Name: "name",
},
},
{
name: "new failure thresh",
inputContainer: &corev1.Container{
Name: "name",
ReadinessProbe: &corev1.Probe{
FailureThreshold: 2,
},
},
failureThresh: 10,
expected: corev1.Container{
Name: "name",
ReadinessProbe: &corev1.Probe{
FailureThreshold: 2,
},
LivenessProbe: &corev1.Probe{
FailureThreshold: 10,
},
},
},
{
name: "new failure thresh with other fields",
inputContainer: &corev1.Container{
Name: "name",
ReadinessProbe: &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/healthz",
},
},
FailureThreshold: 2,
SuccessThreshold: 1,
TimeoutSeconds: 2,
PeriodSeconds: 12,
InitialDelaySeconds: 3,
},
},
failureThresh: 200,
expected: corev1.Container{
Name: "name",
ReadinessProbe: &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/healthz",
},
},
FailureThreshold: 2,
SuccessThreshold: 1,
TimeoutSeconds: 2,
PeriodSeconds: 12,
InitialDelaySeconds: 3,
},
LivenessProbe: &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/healthz",
},
},
FailureThreshold: 200,
SuccessThreshold: 1,
TimeoutSeconds: 2,
PeriodSeconds: 12,
InitialDelaySeconds: 3,
},
},
},
}

for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
got := withLivenessProbeMatchingReadinessNewFailureThresh(c.inputContainer, c.failureThresh)
require.Equal(t, c.expected, *got)
})
}
}

func TestGetOwnerRefs(t *testing.T) {
cases := []struct {
Name string
Expand Down

0 comments on commit 49187f4

Please sign in to comment.