-
Notifications
You must be signed in to change notification settings - Fork 44
/
doc_test.go
143 lines (114 loc) · 2.78 KB
/
doc_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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package recurly_test
import (
"context"
"fmt"
"net/http"
"time"
"github.com/blacklightcms/recurly"
)
var client *recurly.Client
func init() {
client = recurly.NewClient("your-subdomain", "APIKEY")
}
func ExampleNewClient() {
// Create a client pointing to https://your-subdomain.recurly.com
client := recurly.NewClient("your-subdomain", "APIKEY")
// Optionally overwrite the underlying HTTP client with your own
client.Client = &http.Client{
Timeout: 5 * time.Second,
Transport: &http.Transport{},
}
}
func Example_AccountsService_Create() {
_, err := client.Accounts.Create(context.Background(), recurly.Account{
Code: "1",
FirstName: "Verena",
LastName: "Example",
Email: "[email protected]",
})
if err != nil {
panic(err)
}
}
func ExampleNewTestServer() {
client, s := recurly.NewTestServer()
defer s.Close()
// NOTE: This example doesn't have access to *testing.T so it passes nil
// as the last argument to s.HandlFunc(). When setting up your tests,
// be sure to pass *testing.T instead of nil.
s.HandleFunc("GET", "/v2/accounts/1", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte(`
<?xml version="1.0" encoding="UTF-8"?>
<account href="https://your-subdomain.recurly.com/v2/accounts/1">
<email>[email protected]</email>
<first_name>Verena</first_name>
<last_name>Example</last_name>
</account>
`))
}, nil)
a, _ := client.Accounts.Get(context.Background(), "1")
fmt.Printf("%t\n", s.Invoked)
fmt.Printf("%t\n", a.FirstName == "Verena")
fmt.Printf("%t\n", a.LastName == "Example")
fmt.Printf("%t\n", a.Email == "[email protected]")
// Output:
// true
// true
// true
// true
}
func ExampleNullBool() {
b := recurly.NewBool(true)
fmt.Println(b.Bool())
value, ok := b.Value()
fmt.Println(value, ok)
// Output:
// true
// true true
}
func ExampleNullBool_invalid() {
var b recurly.NullBool
fmt.Println(b.Bool())
value, ok := b.Value()
fmt.Println(value, ok)
// Output:
// false
// false false
}
func ExampleNullInt() {
i := recurly.NewInt(100)
fmt.Println(i.Int())
value, ok := i.Value()
fmt.Println(value, ok)
// Output:
// 100
// 100 true
}
func ExampleNullInt_invalid() {
var i recurly.NullInt
fmt.Println(i.Int())
value, ok := i.Value()
fmt.Println(value, ok)
// Output:
// 0
// 0 false
}
func ExampleNullTime() {
t := recurly.NewTime(time.Date(2018, 5, 13, 0, 0, 0, 0, time.UTC))
fmt.Println(t.Time())
value, ok := t.Value()
fmt.Println(value, ok)
// Output:
// 2018-05-13 00:00:00 +0000 UTC
// 2018-05-13 00:00:00 +0000 UTC true
}
func ExampleNullTime_invalid() {
var t recurly.NullTime
fmt.Println(t.Time())
value, ok := t.Value()
fmt.Println(value, ok)
// Output:
// 0001-01-01 00:00:00 +0000 UTC
// 0001-01-01 00:00:00 +0000 UTC false
}