Normalize zero outcomes and omitted diagnostic delivery state
This commit is contained in:
@@ -437,3 +437,35 @@ func TestHelpEntryFormsPresentReportAndDiagnosticFailures(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestExecuteNormalizesOutcomeDefaultsAndPreservesDomainValues(t *testing.T) {
|
||||
cause := errors.New("domain cause")
|
||||
for _, tc := range []struct {
|
||||
outcome commandkit.Outcome
|
||||
kind commandkit.OutcomeKind
|
||||
status int
|
||||
domain string
|
||||
cause error
|
||||
}{
|
||||
{commandkit.Outcome{}, commandkit.OutcomeSuccess, 0, "", nil},
|
||||
{commandkit.Outcome{Kind: commandkit.OutcomeDomain, Status: 2, Domain: "needs action", Cause: cause}, commandkit.OutcomeDomain, 2, "needs action", cause},
|
||||
{commandkit.Outcome{Kind: commandkit.OutcomeDomain, Status: 0, Domain: "complete"}, commandkit.OutcomeDomain, 0, "complete", nil},
|
||||
} {
|
||||
command, err := commandkit.NewCommand(commandkit.CommandSpec[struct{}]{Name: "run", Run: func(commandkit.Invocation, struct{}) commandkit.Outcome { return tc.outcome }})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
app, err := commandkit.New(commandkit.Identity{Name: "example"}, command)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
result := app.Execute(context.Background(), []string{"run"}, commandkit.Streams{})
|
||||
wantDelivery := commandkit.DeliveryNone
|
||||
if tc.cause != nil {
|
||||
wantDelivery = commandkit.DeliveryComplete
|
||||
}
|
||||
if result.Kind != tc.kind || result.Status != tc.status || result.Domain != tc.domain || result.Cause != tc.cause || result.DiagnosticDelivery != wantDelivery {
|
||||
t.Fatalf("result=%#v expected=%#v", result, tc)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user