MCPcopy Create free account
hub / github.com/chain/Core / TestContext

Function TestContext

net/http/httpjson/context_test.go:10–32  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8)
9
10func TestContext(t *testing.T) {
11 wantHead := "bar"
12 wantRespHead := "baz"
13 f := func(ctx context.Context) {
14 if g := Request(ctx).Header.Get("Test-Key"); g != wantHead {
15 t.Errorf("header = %q want %q", g, wantHead)
16 }
17 ResponseWriter(ctx).Header().Set("Test-Resp-Key", wantRespHead)
18 }
19
20 h, err := Handler(f, nil)
21 if err != nil {
22 t.Fatalf("err = %v", err)
23 }
24
25 resp := httptest.NewRecorder()
26 req, _ := http.NewRequest("GET", "/", nil)
27 req.Header.Set("Test-Key", wantHead)
28 h.ServeHTTP(resp, req)
29 if g := resp.Header().Get("Test-Resp-Key"); g != wantRespHead {
30 t.Errorf("header = %q want %q", g, wantRespHead)
31 }
32}

Callers

nothing calls this directly

Calls 7

RequestFunction · 0.85
ResponseWriterFunction · 0.85
HeaderMethod · 0.80
HandlerFunction · 0.70
GetMethod · 0.65
SetMethod · 0.45
ServeHTTPMethod · 0.45

Tested by

no test coverage detected