Flatten Notarius readiness failure aggregation
This commit is contained in:
@@ -3,6 +3,7 @@ package preflight
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -65,6 +66,43 @@ func TestDownstreamChecksPropagateFailureAndCancellation(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNotariusPreservesMultipleFailuresAndAdapterCause(t *testing.T) {
|
||||
cause := errors.New("provider unavailable")
|
||||
adapterErr := &os.PathError{Op: "probe", Path: "synthetic", Err: cause}
|
||||
fake := ¬arius.FakeRunner{PreflightErr: adapterErr, PreflightResult: ¬arius.ReadinessResult{
|
||||
Checks: []notarius.ReadinessCheck{
|
||||
{ID: "provider", Result: "failed", Message: "provider check failed"},
|
||||
{ID: "output", Result: "failed", Message: "output check failed"},
|
||||
{ID: "cache", Result: "warning", Message: "cache unavailable"},
|
||||
},
|
||||
}}
|
||||
result, err := CheckNotarius(context.Background(), fake, notarius.ReadinessRequest{})
|
||||
var typed *os.PathError
|
||||
if !errors.Is(err, cause) || !errors.As(err, &typed) || typed != adapterErr {
|
||||
t.Fatalf("adapter cause lost: %v", err)
|
||||
}
|
||||
for _, message := range []string{"provider check failed", "output check failed"} {
|
||||
if !strings.Contains(err.Error(), message) {
|
||||
t.Fatalf("missing failure %q: %v", message, err)
|
||||
}
|
||||
}
|
||||
for _, check := range fake.PreflightResult.Checks {
|
||||
found := false
|
||||
for _, finding := range result.Findings {
|
||||
if finding.Name == check.ID && finding.Message == check.Message {
|
||||
want := SeverityError
|
||||
if check.Result == "warning" {
|
||||
want = SeverityWarning
|
||||
}
|
||||
found = finding.Severity == want
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Fatalf("missing or reclassified check %q: %+v", check.ID, result.Findings)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestAuditaPreservesFailureAndCancellation(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
failure := errors.New("provider failure")
|
||||
|
||||
Reference in New Issue
Block a user