-
Notifications
You must be signed in to change notification settings - Fork 1
/
accounts_test.go
108 lines (90 loc) · 3.01 KB
/
accounts_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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package shippable
import (
"fmt"
"io/ioutil"
"net/http"
"reflect"
"testing"
)
func TestGetAccounts(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/accounts", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
rawResponse, _ := ioutil.ReadFile("./mocks/response_get_accounts.json")
fmt.Fprint(w, string(rawResponse))
})
accounts, _, err := client.Accounts.GetAccounts()
if err != nil {
t.Errorf("Accounts.GetAccounts returned error %v", err)
}
if len(*accounts) != 2 {
t.Errorf("Accounts.GetAccounts accounts returned; expected %d, actual %d", 2, len(*accounts))
}
wantedAccounts := []string{"foo", "bar"}
if !reflect.DeepEqual(*accounts, wantedAccounts) {
t.Errorf("Actual = %+v, Expected = %+v", *accounts, wantedAccounts)
}
}
func TestGetAccount(t *testing.T) {
setup()
defer teardown()
wantedAccountID := "640e74943999391400416qr0"
mux.HandleFunc("/accounts/"+wantedAccountID, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
rawResponse, _ := ioutil.ReadFile("./mocks/response_get_accounts_640e74943999391400416qr0.json")
fmt.Fprint(w, string(rawResponse))
})
account, _, err := client.Accounts.GetAccount(wantedAccountID)
if err != nil {
t.Errorf("Accounts.GetAccount returned error %v", err)
}
if *account.ID != wantedAccountID {
t.Errorf("Accounts.GetAccount expected: %s, actual %s", wantedAccountID, *account.ID)
}
}
func TestGetAccountIdentities(t *testing.T) {
setup()
defer teardown()
wantedAccountID := "640e74943999391400416qr0"
mux.HandleFunc("/accounts/"+wantedAccountID+"/identities", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
rawResponse, _ := ioutil.ReadFile("./mocks/response_get_accounts_640e74943999391400416qr0_identities.json")
fmt.Fprint(w, string(rawResponse))
})
identities, _, err := client.Accounts.GetAccountIdentities(wantedAccountID)
if err != nil {
t.Errorf("Accounts.GetAccountIdentities returned error %v", err)
}
if len(*identities) != 2 {
t.Errorf("Accounts.GetAccountIdentities identities returned; expected %d, actual %d", 2, len(*identities))
}
wantedIdentities := []string{"foo", "bar"}
if !reflect.DeepEqual(*identities, wantedIdentities) {
t.Errorf("Actual = %+v, Expected = %+v", *identities, wantedIdentities)
}
}
func TestDeleteAccount(t *testing.T) {
setup()
defer teardown()
wantedAccountID := "640e74943999391400416qr0"
mux.HandleFunc("/accounts/"+wantedAccountID, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE")
fmt.Fprint(w, "")
})
ok, _, err := client.Accounts.DeleteAccount(wantedAccountID)
if err != nil {
t.Errorf("Accounts.DeleteAccount returned error %v", err)
}
if !ok {
t.Errorf("Accounts.DeleteAccount should return ok")
}
}
func TestAccountsURLParserErrors(t *testing.T) {
_, _, err := client.Accounts.DeleteAccount("%")
testURLParseError(t, err)
_, _, err = client.Accounts.GetAccount("%")
testURLParseError(t, err)
_, _, err = client.Accounts.GetAccountIdentities("%")
testURLParseError(t, err)
}