This repository has been archived by the owner on Jun 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
account_test.go
78 lines (70 loc) · 1.86 KB
/
account_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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package twiliogo
import (
"os"
"testing"
)
const (
testAccountSidString = "AC5ef8732a3c49700934481addd5ce1659"
testBadAccountSidString = "invalid token"
testTokenString = "token"
)
func TestNewAccount(t *testing.T) {
act, tkn := testAccountSidString, testTokenString
a := NewAccount(act, tkn)
if a.AccountSid != act {
t.Error("AccountSID not set")
} else if a.Token != tkn {
t.Error("Account token not set")
}
}
func TestInvalidNewAccount(t *testing.T) {
handledPanic := false
func() {
defer func() {
if r := recover(); r != nil {
handledPanic = true
}
}()
act, tkn := testBadAccountSidString, testTokenString
NewAccount(act, tkn)
}()
if handledPanic != true {
t.Error("NewAccount did not panic when passed an invalid AccountSid")
}
}
// Helper method for setting environment variables on tests.
func setEnvVariables(sid, token string, t *testing.T) {
err := os.Setenv(twilioAccount, sid)
if err != nil {
t.Errorf("Test failed to set environment variable %s to %s\n", twilioAccount, sid)
}
err = os.Setenv(twilioToken, token)
if err != nil {
t.Errorf("Test failed to set environment variable %s to %s\n", twilioToken, token)
}
}
func TestNewAccountFromEnv(t *testing.T) {
setEnvVariables(testAccountSidString, testTokenString, t)
a := NewAccountFromEnv()
if a.AccountSid != testAccountSidString {
t.Error("NewAccountFromEnv failed to properly set the AccountSid")
}
if a.Token != testTokenString {
t.Error("NewAccountFromEnv failed to properly set the Token")
}
}
func TestInvalidNewAccountFromEnv(t *testing.T) {
handledPanic := false
func() {
defer func() {
if r := recover(); r != nil {
handledPanic = true
}
}()
setEnvVariables(testBadAccountSidString, testTokenString, t)
NewAccountFromEnv()
}()
if handledPanic != true {
t.Error("NewAccount did not panic when passed an invalid AccountSid")
}
}