MCPcopy Index your code
hub / github.com/cockroachdb/errors / TestHTTP

Function TestHTTP

exthttp/ext_http_test.go:27–54  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

25)
26
27func TestHTTP(t *testing.T) {
28 err := fmt.Errorf("hello")
29 err = exthttp.WrapWithHTTPCode(err, 302)
30
31 // Simulate a network transfer.
32 enc := errors.EncodeError(context.Background(), err)
33 otherErr := errors.DecodeError(context.Background(), enc)
34
35 tt := testutils.T{T: t}
36
37 // Error is preserved through the network.
38 tt.CheckDeepEqual(otherErr, err)
39
40 // It's possible to extract the HTTP code.
41 tt.CheckEqual(exthttp.GetHTTPCode(otherErr, 100), 302)
42
43 // If there are multiple codes, the most recent one wins.
44 otherErr = exthttp.WrapWithHTTPCode(otherErr, 404)
45 tt.CheckEqual(exthttp.GetHTTPCode(otherErr, 100), 404)
46
47 // The code is hidden when the error is printed with %v.
48 tt.CheckStringEqual(fmt.Sprintf("%v", err), `hello`)
49 // The code appears when the error is printed verbosely.
50 tt.CheckStringEqual(fmt.Sprintf("%+v", err), `hello
51(1) http code: 302
52Wraps: (2) hello
53Error types: (1) *exthttp.withHTTPCode (2) *errors.errorString`)
54}

Callers

nothing calls this directly

Calls 7

CheckDeepEqualMethod · 0.95
CheckEqualMethod · 0.95
CheckStringEqualMethod · 0.95
WrapWithHTTPCodeFunction · 0.92
EncodeErrorFunction · 0.92
DecodeErrorFunction · 0.92
GetHTTPCodeFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…