-
Notifications
You must be signed in to change notification settings - Fork 4
/
status_test.go
54 lines (49 loc) · 1.85 KB
/
status_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
package requests
import "testing"
func TestStatusString(t *testing.T) {
tests := []struct {
Status
want string
}{
{Status{Code: 200, Reason: "OK"}, "200 OK"},
{Status{Code: 418, Reason: "I'm a teapot"}, "418 I'm a teapot"},
}
for _, tt := range tests {
got := tt.Status.String()
if got != tt.want {
t.Errorf("got: %q, want: %q", got, tt.want)
}
}
}
func TestStatusMethods(t *testing.T) {
tests := []struct {
Status
informational, success, redirect, error, clienterr, servererr bool
}{
{Status{Code: INFO_CONTINUE}, true, false, false, false, false, false},
{Status{Code: SUCCESS_OK}, false, true, false, false, false, false},
{Status{Code: REDIRECTION_MULTIPLE_CHOICES}, false, false, true, false, false, false},
{Status{Code: CLIENT_ERROR_BAD_REQUEST}, false, false, false, true, true, false},
{Status{Code: SERVER_ERROR_INTERNAL}, false, false, false, true, false, true},
}
for _, tt := range tests {
if info := tt.Status.IsInformational(); info != tt.informational {
t.Errorf("Status(%q).Informational: expected %v, got %v", tt.Status, tt.informational, info)
}
if success := tt.Status.IsSuccess(); success != tt.success {
t.Errorf("Status(%q).Success: expected %v, got %v", tt.Status, tt.success, success)
}
if redirect := tt.Status.IsRedirect(); redirect != tt.redirect {
t.Errorf("Status(%q).Redirect: expected %v, got %v", tt.Status, tt.redirect, redirect)
}
if error := tt.Status.IsError(); error != tt.error {
t.Errorf("Status(%q).IsError: expected %v, got %v", tt.Status, tt.error, error)
}
if error := tt.Status.IsClientError(); error != tt.clienterr {
t.Errorf("Status(%q).IsError: expected %v, got %v", tt.Status, tt.clienterr, error)
}
if error := tt.Status.IsServerError(); error != tt.servererr {
t.Errorf("Status(%q).IsError: expected %v, got %v", tt.Status, tt.servererr, error)
}
}
}