-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcounter_test.go
41 lines (37 loc) · 975 Bytes
/
counter_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
package main
import (
"net/http"
"net/http/httptest"
"strings"
"testing"
)
func TestCountHandlerOk(t *testing.T) {
expStCode := 200
b := strings.NewReader("{\"code\": 401 }")
req := httptest.NewRequest(http.MethodPut, "/counter", b)
w := httptest.NewRecorder()
CountHandler(w, req)
if w.Code != 200 {
t.Errorf("expected status code %d\n", expStCode)
}
}
func TestCountHandlerMethodNotAllowed(t *testing.T) {
expStCode := 405
b := strings.NewReader("{\"code\": 401 }")
req := httptest.NewRequest(http.MethodPost, "/counter", b)
w := httptest.NewRecorder()
CountHandler(w, req)
if w.Code != 200 {
t.Errorf("expected status code %d\n", expStCode)
}
}
func TestCountHandlerBadRequest(t *testing.T) {
expStCode := 400
b := strings.NewReader("{\"code\": abc }")
req := httptest.NewRequest(http.MethodPut, "/counter", b)
w := httptest.NewRecorder()
CountHandler(w, req)
if w.Code != expStCode {
t.Errorf("expected status code %d\n", expStCode)
}
}