Documentation
¶
Overview ¶
Package golden provides comparison helpers for types.OperationOutcome in tests.
v1 supports inline and embedded golden JSON payloads only. File-backed golden workflows can be added later when a concrete need appears.
CanonicalOutcomeJSON normalizes an OperationOutcome to stable JSON for comparison, including deterministic sorting of issue objects. AssertOutcomeEqual ignores formatting differences between two outcome values. AssertOutcomeMatchesGolden compares against an inline golden JSON string.
DecodeOutcome, AssertOutcomeCode, and AssertOutcomeIssueCount are convenience wrappers for HTTP, client, core, and validate test assertions.
Primary consumers: pkg/http, pkg/client, pkg/core, and pkg/validate tests that need stable OperationOutcome diagnostics without brittle string equality.
Index ¶
- Variables
- func AssertOutcomeCode(t *testing.T, outcome types.OperationOutcome, want string)
- func AssertOutcomeEqual(t *testing.T, got, want types.OperationOutcome)
- func AssertOutcomeIssueCount(t *testing.T, outcome types.OperationOutcome, want int)
- func AssertOutcomeMatchesGolden(t *testing.T, got types.OperationOutcome, goldenJSON string)
- func CanonicalOutcomeJSON(outcome types.OperationOutcome) ([]byte, error)
- func DecodeOutcome(t *testing.T, body []byte) types.OperationOutcome
- func ForbiddenOutcome(diagnostics string) types.OperationOutcome
- func FormatMismatch(got, want []byte) string
- func OutcomeFromError(err error) (types.OperationOutcome, bool)
- func SecurityOutcome(diagnostics string) types.OperationOutcome
Constants ¶
This section is empty.
Variables ¶
var AuthOutcomeCatalog = map[string]types.OperationOutcome{ "forbidden_policy": ForbiddenOutcome("policy denied"), "forbidden_patient_scope": ForbiddenOutcome("principal scoped to patient \"pat-1\" cannot access \"pat-2\""), "forbidden_scope_filter": ForbiddenOutcome("resource outside granted scope filters"), "security_unauthenticated": SecurityOutcome("http: unauthenticated"), "security_token_expired": SecurityOutcome("smart: token expired"), "security_token_not_yet_valid": SecurityOutcome("smart: token not yet valid"), "security_replay": SecurityOutcome("smart: replayed assertion"), }
AuthOutcomeCatalog documents stable OperationOutcome shapes for authorization failures.
Functions ¶
func AssertOutcomeCode ¶
func AssertOutcomeCode(t *testing.T, outcome types.OperationOutcome, want string)
AssertOutcomeCode asserts the first issue code matches want.
func AssertOutcomeEqual ¶
func AssertOutcomeEqual(t *testing.T, got, want types.OperationOutcome)
AssertOutcomeEqual compares two OperationOutcomes ignoring JSON formatting differences.
func AssertOutcomeIssueCount ¶
func AssertOutcomeIssueCount(t *testing.T, outcome types.OperationOutcome, want int)
AssertOutcomeIssueCount asserts the number of issues.
func AssertOutcomeMatchesGolden ¶
func AssertOutcomeMatchesGolden(t *testing.T, got types.OperationOutcome, goldenJSON string)
AssertOutcomeMatchesGolden compares an outcome to an inline golden JSON payload.
func CanonicalOutcomeJSON ¶
func CanonicalOutcomeJSON(outcome types.OperationOutcome) ([]byte, error)
CanonicalOutcomeJSON returns stable JSON for an OperationOutcome (sorted issues).
func DecodeOutcome ¶
func DecodeOutcome(t *testing.T, body []byte) types.OperationOutcome
DecodeOutcome unmarshals OperationOutcome JSON from a response body.
func ForbiddenOutcome ¶
func ForbiddenOutcome(diagnostics string) types.OperationOutcome
ForbiddenOutcome returns a 403-style OperationOutcome with the given diagnostics.
func FormatMismatch ¶
FormatMismatch returns a readable diff string for two outcome JSON blobs.
func OutcomeFromError ¶
func OutcomeFromError(err error) (types.OperationOutcome, bool)
OutcomeFromError renders an OperationOutcome from a Go error value when possible.
func SecurityOutcome ¶
func SecurityOutcome(diagnostics string) types.OperationOutcome
SecurityOutcome returns a 401-style OperationOutcome with the given diagnostics.
Types ¶
This section is empty.