forked from google/go-github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusers_emails_test.go
More file actions
94 lines (76 loc) · 2.21 KB
/
users_emails_test.go
File metadata and controls
94 lines (76 loc) · 2.21 KB
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
// Copyright 2013 The go-github AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package github
import (
"encoding/json"
"fmt"
"net/http"
"reflect"
"testing"
)
func TestUsersService_ListEmails(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/user/emails", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testFormValues(t, r, values{"page": "2"})
fmt.Fprint(w, `[{
"email": "[email protected]",
"verified": false,
"primary": true
}]`)
})
opt := &ListOptions{Page: 2}
emails, _, err := client.Users.ListEmails(opt)
if err != nil {
t.Errorf("Users.ListEmails returned error: %v", err)
}
want := []UserEmail{{Email: String("[email protected]"), Verified: Bool(false), Primary: Bool(true)}}
if !reflect.DeepEqual(emails, want) {
t.Errorf("Users.ListEmails returned %+v, want %+v", emails, want)
}
}
func TestUsersService_AddEmails(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/user/emails", func(w http.ResponseWriter, r *http.Request) {
v := new([]string)
json.NewDecoder(r.Body).Decode(v)
testMethod(t, r, "POST")
if !reflect.DeepEqual(*v, input) {
t.Errorf("Request body = %+v, want %+v", *v, input)
}
})
emails, _, err := client.Users.AddEmails(input)
if err != nil {
t.Errorf("Users.AddEmails returned error: %v", err)
}
want := []UserEmail{
}
if !reflect.DeepEqual(emails, want) {
t.Errorf("Users.AddEmails returned %+v, want %+v", emails, want)
}
}
func TestUsersService_DeleteEmails(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/user/emails", func(w http.ResponseWriter, r *http.Request) {
v := new([]string)
json.NewDecoder(r.Body).Decode(v)
testMethod(t, r, "DELETE")
if !reflect.DeepEqual(*v, input) {
t.Errorf("Request body = %+v, want %+v", *v, input)
}
})
_, err := client.Users.DeleteEmails(input)
if err != nil {
t.Errorf("Users.DeleteEmails returned error: %v", err)
}
}