Skip to content

Commit ea2f299

Browse files
authored
test: add edge case tests (#103)
1 parent f2ae0a4 commit ea2f299

File tree

3 files changed

+63
-31
lines changed

3 files changed

+63
-31
lines changed

cluster_test.go

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import (
77
"testing"
88

99
"github.com/stretchr/testify/assert"
10-
openapi "github.com/twilio/twilio-go/rest/api/v2010"
10+
ApiV2010 "github.com/twilio/twilio-go/rest/api/v2010"
11+
ChatV2 "github.com/twilio/twilio-go/rest/chat/v2"
12+
EventsV1 "github.com/twilio/twilio-go/rest/events/v1"
1113
)
1214

1315
var from string
@@ -24,7 +26,7 @@ func TestMain(m *testing.M) {
2426
}
2527

2628
func TestSendingAText(t *testing.T) {
27-
params := &openapi.CreateMessageParams{}
29+
params := &ApiV2010.CreateMessageParams{}
2830
params.SetTo(to)
2931
params.SetFrom(from)
3032
params.SetBody("Hello there")
@@ -46,7 +48,7 @@ func TestListingNumbers(t *testing.T) {
4648
}
4749

4850
func TestListingANumber(t *testing.T) {
49-
params := &openapi.ListIncomingPhoneNumberParams{}
51+
params := &ApiV2010.ListIncomingPhoneNumberParams{}
5052
params.SetPhoneNumber(from)
5153

5254
resp, err := testClient.ApiV2010.ListIncomingPhoneNumber(params)
@@ -55,3 +57,61 @@ func TestListingANumber(t *testing.T) {
5557
assert.Equal(t, 1, len(resp))
5658
assert.Equal(t, from, *resp[0].PhoneNumber)
5759
}
60+
61+
func TestSpecialCharacters(t *testing.T) {
62+
serviceParams := &ChatV2.CreateServiceParams{}
63+
serviceParams.SetFriendlyName("service|friendly&name")
64+
65+
service, err := testClient.ChatV2.CreateService(serviceParams)
66+
assert.Nil(t, err)
67+
assert.NotNil(t, service)
68+
69+
userParams := &ChatV2.CreateUserParams{}
70+
userParams.SetIdentity("user|identity&string")
71+
72+
user, err := testClient.ChatV2.CreateUser(*service.Sid, userParams)
73+
assert.Nil(t, err)
74+
assert.NotNil(t, user)
75+
76+
err = testClient.ChatV2.DeleteUser(*service.Sid, *user.Identity)
77+
assert.Nil(t, err)
78+
err = testClient.ChatV2.DeleteService(*service.Sid)
79+
assert.Nil(t, err)
80+
}
81+
82+
func TestListParams(t *testing.T) {
83+
sinkConfig := map[string]interface{}{
84+
"destination": "http://example.org/webhook",
85+
"method": "post",
86+
"batch_events": false,
87+
}
88+
sinkParams := &EventsV1.CreateSinkParams{}
89+
sinkParams.SetSinkConfiguration(sinkConfig)
90+
sinkParams.SetDescription("test sink")
91+
sinkParams.SetSinkType("webhook")
92+
sink, err := testClient.EventsV1.CreateSink(sinkParams)
93+
assert.Nil(t, err)
94+
assert.NotNil(t, sink)
95+
96+
types := []map[string]interface{}{
97+
{
98+
"type": "com.twilio.messaging.message.delivered",
99+
},
100+
{
101+
"type": "com.twilio.messaging.message.sent",
102+
},
103+
}
104+
subscriptionsParams := &EventsV1.CreateSubscriptionParams{}
105+
subscriptionsParams.SetSinkSid(*sink.Sid)
106+
subscriptionsParams.SetTypes(types)
107+
subscriptionsParams.SetDescription("test subscription")
108+
subscription, err := testClient.EventsV1.CreateSubscription(subscriptionsParams)
109+
assert.Nil(t, err)
110+
assert.NotNil(t, subscription)
111+
112+
// Clean up the resources we've created
113+
err = testClient.EventsV1.DeleteSubscription(*subscription.Sid)
114+
assert.Nil(t, err)
115+
err = testClient.EventsV1.DeleteSink(*sink.Sid)
116+
assert.Nil(t, err)
117+
}

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,5 @@ require (
88
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
99
github.com/pkg/errors v0.9.1
1010
github.com/stretchr/testify v1.7.0
11-
golang.org/x/tools v0.1.5 // indirect
1211
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
1312
)

go.sum

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,33 +15,6 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
1515
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
1616
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
1717
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
18-
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
19-
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
20-
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
21-
golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
22-
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
23-
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
24-
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
25-
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
26-
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
27-
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
28-
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
29-
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
30-
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
31-
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
32-
golang.org/x/sys v0.0.0-20210510120138-977fb7262007 h1:gG67DSER+11cZvqIMb8S8bt0vZtiN6xWYARwirrOSfE=
33-
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
34-
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
35-
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
36-
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
37-
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
38-
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
39-
golang.org/x/tools v0.1.5 h1:ouewzE6p+/VEB31YYnTbEJdi8pFqKp4P4n85vwo3DHA=
40-
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
41-
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
42-
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
43-
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
44-
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
4518
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
4619
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
4720
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

0 commit comments

Comments
 (0)