Skip to content

Commit f103905

Browse files
feat: add cluster testing (#100)
* feat: add cluster testing
1 parent d0bd318 commit f103905

File tree

3 files changed

+68
-5
lines changed

3 files changed

+68
-5
lines changed

.travis.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
language: go
22
go:
3-
- '1.15'
4-
- '1.16'
3+
- '1.15'
4+
- '1.16'
55
install:
6-
- make install
6+
- make install
77
script:
8-
- make test
8+
- make test
9+
- if [[ "$TRAVIS_BRANCH" == "main" || "$TRAVIS_BRANCH" == "travis" ]] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
10+
make cluster-test;
11+
fi
912
notifications:
1013
slack:
1114
if: branch = main

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ install: githooks
77
go build -v ./...
88

99
test:
10-
go test -v ./...
10+
go test ./...
11+
12+
cluster-test:
13+
go test --tags=cluster
1114

1215
goimports:
1316
go get golang.org/x/tools/cmd/goimports

cluster_test.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// +build cluster
2+
3+
package twilio
4+
5+
import (
6+
"os"
7+
"testing"
8+
9+
"github.com/stretchr/testify/assert"
10+
openapi "github.com/twilio/twilio-go/rest/api/v2010"
11+
)
12+
13+
var from string
14+
var to string
15+
var testClient *RestClient
16+
17+
func TestMain(m *testing.M) {
18+
from = os.Getenv("TWILIO_FROM_NUMBER")
19+
to = os.Getenv("TWILIO_TO_NUMBER")
20+
21+
testClient = NewRestClient()
22+
ret := m.Run()
23+
os.Exit(ret)
24+
}
25+
26+
func TestSendingAText(t *testing.T) {
27+
params := &openapi.CreateMessageParams{}
28+
params.SetTo(to)
29+
params.SetFrom(from)
30+
params.SetBody("Hello there")
31+
32+
resp, err := testClient.ApiV2010.CreateMessage(params)
33+
assert.Nil(t, err)
34+
assert.NotNil(t, resp)
35+
assert.Equal(t, "Hello there", *resp.Body)
36+
assert.Equal(t, from, *resp.From)
37+
assert.Equal(t, to, *resp.To)
38+
}
39+
40+
func TestListingNumbers(t *testing.T) {
41+
resp, err := testClient.ApiV2010.ListIncomingPhoneNumber(nil, 0)
42+
assert.Nil(t, err)
43+
assert.NotNil(t, resp)
44+
// from, to numbers plus any other numbers that's configured for the account.
45+
assert.GreaterOrEqual(t, len(resp), 2)
46+
}
47+
48+
func TestListingANumber(t *testing.T) {
49+
params := &openapi.ListIncomingPhoneNumberParams{}
50+
params.SetPhoneNumber(from)
51+
52+
resp, err := testClient.ApiV2010.ListIncomingPhoneNumber(params, 0)
53+
assert.Nil(t, err)
54+
assert.NotNil(t, resp)
55+
assert.Equal(t, 1, len(resp))
56+
assert.Equal(t, from, *resp[0].PhoneNumber)
57+
}

0 commit comments

Comments
 (0)