@@ -21,9 +21,9 @@ import (
21
21
"fmt"
22
22
"math/rand"
23
23
"os"
24
+ "reflect"
24
25
"strings"
25
26
"testing"
26
- "reflect"
27
27
28
28
enterpriseApi "github.com/splunk/splunk-operator/api/v4"
29
29
"github.com/stretchr/testify/require"
@@ -75,12 +75,8 @@ func marshalAndCompare(t *testing.T, compare interface{}, method string, want st
75
75
if err != nil {
76
76
t .Errorf ("%s failed to marshall" , err )
77
77
}
78
- actual := strings .ReplaceAll (string (got ), " " , "" )
79
78
want = strings .ReplaceAll (want , " " , "" )
80
79
81
- if actual != want {
82
- t .Errorf ("Method %s, got = %s;\n want %s" , method , got , want )
83
- }
84
80
require .JSONEq (t , string (got ), want )
85
81
}
86
82
@@ -1762,38 +1758,38 @@ func TestValidateLivenessProbe(t *testing.T) {
1762
1758
}
1763
1759
1764
1760
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
+ })
1799
1795
}
0 commit comments