Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error transformations loop and use error filters from test packages #666

Merged
merged 2 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions code/go/internal/validator/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 8 additions & 10 deletions code/go/pkg/validator/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package validator

import (
"errors"
"fmt"
"os"
"path"
Expand Down Expand Up @@ -248,23 +249,20 @@ 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)
errPrefix := fmt.Sprintf("file \"%s/%s\" is invalid: ", pkgRootPath, test.invalidPkgFilePath)

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 {
Expand Down
3 changes: 3 additions & 0 deletions test/packages/bad_dangling_object_ids/validation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
errors:
exclude_checks:
- SVR00004 # References in dashboards.
3 changes: 3 additions & 0 deletions test/packages/good_v3/validation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
errors:
exclude_checks:
- "PSR00001"
3 changes: 3 additions & 0 deletions test/packages/kibana_legacy_visualizations/validation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
errors:
exclude_checks:
- SVR00004 # References in dashboards.