From ba23cc8f1a57561a6fbe740b954c8185a3d54992 Mon Sep 17 00:00:00 2001 From: Raj Date: Mon, 31 Jul 2023 20:36:18 +0530 Subject: [PATCH] fix: Get failing postablePipeline tests to pass --- .../app/logparsingpipeline/postablePipeline.go | 8 ++++++-- .../app/logparsingpipeline/postablePipeline_test.go | 5 +++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/pkg/query-service/app/logparsingpipeline/postablePipeline.go b/pkg/query-service/app/logparsingpipeline/postablePipeline.go index 2810985db4b..2deda650bd0 100644 --- a/pkg/query-service/app/logparsingpipeline/postablePipeline.go +++ b/pkg/query-service/app/logparsingpipeline/postablePipeline.go @@ -1,6 +1,7 @@ package logparsingpipeline import ( + "errors" "fmt" "regexp" "strings" @@ -95,7 +96,9 @@ func (p *PostablePipeline) IsValid() error { } func isValidOperator(op model.PipelineOperator) error { - valueErrStr := "value should have prefix of body, attributes, resource" + if op.ID == "" { + return errors.New("PipelineOperator.ID is required.") + } switch op.Type { case "json_parser": @@ -160,7 +163,8 @@ func isValidOperator(op model.PipelineOperator) error { !isValidOtelValue(op.From) || !isValidOtelValue(op.To) || !isValidOtelValue(op.Field) { - return fmt.Errorf(fmt.Sprintf("%s for operator Id %s", valueErrStr, op.ID)) + valueErrStr := "value should have prefix of body, attributes, resource" + return fmt.Errorf(fmt.Sprintf("%s for operator Id %s", valueErrStr, op.ID)) } return nil } diff --git a/pkg/query-service/app/logparsingpipeline/postablePipeline_test.go b/pkg/query-service/app/logparsingpipeline/postablePipeline_test.go index cb89417f082..fb79997c3d6 100644 --- a/pkg/query-service/app/logparsingpipeline/postablePipeline_test.go +++ b/pkg/query-service/app/logparsingpipeline/postablePipeline_test.go @@ -45,7 +45,7 @@ var correctQueriesTest = []struct { Filter: "attributes.method == \"GET\"", Config: []model.PipelineOperator{}, }, - IsValid: false, + IsValid: true, }, { Name: "Invalid filter", @@ -67,7 +67,7 @@ var correctQueriesTest = []struct { Enabled: true, Filter: "attributes.method == \"GET\"", }, - IsValid: false, + IsValid: true, }, } @@ -75,6 +75,7 @@ func TestIsValidPostablePipeline(t *testing.T) { for _, test := range correctQueriesTest { Convey(test.Name, t, func() { err := test.Pipeline.IsValid() + t.Logf("Testing: %s\t err: %v", test.Name, err) if test.IsValid { So(err, ShouldBeNil) } else {