forked from goadesign/goa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
context_test.go
42 lines (35 loc) · 1014 Bytes
/
context_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
36
37
38
39
40
41
42
package goa_test
import (
"net/http"
"net/url"
"context"
"github.com/goadesign/goa"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("ResponseData", func() {
var data *goa.ResponseData
var rw http.ResponseWriter
var req *http.Request
var params url.Values
BeforeEach(func() {
var err error
req, err = http.NewRequest("GET", "google.com", nil)
Ω(err).ShouldNot(HaveOccurred())
rw = &TestResponseWriter{Status: 42}
params = url.Values{"query": []string{"value"}}
ctx := goa.NewContext(context.Background(), rw, req, params)
data = goa.ContextResponse(ctx)
})
Context("SwitchWriter", func() {
var rwo http.ResponseWriter
It("sets the response writer and returns the previous one", func() {
Ω(rwo).Should(BeNil())
rwo = data.SwitchWriter(&TestResponseWriter{Status: 43})
Ω(rwo).ShouldNot(BeNil())
Ω(rwo).Should(BeAssignableToTypeOf(&TestResponseWriter{}))
trw := rwo.(*TestResponseWriter)
Ω(trw.Status).Should(Equal(42))
})
})
})