Skip to content

Commit 32f0429

Browse files
author
igor.grzankowski
committed
add publisher in test
1 parent 5e73c5f commit 32f0429

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

pkg/splunk/enterprise/clustermanager_test.go

Lines changed: 5 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+
// Mock the event publisher to avoid nil pointer issues in tests
59+
newK8EventPublisher = func(client splcommon.ControllerClient, instance interface{}) (*K8EventPublisher, error) {
60+
return &K8EventPublisher{}, nil
61+
}
62+
5863
ctx := context.TODO()
5964
funcCalls := []spltest.MockFuncCall{
6065
{MetaName: "*v1.Secret-test-splunk-test-secret"},

pkg/splunk/enterprise/events.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ type K8EventPublisher struct {
3232
instance interface{}
3333
}
3434

35-
// private function to get new k8s event publisher
36-
func newK8EventPublisher(client splcommon.ControllerClient, instance interface{}) (*K8EventPublisher, error) {
35+
// newK8EventPublisher is a variable to allow mocking in tests
36+
var newK8EventPublisher = func(client splcommon.ControllerClient, instance interface{}) (*K8EventPublisher, error) {
3737
eventPublisher := &K8EventPublisher{
3838
client: client,
3939
instance: instance,

0 commit comments

Comments
 (0)