Build validation filter sets once per invocation
This commit is contained in:
@@ -60,6 +60,44 @@ func TestDetailedValidationFiltersAndRetainsFailureEvidence(t *testing.T) {
|
||||
if strings.Contains(diag.String(), "native warnings") || !strings.Contains(diag.String(), "application warning") || !strings.Contains(diag.String(), "terminal failure") {
|
||||
t.Fatalf("diagnostics=%q", diag.String())
|
||||
}
|
||||
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
flags []string
|
||||
first, second []string
|
||||
}{
|
||||
{"any within filters", []string{"--severity=warning", "--severity=error", "--code=chosen", "--code=other", "--code=failed"}, []string{"selected warning", "other warning"}, []string{"failed finding"}},
|
||||
{"duplicates and unknown", []string{"--severity=warning", "--severity=warning", "--code=chosen", "--code=chosen", "--code=future-code"}, []string{"selected warning"}, nil},
|
||||
{"both filters", []string{"--severity=error", "--code=chosen", "--code=failed"}, nil, []string{"failed finding"}},
|
||||
{"no matching code", []string{"--code=future-code"}, nil, nil},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
var out bytes.Buffer
|
||||
args := append([]string{"config", "validate", "--scope=all", "--details", "--format=json"}, tc.flags...)
|
||||
got := app.Execute(context.Background(), args, commandkit.Streams{Out: &out, Err: io.Discard})
|
||||
var report validationReport
|
||||
if err := json.Unmarshal(out.Bytes(), &report); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !errors.Is(got.Cause, cause) || len(report.Scopes) != 2 {
|
||||
t.Fatalf("outcome=%#v report=%#v", got, report)
|
||||
}
|
||||
for index, want := range [][]string{tc.first, tc.second} {
|
||||
details := report.Scopes[index].Details
|
||||
if len(details.Findings) != len(want) {
|
||||
t.Fatalf("findings=%#v want=%v", details.Findings, want)
|
||||
}
|
||||
for i, message := range want {
|
||||
if details.Findings[i].Message != message {
|
||||
t.Fatalf("finding order=%#v want=%v", details.Findings, want)
|
||||
}
|
||||
}
|
||||
if len(want) == 0 && details.State != "filtered" {
|
||||
t.Fatalf("state=%q", details.State)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
before := len(calls)
|
||||
for _, args := range [][]string{{"--severity=warning"}, {"--code=x"}, {"--details", "--severity=unknown"}} {
|
||||
result = app.Execute(context.Background(), append([]string{"config", "validate"}, args...), commandkit.Streams{Out: io.Discard, Err: io.Discard})
|
||||
|
||||
Reference in New Issue
Block a user