Add module identity and outcome primitives

This commit is contained in:
2026-10-07 13:12:37 +00:00
parent e5c361d2cb
commit f61d1ae7dd
13 changed files with 538 additions and 8 deletions

40
outcome_test.go Normal file
View File

@@ -0,0 +1,40 @@
package commandkit
import (
"errors"
"testing"
)
func TestOutcomeConstructors(t *testing.T) {
cause := errors.New("operation failed")
tests := []struct {
name string
got Outcome
kind OutcomeKind
status int
domain string
wantCause error
}{
{name: "success", got: Success(), kind: OutcomeSuccess, status: 0},
{name: "usage", got: Usage(cause), kind: OutcomeUsage, status: 2, wantCause: cause},
{name: "failure", got: Failure(cause), kind: OutcomeOperational, status: 1, wantCause: cause},
{name: "domain", got: Domain("record", 7, cause), kind: OutcomeDomain, status: 7, domain: "record", wantCause: cause},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
if test.got.Kind != test.kind {
t.Fatalf("Kind = %q, want %q", test.got.Kind, test.kind)
}
if test.got.Status != test.status {
t.Fatalf("Status = %d, want %d", test.got.Status, test.status)
}
if test.got.Cause != test.wantCause {
t.Fatalf("Cause = %v, want original cause %v", test.got.Cause, test.wantCause)
}
if test.got.Domain != test.domain {
t.Fatalf("Domain = %q, want %q", test.got.Domain, test.domain)
}
})
}
}