forked from sideshow/apns2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_go16_test.go
47 lines (40 loc) · 1.29 KB
/
client_go16_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
// +build go1.6,!go1.7
package apns2_test
import (
"net/http"
"net/http/httptest"
"testing"
"time"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context"
)
func TestClientPushWithContextWithTimeout(t *testing.T) {
const timeout = time.Nanosecond
n := mockNotification()
var apnsID = "02ABC856-EF8D-4E49-8F15-7B8A61D978D6"
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.Header().Set("apns-id", apnsID)
w.WriteHeader(http.StatusOK)
}))
defer server.Close()
ctx, cancel := context.WithTimeout(context.Background(), timeout)
time.Sleep(timeout)
res, err := mockClient(server.URL).PushWithContext(ctx, n)
assert.Error(t, err)
assert.Nil(t, res)
cancel()
}
func TestClientPushWithContext(t *testing.T) {
n := mockNotification()
var apnsID = "02ABC856-EF8D-4E49-8F15-7B8A61D978D6"
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.Header().Set("apns-id", apnsID)
w.WriteHeader(http.StatusOK)
}))
defer server.Close()
res, err := mockClient(server.URL).PushWithContext(context.Background(), n)
assert.Nil(t, err)
assert.Equal(t, res.ApnsID, apnsID)
}