forked from cloudflare/cloudflare-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser_test.go
59 lines (52 loc) · 1.29 KB
/
user_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
package cloudflare
import (
"fmt"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
func TestUser_UserDetails(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/user", func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "GET", r.Method, "Expected method 'GET', got %s", r.Method)
w.Header().Set("content-type", "application/json")
fmt.Fprintf(w, `{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "1",
"email": "[email protected]",
"first_name": "Jane",
"last_name": "Smith",
"username": "cloudflare12345",
"telephone": "+1 (650) 319 8930",
"country": "US",
"zipcode": "94107",
"created_on": "2009-07-01T00:00:00Z",
"modified_on": "2016-05-06T20:32:00Z",
"two_factor_authentication_enabled": true,
"betas": ["mirage_forever"]
}
}`)
})
user, err := client.UserDetails()
want := User{
ID: "1",
Email: "[email protected]",
FirstName: "Jane",
LastName: "Smith",
Username: "cloudflare12345",
Telephone: "+1 (650) 319 8930",
Country: "US",
Zipcode: "94107",
CreatedOn: "2009-07-01T00:00:00Z",
ModifiedOn: "2016-05-06T20:32:00Z",
TwoFA: true,
Betas: []string{"mirage_forever"},
}
if assert.NoError(t, err) {
assert.Equal(t, user, want)
}
}