From eb2ec3f3597f85cb79ef371722ade52cbc3bc67b Mon Sep 17 00:00:00 2001 From: Jaime Soriano Pastor Date: Tue, 14 Nov 2023 15:25:15 +0100 Subject: [PATCH] Fix error transformations loop and use error filters from test packages (#666) --- code/go/internal/validator/spec.go | 17 +++++++---------- code/go/pkg/validator/validator_test.go | 18 ++++++++---------- .../bad_dangling_object_ids/validation.yml | 3 +++ test/packages/good_v3/validation.yml | 3 +++ .../validation.yml | 3 +++ 5 files changed, 24 insertions(+), 20 deletions(-) create mode 100644 test/packages/bad_dangling_object_ids/validation.yml create mode 100644 test/packages/good_v3/validation.yml create mode 100644 test/packages/kibana_legacy_visualizations/validation.yml diff --git a/code/go/internal/validator/spec.go b/code/go/internal/validator/spec.go index 5929c29ff..de4f7e2ef 100644 --- a/code/go/internal/validator/spec.go +++ b/code/go/internal/validator/spec.go @@ -118,18 +118,15 @@ func processErrors(errs specerrors.ValidationErrors) specerrors.ValidationErrors for _, e := range errs { for _, msg := range msgTransforms { if strings.Contains(e.Error(), msg.original) { - processedErrs = append(processedErrs, - specerrors.NewStructuredError( - errors.New(strings.Replace(e.Error(), msg.original, msg.new, 1)), - specerrors.UnassignedCode), - ) - continue + e = specerrors.NewStructuredError( + errors.New(strings.Replace(e.Error(), msg.original, msg.new, 1)), + specerrors.UnassignedCode) } - if substringInSlice(e.Error(), redundant) { - continue - } - processedErrs = append(processedErrs, e) } + if substringInSlice(e.Error(), redundant) { + continue + } + processedErrs = append(processedErrs, e) } return processedErrs diff --git a/code/go/pkg/validator/validator_test.go b/code/go/pkg/validator/validator_test.go index ceacec600..3cd8e1679 100644 --- a/code/go/pkg/validator/validator_test.go +++ b/code/go/pkg/validator/validator_test.go @@ -5,6 +5,7 @@ package validator import ( + "errors" "fmt" "os" "path" @@ -248,13 +249,6 @@ func TestValidateFile(t *testing.T) { }, } - filter := specerrors.NewFilter(&specerrors.ConfigFilter{ - Errors: specerrors.Processors{ - // TODO: Actually fix the references instead of ignoring the error. - ExcludeChecks: []string{"SVR00004"}, - }, - }) - for pkgName, test := range tests { t.Run(pkgName, func(t *testing.T) { pkgRootPath := filepath.Join("..", "..", "..", "..", "test", "packages", pkgName) @@ -262,9 +256,13 @@ func TestValidateFile(t *testing.T) { errs := ValidateFromPath(pkgRootPath) if verrs, ok := errs.(specerrors.ValidationErrors); ok { - result, err := filter.Run(verrs) - require.NoError(t, err) - errs = result.Processed + filterConfig, err := specerrors.LoadConfigFilter(os.DirFS(pkgRootPath)) + if !errors.Is(err, os.ErrNotExist) { + filter := specerrors.NewFilter(filterConfig) + result, err := filter.Run(verrs) + require.NoError(t, err) + errs = result.Processed + } } if test.expectedErrContains == nil { diff --git a/test/packages/bad_dangling_object_ids/validation.yml b/test/packages/bad_dangling_object_ids/validation.yml new file mode 100644 index 000000000..7756743e8 --- /dev/null +++ b/test/packages/bad_dangling_object_ids/validation.yml @@ -0,0 +1,3 @@ +errors: + exclude_checks: + - SVR00004 # References in dashboards. diff --git a/test/packages/good_v3/validation.yml b/test/packages/good_v3/validation.yml new file mode 100644 index 000000000..06b762198 --- /dev/null +++ b/test/packages/good_v3/validation.yml @@ -0,0 +1,3 @@ +errors: + exclude_checks: + - "PSR00001" diff --git a/test/packages/kibana_legacy_visualizations/validation.yml b/test/packages/kibana_legacy_visualizations/validation.yml new file mode 100644 index 000000000..7756743e8 --- /dev/null +++ b/test/packages/kibana_legacy_visualizations/validation.yml @@ -0,0 +1,3 @@ +errors: + exclude_checks: + - SVR00004 # References in dashboards.