-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcontext_test.go
More file actions
38 lines (31 loc) · 816 Bytes
/
context_test.go
File metadata and controls
38 lines (31 loc) · 816 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright 2016 Canonical Ltd.
// Licensed under the LGPLv3, see LICENCE file for details.
package httprequest_test
import (
"net/http"
"net/http/httptest"
"testing"
qt "github.com/frankban/quicktest"
"github.com/julienschmidt/httprouter"
"gopkg.in/httprequest.v1"
)
type testRequest struct {
httprequest.Route `httprequest:"GET /foo"`
}
func TestContextCancelledWhenDone(t *testing.T) {
c := qt.New(t)
var ch <-chan struct{}
hnd := testServer.Handle(func(p httprequest.Params, req *testRequest) {
ch = p.Context.Done()
})
router := httprouter.New()
router.Handle(hnd.Method, hnd.Path, hnd.Handle)
srv := httptest.NewServer(router)
_, err := http.Get(srv.URL + "/foo")
c.Assert(err, qt.Equals, nil)
select {
case <-ch:
default:
c.Fatal("context not canceled at end of handler.")
}
}