forked from saintpete/twilio-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
phonenumbers_test.go
49 lines (45 loc) · 1.14 KB
/
phonenumbers_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package twilio
import (
"context"
"net/url"
"testing"
"time"
"github.com/kevinburke/rest"
)
func TestGetNumberPage(t *testing.T) {
if testing.Short() {
t.Skip("skipping HTTP request in short mode")
}
t.Parallel()
data := url.Values{"PageSize": []string{"1000"}}
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
numbers, err := envClient.IncomingNumbers.GetPage(ctx, data)
if err != nil {
t.Fatal(err)
}
if len(numbers.IncomingPhoneNumbers) == 0 {
t.Error("expected to get a list of phone numbers, got back 0")
}
}
func TestBuyNumber(t *testing.T) {
if testing.Short() {
t.Skip("skipping HTTP request in short mode")
}
t.Parallel()
_, err := envClient.IncomingNumbers.BuyNumber("+1foobar")
if err == nil {
t.Fatal("expected to get an error, got nil")
}
rerr, ok := err.(*rest.Error)
if !ok {
t.Fatal("couldn't cast err to a rest.Error")
}
expected := "+1foobar is not a valid number"
if rerr.Title != expected {
t.Errorf("expected Title to be %s, got %s", expected, rerr.Title)
}
if rerr.StatusCode != 400 {
t.Errorf("expected StatusCode to be 400, got %d", rerr.StatusCode)
}
}