Skip to content

Commit

Permalink
test: add edge case tests (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
eshanholtz committed Jul 20, 2021
1 parent f2ae0a4 commit ea2f299
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 31 deletions.
66 changes: 63 additions & 3 deletions cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (
"testing"

"github.com/stretchr/testify/assert"
openapi "github.com/twilio/twilio-go/rest/api/v2010"
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
Expand All @@ -24,7 +26,7 @@ func TestMain(m *testing.M) {
}

func TestSendingAText(t *testing.T) {
params := &openapi.CreateMessageParams{}
params := &ApiV2010.CreateMessageParams{}
params.SetTo(to)
params.SetFrom(from)
params.SetBody("Hello there")
Expand All @@ -46,7 +48,7 @@ func TestListingNumbers(t *testing.T) {
}

func TestListingANumber(t *testing.T) {
params := &openapi.ListIncomingPhoneNumberParams{}
params := &ApiV2010.ListIncomingPhoneNumberParams{}
params.SetPhoneNumber(from)

resp, err := testClient.ApiV2010.ListIncomingPhoneNumber(params)
Expand All @@ -55,3 +57,61 @@ func TestListingANumber(t *testing.T) {
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 := []map[string]interface{}{
{
"type": "com.twilio.messaging.message.delivered",
},
{
"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)
}
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ require (
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.7.0
golang.org/x/tools v0.1.5 // indirect
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
)
27 changes: 0 additions & 27 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,6 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007 h1:gG67DSER+11cZvqIMb8S8bt0vZtiN6xWYARwirrOSfE=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.5 h1:ouewzE6p+/VEB31YYnTbEJdi8pFqKp4P4n85vwo3DHA=
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down

0 comments on commit ea2f299

Please sign in to comment.