Factor the Audita readiness check
This commit is contained in:
@@ -76,7 +76,7 @@ func TestDownstreamChecksPropagateFailureAndCancellation(t *testing.T) {
|
||||
checker := auditaFunc(func(context.Context, audita.PolishRequest) (audita.PreflightResult, error) {
|
||||
return audita.PreflightResult{ExitCode: 2}, failure
|
||||
})
|
||||
result, err := CheckDownstream(context.Background(), nil, checker, Targets{Polish: true}, audita.PolishRequest{})
|
||||
result, err := CheckAudita(context.Background(), checker, audita.PolishRequest{})
|
||||
if !errors.Is(err, failure) || len(result.Findings) != 1 || result.Findings[0].Severity != SeverityError || !strings.Contains(result.Findings[0].Message, "provider refused") {
|
||||
t.Fatalf("failure: %+v %v", result, err)
|
||||
}
|
||||
@@ -87,8 +87,21 @@ func TestDownstreamChecksPropagateFailureAndCancellation(t *testing.T) {
|
||||
called = true
|
||||
return audita.PreflightResult{}, nil
|
||||
})
|
||||
_, err = CheckDownstream(ctx, nil, checker, Targets{Polish: true}, audita.PolishRequest{})
|
||||
_, err = CheckAudita(ctx, checker, audita.PolishRequest{})
|
||||
if !errors.Is(err, context.Canceled) || called {
|
||||
t.Fatalf("cancellation: called=%v err=%v", called, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAuditaPreservesFailureAndCancellation(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
failure := errors.New("provider failure")
|
||||
checker := auditaFunc(func(context.Context, audita.PolishRequest) (audita.PreflightResult, error) {
|
||||
cancel()
|
||||
return audita.PreflightResult{}, failure
|
||||
})
|
||||
result, err := CheckAudita(ctx, checker, audita.PolishRequest{})
|
||||
if !errors.Is(err, failure) || !errors.Is(err, context.Canceled) || len(result.Findings) != 1 || result.Findings[0].Severity != SeverityError {
|
||||
t.Fatalf("result = %+v, error = %v", result, err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user