-
Notifications
You must be signed in to change notification settings - Fork 0
/
web_test.go
83 lines (58 loc) · 1.59 KB
/
web_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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
import (
"net/http"
"net/http/httptest"
"testing"
)
func TestHTTPProbe(t *testing.T) {
t.Run("Return default status", func(t *testing.T) {
request, _ := http.NewRequest(http.MethodGet, "/", nil)
response := httptest.NewRecorder()
HTTPProbe(response, request)
got := response.Result().StatusCode
want := 200
if got != want {
t.Errorf("got %q, want %q", got, want)
}
})
t.Run("Return status 200", func(t *testing.T) {
request, _ := http.NewRequest(http.MethodGet, "/200", nil)
response := httptest.NewRecorder()
HTTPProbe(response, request)
got := response.Result().StatusCode
want := 200
if got != want {
t.Errorf("got %q, want %q", got, want)
}
})
t.Run("Return status 404", func(t *testing.T) {
request, _ := http.NewRequest(http.MethodGet, "/404", nil)
response := httptest.NewRecorder()
HTTPProbe(response, request)
got := response.Result().StatusCode
want := 404
if got != want {
t.Errorf("got %q, want %q", got, want)
}
})
t.Run("Return status non-status", func(t *testing.T) {
request, _ := http.NewRequest(http.MethodGet, "/asdf", nil)
response := httptest.NewRecorder()
HTTPProbe(response, request)
got := response.Result().StatusCode
want := 400
if got != want {
t.Errorf("got %d, want %d", got, want)
}
})
t.Run("PATCH method", func(t *testing.T) {
request, _ := http.NewRequest(http.MethodPatch, "/asdf", nil)
response := httptest.NewRecorder()
HTTPProbe(response, request)
got := response.Result().StatusCode
want := 400
if got != want {
t.Errorf("got %d, want %d", got, want)
}
})
}