|
| 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