forked from emicklei/go-restful
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options_filter_test.go
34 lines (30 loc) · 959 Bytes
/
options_filter_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
package restful
import (
"net/http"
"net/http/httptest"
"testing"
)
// go test -v -test.run TestOptionsFilter ...restful
func TestOptionsFilter(t *testing.T) {
tearDown()
ws := new(WebService)
ws.Route(ws.GET("/candy/{kind}").To(dummy))
ws.Route(ws.DELETE("/candy/{kind}").To(dummy))
ws.Route(ws.POST("/candies").To(dummy))
Add(ws)
Filter(OPTIONSFilter())
httpRequest, _ := http.NewRequest("OPTIONS", "http://here.io/candy/gum", nil)
httpWriter := httptest.NewRecorder()
DefaultContainer.dispatch(httpWriter, httpRequest)
actual := httpWriter.Header().Get(HEADER_Allow)
if "GET,DELETE" != actual {
t.Fatal("expected: GET,DELETE but got:" + actual)
}
httpRequest, _ = http.NewRequest("OPTIONS", "http://here.io/candies", nil)
httpWriter = httptest.NewRecorder()
DefaultContainer.dispatch(httpWriter, httpRequest)
actual = httpWriter.Header().Get(HEADER_Allow)
if "POST" != actual {
t.Fatal("expected: POST but got:" + actual)
}
}