1// Copyright 2016 The go-github AUTHORS. All rights reserved. 2// 3// Use of this source code is governed by a BSD-style 4// license that can be found in the LICENSE file. 5 6package github 7 8import ( 9 "context" 10 "fmt" 11 "net/http" 12 "reflect" 13 "testing" 14) 15 16func TestRepositoriesService_ListInvitations(t *testing.T) { 17 client, mux, _, teardown := setup() 18 defer teardown() 19 20 mux.HandleFunc("/repos/o/r/invitations", func(w http.ResponseWriter, r *http.Request) { 21 testMethod(t, r, "GET") 22 testHeader(t, r, "Accept", mediaTypeRepositoryInvitationsPreview) 23 testFormValues(t, r, values{"page": "2"}) 24 fmt.Fprintf(w, `[{"id":1}, {"id":2}]`) 25 }) 26 27 opt := &ListOptions{Page: 2} 28 got, _, err := client.Repositories.ListInvitations(context.Background(), "o", "r", opt) 29 if err != nil { 30 t.Errorf("Repositories.ListInvitations returned error: %v", err) 31 } 32 33 want := []*RepositoryInvitation{{ID: Int64(1)}, {ID: Int64(2)}} 34 if !reflect.DeepEqual(got, want) { 35 t.Errorf("Repositories.ListInvitations = %+v, want %+v", got, want) 36 } 37} 38 39func TestRepositoriesService_DeleteInvitation(t *testing.T) { 40 client, mux, _, teardown := setup() 41 defer teardown() 42 43 mux.HandleFunc("/repos/o/r/invitations/2", func(w http.ResponseWriter, r *http.Request) { 44 testMethod(t, r, "DELETE") 45 testHeader(t, r, "Accept", mediaTypeRepositoryInvitationsPreview) 46 w.WriteHeader(http.StatusNoContent) 47 }) 48 49 _, err := client.Repositories.DeleteInvitation(context.Background(), "o", "r", 2) 50 if err != nil { 51 t.Errorf("Repositories.DeleteInvitation returned error: %v", err) 52 } 53} 54 55func TestRepositoriesService_UpdateInvitation(t *testing.T) { 56 client, mux, _, teardown := setup() 57 defer teardown() 58 59 mux.HandleFunc("/repos/o/r/invitations/2", func(w http.ResponseWriter, r *http.Request) { 60 testMethod(t, r, "PATCH") 61 testHeader(t, r, "Accept", mediaTypeRepositoryInvitationsPreview) 62 fmt.Fprintf(w, `{"id":1}`) 63 }) 64 65 got, _, err := client.Repositories.UpdateInvitation(context.Background(), "o", "r", 2, "write") 66 if err != nil { 67 t.Errorf("Repositories.UpdateInvitation returned error: %v", err) 68 } 69 70 want := &RepositoryInvitation{ID: Int64(1)} 71 if !reflect.DeepEqual(got, want) { 72 t.Errorf("Repositories.UpdateInvitation = %+v, want %+v", got, want) 73 } 74} 75