MCPcopy
hub / github.com/larksuite/cli / TestMarkRawUnwrapsToInnerTypedError

Function TestMarkRawUnwrapsToInnerTypedError

errs/raw_test.go:80–96  ·  view source on GitHub ↗

TestMarkRawUnwrapsToInnerTypedError pins the envelope-serialization contract: UnwrapTypedError must return the inner concrete typed error, not the rawPassthrough wrapper. The wrapper has no exported fields, so if it were returned the JSON envelope would marshal to an empty "{}" error.

(t *testing.T)

Source from the content-addressed store, hash-verified

78// not the rawPassthrough wrapper. The wrapper has no exported fields, so if it
79// were returned the JSON envelope would marshal to an empty "{}" error.
80func TestMarkRawUnwrapsToInnerTypedError(t *testing.T) {
81 base := errs.NewValidationError(errs.SubtypeInvalidArgument, "bad flag")
82 typed, ok := errs.UnwrapTypedError(errs.MarkRaw(base))
83 if !ok {
84 t.Fatal("UnwrapTypedError(MarkRaw(typed)) must find a typed error")
85 }
86 out, err := json.Marshal(typed)
87 if err != nil {
88 t.Fatal(err)
89 }
90 if string(out) == "{}" {
91 t.Fatalf("UnwrapTypedError returned the opaque rawPassthrough wrapper; envelope would be empty: %s", out)
92 }
93 if got := errs.CategoryOf(typed); got != errs.CategoryValidation {
94 t.Fatalf("unwrapped category = %q, want validation", got)
95 }
96}

Callers

nothing calls this directly

Calls 4

NewValidationErrorFunction · 0.92
UnwrapTypedErrorFunction · 0.92
MarkRawFunction · 0.92
CategoryOfFunction · 0.92

Tested by

no test coverage detected