getui_test.go
2.5 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package getuiV2
import (
"openapi/pkg/infrastructure/push"
"openapi/pkg/infrastructure/utils"
"sync"
"testing"
)
func TestGetui(t *testing.T) {
var param = make(map[string]interface{})
param["A"] = "A1"
param["B"] = 2
param["transData"] = struct{ Id int }{Id: 10}
notification := &GetuiNotification{}
err := notification.Init(
push.DebugModule(true),
push.AppId("TkpBI4awmg9fBUx3NWKXS6"),
push.AppKey("5AjJeDOSOZ5ojQpXJFjhg9"),
push.AppMasterSecret("9VnM8MaA6n84Y5VnOIaSvA"),
//单推
push.PushType(push.PushToSingle),
push.ClientId("b5fff5f6b0af551da5f381fa47991828"),
//群推
//push.PushType(push.PushToList),
//push.ClientIds([]string{"b5fff5f6b0af551da5f381fa47991828"}),
push.MsgType(push.SystemTransmission), //push.SystemNotification
push.Title("测试 hello"),
push.Content("hello content"),
push.TransmissionContent(utils.JsonAssertString(param["transData"])),
push.Extra(param),
)
if err != nil {
t.Fatal(err)
}
_, err = notification.Send(param)
if err != nil {
t.Fatal(err)
}
}
func TestGetuiPrd(t *testing.T) {
var param = make(map[string]interface{})
param["A"] = "A1"
param["B"] = 2
param["transData"] = struct {
Id int `json:"id"`
}{Id: 1}
notification := &GetuiNotification{}
err := notification.Init(
push.DebugModule(true),
push.AppId("WgrbaaStTk7JElrXOCgUg6"),
push.AppKey("FG5lbqVrHa5rS9NVfxNP7"),
push.AppMasterSecret("FW3jMNLJrRARYKv2iqA5H5"),
//单推
//push.PushType(push.PushToSingle),
//push.ClientId("502f4fd7ba5df15ac6b3d5c561efd9ca"),
//群推
push.PushType(push.PushToList),
push.ClientIds([]string{"502f4fd7ba5df15ac6b3d5c561efd9ca"}),
push.MsgType(push.SystemTransmission),
push.Title("hello"),
push.Content("hello content"),
push.TransmissionContent(utils.JsonAssertString(param["transData"])),
push.Extra(param),
)
if err != nil {
t.Fatal(err)
}
_, err = notification.Send(param)
if err != nil {
t.Fatal(err)
}
}
func TestGetAuthToken(t *testing.T) {
var wg sync.WaitGroup
round := 100
notification := &GetuiNotification{}
var tokenMap = make(map[string]string)
notification.Init(
push.DebugModule(true),
push.AppId("WgrbaaStTk7JElrXOCgUg6"),
push.AppKey("FG5lbqVrHa5rS9NVfxNP7"),
push.AppMasterSecret("FW3jMNLJrRARYKv2iqA5H5"),
)
for i := 0; i < round; i++ {
wg.Add(1)
go func() {
defer wg.Done()
token, _ := notification.GetAuthToken()
tokenMap[token] = token
}()
}
wg.Wait()
if len(tokenMap) > 1 {
t.Fatalf("token want 1 get %v", len(tokenMap))
}
}