forked from twilio/twilio-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcluster_test.go
121 lines (102 loc) · 3.36 KB
/
cluster_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
//go:build cluster
// +build cluster
package twilio
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
ApiV2010 "github.com/twilio/twilio-go/rest/api/v2010"
ChatV2 "github.com/twilio/twilio-go/rest/chat/v2"
EventsV1 "github.com/twilio/twilio-go/rest/events/v1"
)
var from string
var to string
var testClient *RestClient
func TestMain(m *testing.M) {
from = os.Getenv("TWILIO_FROM_NUMBER")
to = os.Getenv("TWILIO_TO_NUMBER")
var apiKey = os.Getenv("TWILIO_API_KEY")
var secret = os.Getenv("TWILIO_API_SECRET")
var accountSid = os.Getenv("TWILIO_ACCOUNT_SID")
testClient = NewRestClientWithParams(ClientParams{apiKey, secret, accountSid, nil})
ret := m.Run()
os.Exit(ret)
}
func TestSendingAText(t *testing.T) {
params := &ApiV2010.CreateMessageParams{}
params.SetTo(to)
params.SetFrom(from)
params.SetBody("Hello there")
resp, err := testClient.ApiV2010.CreateMessage(params)
assert.Nil(t, err)
assert.NotNil(t, resp)
assert.Equal(t, "Hello there", *resp.Body)
assert.Equal(t, from, *resp.From)
assert.Equal(t, to, *resp.To)
}
func TestListingNumbers(t *testing.T) {
resp, err := testClient.ApiV2010.ListIncomingPhoneNumber(nil)
assert.Nil(t, err)
assert.NotNil(t, resp)
// from, to numbers plus any other numbers that's configured for the account.
assert.GreaterOrEqual(t, len(resp), 2)
}
func TestListingANumber(t *testing.T) {
params := &ApiV2010.ListIncomingPhoneNumberParams{}
params.SetPhoneNumber(from)
resp, err := testClient.ApiV2010.ListIncomingPhoneNumber(params)
assert.Nil(t, err)
assert.NotNil(t, resp)
assert.Equal(t, 1, len(resp))
assert.Equal(t, from, *resp[0].PhoneNumber)
}
func TestSpecialCharacters(t *testing.T) {
serviceParams := &ChatV2.CreateServiceParams{}
serviceParams.SetFriendlyName("service|friendly&name")
service, err := testClient.ChatV2.CreateService(serviceParams)
assert.Nil(t, err)
assert.NotNil(t, service)
userParams := &ChatV2.CreateUserParams{}
userParams.SetIdentity("user|identity&string")
user, err := testClient.ChatV2.CreateUser(*service.Sid, userParams)
assert.Nil(t, err)
assert.NotNil(t, user)
err = testClient.ChatV2.DeleteUser(*service.Sid, *user.Identity)
assert.Nil(t, err)
err = testClient.ChatV2.DeleteService(*service.Sid)
assert.Nil(t, err)
}
func TestListParams(t *testing.T) {
sinkConfig := map[string]interface{}{
"destination": "http://example.org/webhook",
"method": "post",
"batch_events": false,
}
sinkParams := &EventsV1.CreateSinkParams{}
sinkParams.SetSinkConfiguration(sinkConfig)
sinkParams.SetDescription("test sink")
sinkParams.SetSinkType("webhook")
sink, err := testClient.EventsV1.CreateSink(sinkParams)
assert.Nil(t, err)
assert.NotNil(t, sink)
types := []interface{}{
map[string]interface{}{
"type": "com.twilio.messaging.message.delivered",
},
map[string]interface{}{
"type": "com.twilio.messaging.message.sent",
},
}
subscriptionsParams := &EventsV1.CreateSubscriptionParams{}
subscriptionsParams.SetSinkSid(*sink.Sid)
subscriptionsParams.SetTypes(types)
subscriptionsParams.SetDescription("test subscription")
subscription, err := testClient.EventsV1.CreateSubscription(subscriptionsParams)
assert.Nil(t, err)
assert.NotNil(t, subscription)
// Clean up the resources we've created
err = testClient.EventsV1.DeleteSubscription(*subscription.Sid)
assert.Nil(t, err)
err = testClient.EventsV1.DeleteSink(*sink.Sid)
assert.Nil(t, err)
}