-
Notifications
You must be signed in to change notification settings - Fork 3
/
client_test.go
113 lines (98 loc) · 2.23 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
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
107
108
109
110
111
112
113
package polysdk_test
import (
"testing"
"time"
"polysdk"
"polysdk/internal/config"
"polysdk/internal/polysign"
)
var c *polysdk.PolyClient
func init() {
_c, err := polysdk.NewPolyClient(&config.PolyConfig{})
if err != nil {
panic(err)
}
c = _c
}
func TestClient(t *testing.T) {
accessToken := ""
body := map[string]interface{}{
"rand": "r8xv2de",
"pingTimestamp": time.Now().Format(polysign.PingTimestampFmt),
"zone": "pek3d",
"active": -1,
"name": "test3",
}
polysdk.PrettyShow(body)
h := polysdk.Header{}
h.Set(polysdk.HeaderContentType, "application/json")
if accessToken != "" {
h.Set("Access-Token", accessToken)
}
uris := []string{
"/api/v1/polyapi/namespace/create/system/app/swhnm/poly",
}
r, err := c.DoRequestAPI(uris[len(uris)-1], polysdk.MethodPost, h, body)
if err != nil {
panic(err)
}
polysdk.PrettyShow(r)
}
func _TestRawRequest(t *testing.T) {
body := polysdk.CustomBody{
polysdk.XPolyBodyHideArgs: map[string]interface{}{
"app": "appX",
},
}
h := polysdk.Header{}
h.Set(polysdk.HeaderContentType, "application/json")
uri := "/system/app/gskgx/raw/inner/form/2q2bh/2q2bh_get.r"
r, err := c.RawAPIRequest(uri, polysdk.MethodPost, h, body)
if err != nil {
panic(err)
}
polysdk.PrettyShow(r)
}
func _TestRawDoc(t *testing.T) {
apiPath := "/system/app/gskgx/raw/customer/a/bb.r"
r, err := c.RawAPIDoc(apiPath, polysdk.DocRaw, true)
if err != nil {
panic(err)
}
polysdk.PrettyShow(r)
}
func _TestPolyRequest(t *testing.T) {
body := polysdk.CustomBody{
"appID": "app1",
"name": "app1Name",
"description": "description",
"scopes": []polysdk.CustomBody{
{
"type": 1,
"id": "someid1",
"name": "somename1",
},
{
"type": 2,
"id": "someid2",
"name": "somename2",
},
},
}
h := polysdk.Header{}
h.Set(polysdk.HeaderContentType, "application/json")
uri := "/system/poly/permissionInit"
r, err := c.PolyAPIRequest(uri, polysdk.MethodPost, h, body)
if err != nil {
panic(err)
}
polysdk.PrettyShow(r)
}
func _TestPolyDoc(t *testing.T) {
apiPath := "/system/poly/permissionInit.p"
r, err := c.PolyAPIDoc(apiPath, polysdk.DocRaw, false)
if err != nil {
panic(err)
}
polysdk.PrettyShow(r)
}