-
Notifications
You must be signed in to change notification settings - Fork 11
/
globaloptionshandler_test.go
53 lines (44 loc) · 1.12 KB
/
globaloptionshandler_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
43
44
45
46
47
48
49
50
51
52
53
package j8a
import (
"net/http"
"net/http/httptest"
"testing"
)
// this testHandler binds the mock HTTP server to proxyHandler.
type GlobalOptionsHandler struct{}
func (t GlobalOptionsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
globalOptionsHandler(w, r)
}
func TestGlobalOptionsHandlerReturnsWithAcceptHeaders(t *testing.T) {
eq := func(a, b []string) bool {
if len(a) != len(b) {
return false
}
for i, v := range a {
if v != b[i] {
return false
}
}
return true
}
Runner = mockRuntime()
server := httptest.NewServer(&GlobalOptionsHandler{})
defer server.Close()
c := &http.Client{}
req, _ := http.NewRequest("OPTIONS", server.URL, nil)
req.Header.Set(acceptEncoding, "identity")
resp, err := c.Do(req)
if err != nil {
t.Fatal(err)
}
got := resp.Header["Allow"]
want := httpLegalMethods
if !eq(want, got) {
t.Errorf("expected server global allowed HTTP methods, want %v, got %v", want, got)
}
want2 := "identity"
got2 := resp.Header[contentEncoding][0]
if got2 != want2 {
t.Errorf("response does have correct Content-Encoding header, want %v, got %v", want2, got2)
}
}