forked from saintpete/twilio-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
media_test.go
56 lines (52 loc) · 1.47 KB
/
media_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
50
51
52
53
54
55
56
package twilio
import (
"errors"
"os"
"strings"
"testing"
"time"
"golang.org/x/net/context"
)
func TestGetURL(t *testing.T) {
if testing.Short() {
t.Skip("skipping HTTP request in short mode")
}
t.Parallel()
sid := os.Getenv("TWILIO_ACCOUNT_SID")
c := NewClient(sid, os.Getenv("TWILIO_AUTH_TOKEN"), nil)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
// These are tied to Kevin's account, sorry I don't have a better way to do
// this.
u, err := c.Media.GetURL(ctx, "MM89a8c4a6891c53054e9cd604922bfb61", "ME4f366233682e811f63f73220bc07fc34")
if err != nil {
t.Fatal(err)
}
if u == nil {
t.Fatal(errors.New("got nil url"))
}
str := u.String()
if !strings.HasPrefix(str, "https://s3-external-1.amazonaws.com/media.twiliocdn.com/"+sid) {
t.Errorf("wrong url: %s", str)
}
}
func TestGetImage(t *testing.T) {
if testing.Short() {
t.Skip("skipping HTTP request in short mode")
}
t.Parallel()
sid := os.Getenv("TWILIO_ACCOUNT_SID")
c := NewClient(sid, os.Getenv("TWILIO_AUTH_TOKEN"), nil)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
// These are tied to Kevin's account, sorry I don't have a better way to do
// this.
i, err := c.Media.GetImage(ctx, "MM89a8c4a6891c53054e9cd604922bfb61", "ME4f366233682e811f63f73220bc07fc34")
if err != nil {
t.Fatal(err)
}
bounds := i.Bounds()
if bounds.Max.X < 50 || bounds.Max.Y < 50 {
t.Errorf("Invalid picture bounds: %v", bounds)
}
}