-
Notifications
You must be signed in to change notification settings - Fork 1
/
accounts_test.go
70 lines (60 loc) · 1.71 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
package gocancel
import (
"context"
"fmt"
"net/http"
"testing"
"time"
"github.com/google/go-cmp/cmp"
)
func TestAccount_marshal(t *testing.T) {
testJSONMarshal(t, &Account{}, "{}")
o := &Account{
ID: String("7ef66283-3f9d-4cab-8f31-72f3f734652b"),
Name: String("ACME"),
SandboxMode: Bool(true),
SandboxEmail: String("sandbox@acme.com"),
CreatedAt: &Timestamp{time.Date(2021, time.May, 27, 11, 49, 05, 0, time.UTC)},
UpdatedAt: &Timestamp{time.Date(2021, time.May, 27, 11, 49, 05, 0, time.UTC)},
}
want := `
{
"id":"7ef66283-3f9d-4cab-8f31-72f3f734652b",
"name":"ACME",
"sandbox_mode":true,
"sandbox_email":"sandbox@acme.com",
"created_at":"2021-05-27T11:49:05Z",
"updated_at":"2021-05-27T11:49:05Z"
}
`
testJSONMarshal(t, o, want)
}
func TestAccountsService_Get(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
mux.HandleFunc("/api/v1/accounts/b", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{"account": {"id":"b"}}`)
})
ctx := context.Background()
account, _, err := client.Accounts.Get(ctx, "b")
if err != nil {
t.Fatalf("Accounts.Get returned error: %v", err)
}
want := &Account{ID: String("b")}
if !cmp.Equal(account, want) {
t.Errorf("Accounts.Get returned %+v, want %+v", account, want)
}
const methodName = "Get"
testBadOptions(t, methodName, func() (err error) {
_, _, err = client.Accounts.Get(ctx, "\n")
return err
})
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Accounts.Get(ctx, "b")
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
return resp, err
})
}