Skip to content

Commit 00e36a9

Browse files
author
Patryk Wasielewski
committed
fix tests
1 parent 7418914 commit 00e36a9

File tree

2 files changed

+36
-39
lines changed

2 files changed

+36
-39
lines changed

pkg/splunk/enterprise/clustermanager_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,6 +1479,7 @@ func TestIsClusterManagerReadyForUpgrade(t *testing.T) {
14791479
Spec: enterpriseApi.Spec{
14801480
ImagePullPolicy: "Always",
14811481
Image: "splunk/splunk:latest",
1482+
TerminationGracePeriodSeconds: 20,
14821483
},
14831484
Volumes: []corev1.Volume{},
14841485
LicenseManagerRef: corev1.ObjectReference{

pkg/splunk/enterprise/configuration_test.go

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ import (
2121
"fmt"
2222
"math/rand"
2323
"os"
24+
"reflect"
2425
"strings"
2526
"testing"
26-
"reflect"
2727

2828
enterpriseApi "github.com/splunk/splunk-operator/api/v4"
2929
"github.com/stretchr/testify/require"
@@ -75,12 +75,8 @@ func marshalAndCompare(t *testing.T, compare interface{}, method string, want st
7575
if err != nil {
7676
t.Errorf("%s failed to marshall", err)
7777
}
78-
actual := strings.ReplaceAll(string(got), " ", "")
7978
want = strings.ReplaceAll(want, " ", "")
8079

81-
if actual != want {
82-
t.Errorf("Method %s, got = %s;\nwant %s", method, got, want)
83-
}
8480
require.JSONEq(t, string(got), want)
8581
}
8682

@@ -1762,38 +1758,38 @@ func TestValidateLivenessProbe(t *testing.T) {
17621758
}
17631759

17641760
func TestSetPreStopLifecycleHandler(t *testing.T) {
1765-
// Create a pod template spec with a single container
1766-
podTemplateSpec := corev1.PodTemplateSpec{
1767-
Spec: corev1.PodSpec{
1768-
Containers: []corev1.Container{
1769-
{Name: "splunk"},
1770-
},
1771-
},
1772-
}
1773-
1774-
// Index of the container to apply the lifecycle handler
1775-
idx := 0
1776-
1777-
// Set the lifecycle handler
1778-
setPreStopLifecycleHandler(&podTemplateSpec, idx)
1779-
1780-
t.Run("test lifecycle pre-stop handler", func(t *testing.T) {
1781-
// Verify that the lifecycle handler was set correctly
1782-
if podTemplateSpec.Spec.Containers[idx].Lifecycle == nil {
1783-
t.Error("Expected Lifecycle to be set, but it was nil")
1784-
}
1785-
1786-
if podTemplateSpec.Spec.Containers[idx].Lifecycle.PreStop == nil {
1787-
t.Error("Expected PreStop to be set, but it was nil")
1788-
}
1789-
1790-
if podTemplateSpec.Spec.Containers[idx].Lifecycle.PreStop.Exec == nil {
1791-
t.Error("Expected Exec to be set, but it was nil")
1792-
}
1793-
1794-
expectedCommand := []string{"/bin/sh", "-c", "/opt/splunk/bin/splunk offline && /opt/splunk/bin/splunk stop"}
1795-
if !reflect.DeepEqual(podTemplateSpec.Spec.Containers[idx].Lifecycle.PreStop.Exec.Command, expectedCommand) {
1796-
t.Errorf("Expected command to be %v, but got %v", expectedCommand, podTemplateSpec.Spec.Containers[idx].Lifecycle.PreStop.Exec.Command)
1797-
}
1798-
})
1761+
// Create a pod template spec with a single container
1762+
podTemplateSpec := corev1.PodTemplateSpec{
1763+
Spec: corev1.PodSpec{
1764+
Containers: []corev1.Container{
1765+
{Name: "splunk"},
1766+
},
1767+
},
1768+
}
1769+
1770+
// Index of the container to apply the lifecycle handler
1771+
idx := 0
1772+
1773+
// Set the lifecycle handler
1774+
setPreStopLifecycleHandler(&podTemplateSpec, idx)
1775+
1776+
t.Run("test lifecycle pre-stop handler", func(t *testing.T) {
1777+
// Verify that the lifecycle handler was set correctly
1778+
if podTemplateSpec.Spec.Containers[idx].Lifecycle == nil {
1779+
t.Error("Expected Lifecycle to be set, but it was nil")
1780+
}
1781+
1782+
if podTemplateSpec.Spec.Containers[idx].Lifecycle.PreStop == nil {
1783+
t.Error("Expected PreStop to be set, but it was nil")
1784+
}
1785+
1786+
if podTemplateSpec.Spec.Containers[idx].Lifecycle.PreStop.Exec == nil {
1787+
t.Error("Expected Exec to be set, but it was nil")
1788+
}
1789+
1790+
expectedCommand := []string{"/bin/sh", "-c", "/opt/splunk/bin/splunk offline && /opt/splunk/bin/splunk stop"}
1791+
if !reflect.DeepEqual(podTemplateSpec.Spec.Containers[idx].Lifecycle.PreStop.Exec.Command, expectedCommand) {
1792+
t.Errorf("Expected command to be %v, but got %v", expectedCommand, podTemplateSpec.Spec.Containers[idx].Lifecycle.PreStop.Exec.Command)
1793+
}
1794+
})
17991795
}

0 commit comments

Comments
 (0)