37 lines
2.1 KiB
Go
37 lines
2.1 KiB
Go
|
|
package processreport
|
||
|
|
|
||
|
|
import (
|
||
|
|
"strings"
|
||
|
|
"testing"
|
||
|
|
"time"
|
||
|
|
|
||
|
|
"gitea.maximumdirect.net/eric/audita/v3/internal/core/reporting"
|
||
|
|
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/contracts"
|
||
|
|
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/outcomes"
|
||
|
|
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/runner"
|
||
|
|
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/validators"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestUnavailableCandidateAndFailureKeepIdentity(t *testing.T) {
|
||
|
|
id := "review/name"
|
||
|
|
index := 1
|
||
|
|
output := &runner.RunOutput{InventoryAvailable: true, ModuleResults: []runner.ModuleResult{
|
||
|
|
{StageIndex: 1, StageID: &id, ModuleKey: "grammar", ModuleInstance: "grammar_2", ValidatorRejected: []runner.ValidatorRejectedChange{{ProposalIndex: 3, Disposition: validators.DispositionUnavailable, ReasonCode: "provider_failed"}}},
|
||
|
|
}, WorkUnits: []runner.WorkUnitOutcome{{ModuleIndex: 1, StageIndex: 1, StageID: &id, ModuleKey: "grammar", ModuleInstance: "grammar_2", State: outcomes.WorkCompleted, Operations: []outcomes.Operation{{Reference: outcomes.Reference{StageIndex: &index, StageID: &id, Kind: outcomes.OperationValidation}, FailureReason: outcomes.ReasonProviderFailed}}}}}
|
||
|
|
ledger := BuildCorrectionLedger(CorrectionLedgerInput{RunOutput: output})
|
||
|
|
if len(ledger) != 1 || ledger[0].Disposition != "unavailable" || ledger[0].StageIndex != 1 || ledger[0].StageID == nil || *ledger[0].StageID != id {
|
||
|
|
t.Fatalf("ledger=%+v", ledger)
|
||
|
|
}
|
||
|
|
snapshot := Build(BuildInput{StartedAt: time.Now(), Status: reporting.StatusCompleted, ModuleSpecs: []contracts.ModuleRunSpec{{Index: 0, ModuleKey: "glossary"}, {Index: 1, ID: &id, ModuleKey: "grammar"}}, RunOutput: output})
|
||
|
|
if len(snapshot.Errors) != 1 || snapshot.Errors[0].StageID == nil || *snapshot.Errors[0].StageID != id || snapshot.Errors[0].StageIndex == nil || *snapshot.Errors[0].StageIndex != 1 {
|
||
|
|
t.Fatalf("errors=%+v", snapshot.Errors)
|
||
|
|
}
|
||
|
|
raw, err := reporting.YAML(snapshot.ErrorsDocument())
|
||
|
|
if err != nil {
|
||
|
|
t.Fatal(err)
|
||
|
|
}
|
||
|
|
if !strings.Contains(string(raw), "stage_id: review/name") || !strings.Contains(string(raw), "stage_index: 1") {
|
||
|
|
t.Fatalf("error report: %s", raw)
|
||
|
|
}
|
||
|
|
}
|