-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathclient_test.go
79 lines (71 loc) · 1.74 KB
/
client_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
package jpush
import (
"context"
"strconv"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
const (
appKey = "b1ccd0dd04ec36b66c75e99f"
masterSecret = "ed431429270144d3ed53555b"
)
func TestPush(t *testing.T) {
Convey("test client push", t, func() {
cli := NewClient(2,
SetAppKey(appKey),
SetMasterSecret(masterSecret),
SetCIDCount(2),
)
pushID, err := cli.GetPushID(context.Background())
So(err, ShouldBeNil)
So(pushID, ShouldNotBeEmpty)
payload := &Payload{
Platform: NewPlatform().All(),
Audience: NewAudience().All(),
Notification: &Notification{
Alert: "推送通知测试",
},
Options: &Options{
SendNO: 1,
},
CID: pushID,
}
err = cli.Push(context.Background(), payload, func(ctx context.Context, result *PushResult, err error) {
Convey("async callback", t, func() {
So(err, ShouldBeNil)
So(result, ShouldNotBeNil)
So(result.SendNO, ShouldEqual, strconv.Itoa(payload.Options.SendNO))
})
})
So(err, ShouldBeNil)
cli.Terminate()
})
}
func TestPushValidate(t *testing.T) {
Convey("test client push validate", t, func() {
cli := NewClient(2,
SetAppKey(appKey),
SetMasterSecret(masterSecret),
SetCIDCount(2),
)
payload := &Payload{
Platform: NewPlatform().All(),
Audience: NewAudience().All(),
Notification: &Notification{
Alert: "推送通知测试2",
},
Options: &Options{
SendNO: 2,
},
}
err := cli.PushValidate(context.Background(), payload, func(ctx context.Context, result *PushResult, err error) {
Convey("async callback", t, func() {
So(err, ShouldBeNil)
So(result, ShouldNotBeNil)
So(result.SendNO, ShouldEqual, strconv.Itoa(payload.Options.SendNO))
})
})
So(err, ShouldBeNil)
cli.Terminate()
})
}