func ExampleNewContext() { handler := func(w http.ResponseWriter, r *http.Request) { ctx, cancelFunc := httpctx.NewContext(context.Background(), w, r) defer cancelFunc() doSomethingWith(ctx, w, r) } http.HandleFunc("/", handler) http.ListenAndServe(":8080", nil) }
func TestNewContext_CancelFunc(t *testing.T) { assert := assert.New(t) fw := newFakeWriter() fr := &http.Request{} ctx := context.Background() ctx, cancelFunc := httpctx.NewContext(ctx, fw, fr) var wg sync.WaitGroup finished := false wg.Add(1) go func(ctx context.Context) { <-ctx.Done() finished = true wg.Done() }(ctx) cancelFunc() wg.Wait() assert.True(finished) }
func TestNewContext(t *testing.T) { httpctx.NewContext(nil, nil, nil) }