Skip to content

Commit

Permalink
Fix informers mock
Browse files Browse the repository at this point in the history
  • Loading branch information
jotak committed Jan 26, 2024
1 parent 6b29e54 commit 403eac5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
4 changes: 1 addition & 3 deletions cmd/flowlogs-pipeline/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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\"}]",
Expand Down
5 changes: 0 additions & 5 deletions pkg/pipeline/transform/kubernetes/enrich.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 7 additions & 1 deletion pkg/pipeline/transform/kubernetes/informers-mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 403eac5

Please sign in to comment.