forked from suzuken/wiki
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhandler_test.go
45 lines (41 loc) · 1.09 KB
/
handler_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
package wiki_test
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/suzuken/wiki"
)
func TestGETHandler(t *testing.T) {
h := func(w http.ResponseWriter, r *http.Request) error {
return nil
}
ts := httptest.NewServer(wiki.GET(h))
if _, err := http.Get(ts.URL); err != nil {
t.Fatalf("GET failed: %s", err)
}
resp, err := http.Post(ts.URL, "application/json", nil)
if err != nil {
t.Fatalf("POST failed: %s", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusMethodNotAllowed {
t.Errorf("want %d, got %d", http.StatusMethodNotAllowed, resp.StatusCode)
}
}
func TestPOSTHandler(t *testing.T) {
h := func(w http.ResponseWriter, r *http.Request) error {
return nil
}
ts := httptest.NewServer(wiki.POST(h))
if _, err := http.Post(ts.URL, "application/json", nil); err != nil {
t.Fatalf("POST failed: %s", err)
}
resp, err := http.Get(ts.URL)
if err != nil {
t.Fatalf("GET failed: %s", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusMethodNotAllowed {
t.Errorf("want %d, got %d", http.StatusMethodNotAllowed, resp.StatusCode)
}
}