Skip to content

Commit f588c3a

Browse files
committed
CSPL-4281 Fix unit tests by mocking GetCMMultisiteEnvVarsCall
Add GetCMMultisiteEnvVarsCall mock to 5 ClusterManager tests that were failing due to attempted real HTTP calls to non-existent Splunk services. The mock prevents network requests and returns expected environment variables. Tests fixed: - TestApplyClusterManager - TestApplyClusterManagerWithSmartstore - TestAppFrameworkApplyClusterManagerShouldNotFail - TestApplyClusterManagerDeletion - TestIsClusterManagerReadyForUpgrade
1 parent 0d414a9 commit f588c3a

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

pkg/splunk/enterprise/clustermanager_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ func TestApplyClusterManager(t *testing.T) {
5555
return nil
5656
}
5757

58+
GetCMMultisiteEnvVarsCall = func(ctx context.Context, cr *enterpriseApi.ClusterManager, namespaceScopedSecret *corev1.Secret) ([]corev1.EnvVar, error) {
59+
extraEnv := getClusterManagerExtraEnv(cr, &cr.Spec.CommonSplunkSpec)
60+
return extraEnv, nil
61+
}
62+
5863
ctx := context.TODO()
5964
funcCalls := []spltest.MockFuncCall{
6065
{MetaName: "*v1.Secret-test-splunk-test-secret"},
@@ -542,6 +547,12 @@ func TestClusterManagerSpecNotCreatedWithoutGeneralTerms(t *testing.T) {
542547

543548
func TestApplyClusterManagerWithSmartstore(t *testing.T) {
544549
os.Setenv("SPLUNK_GENERAL_TERMS", "--accept-sgt-current-at-splunk-com")
550+
551+
GetCMMultisiteEnvVarsCall = func(ctx context.Context, cr *enterpriseApi.ClusterManager, namespaceScopedSecret *corev1.Secret) ([]corev1.EnvVar, error) {
552+
extraEnv := getClusterManagerExtraEnv(cr, &cr.Spec.CommonSplunkSpec)
553+
return extraEnv, nil
554+
}
555+
545556
ctx := context.TODO()
546557
funcCalls := []spltest.MockFuncCall{
547558
{MetaName: "*v1.Secret-test-splunk-test-secret"},
@@ -874,6 +885,12 @@ func TestPushManagerAppsBundle(t *testing.T) {
874885
func TestAppFrameworkApplyClusterManagerShouldNotFail(t *testing.T) {
875886
os.Setenv("SPLUNK_GENERAL_TERMS", "--accept-sgt-current-at-splunk-com")
876887
initGlobalResourceTracker()
888+
889+
GetCMMultisiteEnvVarsCall = func(ctx context.Context, cr *enterpriseApi.ClusterManager, namespaceScopedSecret *corev1.Secret) ([]corev1.EnvVar, error) {
890+
extraEnv := getClusterManagerExtraEnv(cr, &cr.Spec.CommonSplunkSpec)
891+
return extraEnv, nil
892+
}
893+
877894
ctx := context.TODO()
878895
cm := enterpriseApi.ClusterManager{
879896
ObjectMeta: metav1.ObjectMeta{
@@ -948,6 +965,12 @@ func TestAppFrameworkApplyClusterManagerShouldNotFail(t *testing.T) {
948965

949966
func TestApplyClusterManagerDeletion(t *testing.T) {
950967
os.Setenv("SPLUNK_GENERAL_TERMS", "--accept-sgt-current-at-splunk-com")
968+
969+
GetCMMultisiteEnvVarsCall = func(ctx context.Context, cr *enterpriseApi.ClusterManager, namespaceScopedSecret *corev1.Secret) ([]corev1.EnvVar, error) {
970+
extraEnv := getClusterManagerExtraEnv(cr, &cr.Spec.CommonSplunkSpec)
971+
return extraEnv, nil
972+
}
973+
951974
ctx := context.TODO()
952975
cm := enterpriseApi.ClusterManager{
953976
ObjectMeta: metav1.ObjectMeta{
@@ -1471,6 +1494,12 @@ func TestCheckIfsmartstoreConfigMapUpdatedToPod(t *testing.T) {
14711494

14721495
func TestIsClusterManagerReadyForUpgrade(t *testing.T) {
14731496
os.Setenv("SPLUNK_GENERAL_TERMS", "--accept-sgt-current-at-splunk-com")
1497+
1498+
GetCMMultisiteEnvVarsCall = func(ctx context.Context, cr *enterpriseApi.ClusterManager, namespaceScopedSecret *corev1.Secret) ([]corev1.EnvVar, error) {
1499+
extraEnv := getClusterManagerExtraEnv(cr, &cr.Spec.CommonSplunkSpec)
1500+
return extraEnv, nil
1501+
}
1502+
14741503
ctx := context.TODO()
14751504

14761505
sch := pkgruntime.NewScheme()

0 commit comments

Comments
 (0)