-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwspingpong_test.go
46 lines (37 loc) · 1.04 KB
/
wspingpong_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
package wspingpong
import (
"net/http"
"net/http/httptest"
"strings"
"testing"
)
func TestNoFavicon(t *testing.T) {
srv := httptest.NewServer(WSPingPongServer{})
// TODO: currently the server just returns for this route. What happens then exactly?
req, err := http.NewRequest("GET", srv.URL+"/favicon.ico", strings.NewReader(""))
if err != nil {
t.Errorf("Request error: %v\n", err)
}
res, err := srv.Client().Do(req)
if err != nil {
t.Errorf("Client error: %v\n", err)
}
t.Errorf("Response: %v\n", res)
}
func TestAllowOnlyGet(t *testing.T) {
methods := []string{"POST", "PUT", "PATCH", "HACK"}
srv := httptest.NewServer(WSPingPongServer{LogLevel: LogLevelBasicWithHeaders})
for _, m := range methods {
req, err := http.NewRequest(m, srv.URL, strings.NewReader(""))
if err != nil {
t.Errorf("%v\n", err)
}
res, err := srv.Client().Do(req)
if err != nil {
t.Errorf("%v\n", err)
}
if res.StatusCode != http.StatusMethodNotAllowed {
t.Errorf("Status should be MethodNotAllowed but is %d.\n", res.StatusCode)
}
}
}