Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add cluster testing #100

Merged
merged 3 commits into from
Jul 19, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
language: go
go:
- '1.15'
- '1.16'
- '1.15'
- '1.16'
install:
- make install
- make install
script:
- make test
- make test
- if [[ "$TRAVIS_BRANCH" == "main" || "$TRAVIS_BRANCH" == "travis" ]] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
make cluster-test;
fi
notifications:
slack:
if: branch = main
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ install: githooks
go build -v ./...

test:
go test -v ./...
go test `go list ./... | grep -v rest`

cluster-test:
go test -v ./rest

goimports:
go get golang.org/x/tools/cmd/goimports
Expand Down
67 changes: 67 additions & 0 deletions rest/cluster_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package rest

import (
"os"
"testing"

"github.com/stretchr/testify/assert"
"github.com/twilio/twilio-go"
openapi "github.com/twilio/twilio-go/rest/api/v2010"
)

var from string
var to string
var client *twilio.RestClient

func TestMain(m *testing.M) {
from = os.Getenv("TWILIO_FROM_NUMBER")
eshanholtz marked this conversation as resolved.
Show resolved Hide resolved
to = os.Getenv("TWILIO_TO_NUMBER")

client = twilio.NewRestClient()
ret := m.Run()
os.Exit(ret)
}

func TestSendingAText(t *testing.T) {
params := &openapi.CreateMessageParams{}
params.SetTo(to)
params.SetFrom(from)
params.SetBody("Hello there")

resp, err := client.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 := client.ApiV2010.ListIncomingPhoneNumber(nil, 0)
assert.Nil(t, err)
assert.NotNil(t, resp)
assert.GreaterOrEqual(t, len(resp), 2)
}

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

resp, err := client.ApiV2010.ListIncomingPhoneNumber(params, 0)
assert.Nil(t, err)
assert.NotNil(t, resp)
assert.Equal(t, 1, len(resp))
assert.Equal(t, from, *resp[0].PhoneNumber)
}

func TestCreateAndDeleteNumber(t *testing.T) {
createParams := &openapi.CreateIncomingPhoneNumberParams{}
createParams.SetAreaCode("415")
resp, err := client.ApiV2010.CreateIncomingPhoneNumber(createParams)
eshanholtz marked this conversation as resolved.
Show resolved Hide resolved
assert.Nil(t, err)
assert.NotNil(t, resp)

sid := *resp.Sid
err = client.ApiV2010.DeleteIncomingPhoneNumber(sid, nil)
assert.Nil(t, err)
}