diff --git a/.travis.yml b/.travis.yml index 3a0abd094..4ef75a443 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/Makefile b/Makefile index 32e4dc7f5..bdda6c490 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,10 @@ install: githooks go build -v ./... test: - go test -v ./... + go test ./... + +cluster-test: + go test --tags=cluster goimports: go get golang.org/x/tools/cmd/goimports diff --git a/cluster_test.go b/cluster_test.go new file mode 100644 index 000000000..f417ecc78 --- /dev/null +++ b/cluster_test.go @@ -0,0 +1,57 @@ +// +build cluster + +package twilio + +import ( + "os" + "testing" + + "github.com/stretchr/testify/assert" + openapi "github.com/twilio/twilio-go/rest/api/v2010" +) + +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") + + testClient = 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 := 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, 0) + 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 := &openapi.ListIncomingPhoneNumberParams{} + params.SetPhoneNumber(from) + + resp, err := testClient.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) +}