Browse Source

pass and return user emails as slices

there's no real need to use pointers here
Will Norris 13 years ago
parent
commit
af26438124
2 changed files with 12 additions and 12 deletions
  1. +3
    -3
      github/users.go
  2. +9
    -9
      github/users_test.go

+ 3
- 3
github/users.go View File

@ -126,7 +126,7 @@ func (s *UsersService) ListEmails() ([]UserEmail, error) {
// AddEmails adds email addresses of authenticated user
//
// GitHub API docs: http://developer.github.com/v3/users/emails/#add-email-addresses
func (s *UsersService) AddEmails(emails *[]UserEmail) (*[]UserEmail, error) {
func (s *UsersService) AddEmails(emails []UserEmail) ([]UserEmail, error) {
u := "user/emails"
req, err := s.client.NewRequest("POST", u, emails)
if err != nil {
@ -135,13 +135,13 @@ func (s *UsersService) AddEmails(emails *[]UserEmail) (*[]UserEmail, error) {
e := new([]UserEmail)
_, err = s.client.Do(req, e)
return e, err
return *e, err
}
// DeleteEmails deletes email addresses from authenticated user
//
// GitHub API docs: http://developer.github.com/v3/users/emails/#delete-email-addresses
func (s *UsersService) DeleteEmails(emails *[]UserEmail) error {
func (s *UsersService) DeleteEmails(emails []UserEmail) error {
u := "user/emails"
req, err := s.client.NewRequest("DELETE", u, emails)
if err != nil {


+ 9
- 9
github/users_test.go View File

@ -134,15 +134,15 @@ func TestUsersService_AddEmails(t *testing.T) {
setup()
defer teardown()
input := &[]UserEmail{"new@example.com"}
input := []UserEmail{"new@example.com"}
mux.HandleFunc("/user/emails", func(w http.ResponseWriter, r *http.Request) {
v := &[]UserEmail{}
v := new([]UserEmail)
json.NewDecoder(r.Body).Decode(v)
testMethod(t, r, "POST")
if !reflect.DeepEqual(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
if !reflect.DeepEqual(*v, input) {
t.Errorf("Request body = %+v, want %+v", *v, input)
}
fmt.Fprint(w, `["old@example.com", "new@example.com"]`)
@ -153,7 +153,7 @@ func TestUsersService_AddEmails(t *testing.T) {
t.Errorf("Users.AddEmails returned error: %v", err)
}
want := &[]UserEmail{"old@example.com", "new@example.com"}
want := []UserEmail{"old@example.com", "new@example.com"}
if !reflect.DeepEqual(emails, want) {
t.Errorf("Users.AddEmails returned %+v, want %+v", emails, want)
}
@ -163,15 +163,15 @@ func TestUsersService_DeleteEmails(t *testing.T) {
setup()
defer teardown()
input := &[]UserEmail{"user@example.com"}
input := []UserEmail{"user@example.com"}
mux.HandleFunc("/user/emails", func(w http.ResponseWriter, r *http.Request) {
v := &[]UserEmail{}
v := new([]UserEmail)
json.NewDecoder(r.Body).Decode(v)
testMethod(t, r, "DELETE")
if !reflect.DeepEqual(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
if !reflect.DeepEqual(*v, input) {
t.Errorf("Request body = %+v, want %+v", *v, input)
}
})


Loading…
Cancel
Save