forked from carlosdp/twiliogo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ip_integration_test.go
177 lines (152 loc) · 4.36 KB
/
ip_integration_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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package twiliogo
import (
"fmt"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestIntegrationIPMessaging(t *testing.T) {
CheckTestEnv(t)
client := NewIPMessagingClient(API_KEY, API_TOKEN)
service, err := NewIPService(client, "integration_test", "", "", 60*time.Second, nil)
if !assert.Nil(t, err, fmt.Sprintf("Failed to create service: %v", err)) {
return
}
ssid := service.Sid
if !assert.NotEqual(t, "", ssid, "Service SID was empty") {
return
}
defer DeleteIPService(client, ssid)
serviceList, err := ListIPServices(client)
if !assert.Nil(t, err, fmt.Sprintf("Failed to retrieve service list: %v", err)) {
return
}
services, err := serviceList.GetAllServices()
if !assert.Nil(t, err, fmt.Sprintf("Failed to get all services: %v", err)) {
return
}
found := false
for _, s := range services {
if s.FriendlyName == "integration_test" && s.Sid == ssid {
found = true
break
}
}
if !assert.True(t, found, "Could not find service") {
return
}
channel, err := NewIPChannel(client, ssid, "integration-channel", "", false, "")
if !assert.Nil(t, err, fmt.Sprintf("Failed to create channel: %v", err)) {
return
}
csid := channel.Sid
if !assert.NotEqual(t, "", csid, "Channel SID was empty") {
return
}
channelList, err := ListIPChannels(client, ssid)
if !assert.Nil(t, err, fmt.Sprintf("Failed to list channels: %v", err)) {
return
}
channels, err := channelList.GetAllChannels()
if !assert.Nil(t, err, fmt.Sprintf("Failed to get all channels: %v", err)) {
return
}
found = false
for _, c := range channels {
if c.Sid == csid {
found = true
break
}
}
if !assert.True(t, found, "Could not find channel") {
return
}
// disables for now because I don't have keys to test with
/*
credential, err := NewIPCredential(client, "integration_cred", "gcm", false, "", "", "")
if !assert.Nil(t, err, fmt.Sprintf("Failed to create credential: %v", err)) {
return
}
credSid := credential.Sid
if !assert.NotEqual(t, "", credSid, "Credential SID was empty") {
return
}
*/
role, err := NewIPRole(client, ssid, "integration_role", "channel",
[]string{PermissionSendMessage, PermissionEditOwnMessage})
if !assert.Nil(t, err, fmt.Sprintf("Failed to create role: %v", err)) {
return
}
roleSid := role.Sid
if !assert.NotEqual(t, "", roleSid, "Role SID was empty") {
return
}
user, err := NewIPUser(client, ssid, "integration_user", "")
if !assert.Nil(t, err, fmt.Sprintf("Failed to create user: %v", err)) {
return
}
userSid := user.Sid
if !assert.NotEqual(t, "", userSid, "User SID was empty") {
return
}
member, err := AddIPMemberToChannel(client, ssid, csid, "integration_user", roleSid)
if !assert.Nil(t, err, fmt.Sprintf("Failed to add member: %v", err)) {
return
}
memberSid := member.Sid
if !assert.NotEqual(t, "", memberSid, "Member SID was empty") {
return
}
_, err = NewIPUser(client, ssid, "integration_user2", "")
if !assert.Nil(t, err, fmt.Sprintf("Failed to create user: %v", err)) {
return
}
_, err = AddIPMemberToChannel(client, ssid, csid, "integration_user2", roleSid)
if !assert.Nil(t, err, fmt.Sprintf("Failed to add member: %v", err)) {
return
}
memberList, err := ListIPMembers(client, ssid, csid)
if !assert.Nil(t, err, fmt.Sprintf("Failed to add member: %v", err)) {
return
}
members, err := memberList.GetAllMembers()
if !assert.Nil(t, err, fmt.Sprintf("Failed to list members: %v", err)) {
return
}
found = false
for _, m := range members {
if m.Sid == memberSid && m.Identity == member.Identity {
found = true
break
}
}
if !assert.True(t, found, "Could not find member") {
return
}
message, err := SendIPMessageToChannel(client, ssid, csid, "integration_user2", "testing integration")
if !assert.Nil(t, err, fmt.Sprintf("Failed to send message: %v", err)) {
return
}
if !assert.NotEqual(t, "", message.Sid, "Message SID was empty") {
return
}
found = false
messageList, err := ListIPMessages(client, ssid, csid)
if !assert.Nil(t, err, fmt.Sprintf("Failed to list messages: %v", err)) {
return
}
messages, err := messageList.GetAllMessages()
if !assert.Nil(t, err, fmt.Sprintf("Failed to get all messages: %v", err)) {
return
}
found = false
for _, m := range messages {
if m.Sid == message.Sid && m.Body == "testing integration" {
found = true
break
}
}
if !assert.True(t, found, "Could not find message") {
return
}
}