-
Notifications
You must be signed in to change notification settings - Fork 1
/
response_test.go
73 lines (69 loc) · 1.68 KB
/
response_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
package apns
import (
"io"
"net/http"
"strings"
"testing"
)
func TestParseResponse200(t *testing.T) {
r := &http.Response{
StatusCode: 200,
Header: http.Header{
"Apns-Id": []string{"EC1BF194-B3B2-424A-89A9-5A918A6E6B5D"},
},
Body: io.NopCloser(strings.NewReader("")),
}
res, err := ParseResponse(r)
if err != nil {
t.Errorf("err not nil: %q", err)
}
if res != nil {
if res.ID != "EC1BF194-B3B2-424A-89A9-5A918A6E6B5D" {
t.Errorf("res.ID: %v want: EC1BF194-B3B2-424A-89A9-5A918A6E6B5D", res.ID)
}
if res.Status != Status200 {
t.Errorf("res.Status: %v want: 200", res.Status)
}
} else {
t.Error("res is nil")
}
}
func TestParseResponseNot200(t *testing.T) {
r := &http.Response{
StatusCode: 410,
Header: http.Header{
"Apns-Id": []string{"EC1BF194-B3B2-424A-89A9-5A918A6E6B5D"},
},
Body: io.NopCloser(strings.NewReader(`{"reason":"Unregistered","timestamp":1629000000000}`)),
}
res, err := ParseResponse(r)
if err != nil {
t.Errorf("err not nil: %q", err)
}
if res != nil {
if res.ID != "EC1BF194-B3B2-424A-89A9-5A918A6E6B5D" {
t.Errorf("res.ID: %v want: EC1BF194-B3B2-424A-89A9-5A918A6E6B5D", res.ID)
}
if res.Status != 410 {
t.Errorf("res.Status: %v want: 410", res.Status)
}
if res.Timestamp != 1629000000000 {
t.Errorf("res.Timestamp: %v want: 1629000000000", res.Timestamp)
}
} else {
t.Error("res is nil")
}
}
func TestParseResponseErrors(t *testing.T) {
r := &http.Response{
StatusCode: 410,
Header: http.Header{
"Apns-Id": []string{"EC1BF194-B3B2-424A-89A9-5A918A6E6B5D"},
},
Body: io.NopCloser(strings.NewReader("Hello")),
}
_, err := ParseResponse(r)
if err == nil {
t.Error("err must be not nil")
}
}