forked from goadesign/goa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimeout_test.go
35 lines (30 loc) · 872 Bytes
/
timeout_test.go
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
package middleware_test
import (
"net/http"
"strings"
"time"
"golang.org/x/net/context"
"github.com/goadesign/goa"
"github.com/goadesign/goa/middleware"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Timeout", func() {
It("sets a deadline", func() {
service := newService(nil)
req, err := http.NewRequest("POST", "/goo", strings.NewReader(`{"payload":42}`))
Ω(err).ShouldNot(HaveOccurred())
rw := new(testResponseWriter)
ctx := newContext(service, rw, req, nil)
var newCtx context.Context
h := func(ctx context.Context, rw http.ResponseWriter, req *http.Request) error {
newCtx = ctx
return goa.ContextResponse(ctx).Send(ctx, 200, "ok")
}
t := middleware.Timeout(time.Duration(1))(h)
err = t(ctx, rw, req)
Ω(err).ShouldNot(HaveOccurred())
_, ok := newCtx.Deadline()
Ω(ok).Should(BeTrue())
})
})