From 403eac5f0f09f273c366cf00742a49f8859614f8 Mon Sep 17 00:00:00 2001 From: Joel Takvorian Date: Fri, 26 Jan 2024 10:40:25 +0100 Subject: [PATCH] Fix informers mock --- cmd/flowlogs-pipeline/main_test.go | 4 +--- pkg/pipeline/transform/kubernetes/enrich.go | 5 ----- pkg/pipeline/transform/kubernetes/informers-mock.go | 8 +++++++- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/cmd/flowlogs-pipeline/main_test.go b/cmd/flowlogs-pipeline/main_test.go index 732838fe4..fca40f8e9 100644 --- a/cmd/flowlogs-pipeline/main_test.go +++ b/cmd/flowlogs-pipeline/main_test.go @@ -46,9 +46,7 @@ func TestTheMain(t *testing.T) { func TestPipelineConfigSetup(t *testing.T) { // Kube init mock - kdata := new(kubernetes.InformersMock) - kdata.On("InitFromConfig", "").Return(nil) - kubernetes.MockInformers(kdata) + kubernetes.MockInformers() js := `{ "PipeLine": "[{\"name\":\"grpc\"},{\"follows\":\"grpc\",\"name\":\"enrich\"},{\"follows\":\"enrich\",\"name\":\"loki\"},{\"follows\":\"enrich\",\"name\":\"prometheus\"}]", diff --git a/pkg/pipeline/transform/kubernetes/enrich.go b/pkg/pipeline/transform/kubernetes/enrich.go index de871b3bc..65e2dd1f9 100644 --- a/pkg/pipeline/transform/kubernetes/enrich.go +++ b/pkg/pipeline/transform/kubernetes/enrich.go @@ -14,11 +14,6 @@ func InitFromConfig(kubeConfigPath string) error { return informers.initFromConfig(kubeConfigPath) } -// For testing -func MockInformers(m *InformersMock) { - informers = m -} - func Enrich(outputEntry config.GenericMap, rule api.NetworkTransformRule) { kubeInfo, err := informers.getInfo(fmt.Sprintf("%s", outputEntry[rule.Input])) if err != nil { diff --git a/pkg/pipeline/transform/kubernetes/informers-mock.go b/pkg/pipeline/transform/kubernetes/informers-mock.go index a6b758f23..e6573c479 100644 --- a/pkg/pipeline/transform/kubernetes/informers-mock.go +++ b/pkg/pipeline/transform/kubernetes/informers-mock.go @@ -11,7 +11,13 @@ type InformersMock struct { informersInterface } -func (o *InformersMock) InitFromConfig(kubeConfigPath string) error { +func MockInformers() { + inf := new(InformersMock) + inf.On("initFromConfig", mock.Anything).Return(nil) + informers = inf +} + +func (o *InformersMock) initFromConfig(kubeConfigPath string) error { args := o.Called(kubeConfigPath) return args.Error(0) }