github.com/google/go-github/v33@v33.0.0/github/repos_invitations_test.go (about) 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 6 package github 7 8 import ( 9 "context" 10 "fmt" 11 "net/http" 12 "reflect" 13 "testing" 14 ) 15 16 func 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 testFormValues(t, r, values{"page": "2"}) 23 fmt.Fprintf(w, `[{"id":1}, {"id":2}]`) 24 }) 25 26 opt := &ListOptions{Page: 2} 27 got, _, err := client.Repositories.ListInvitations(context.Background(), "o", "r", opt) 28 if err != nil { 29 t.Errorf("Repositories.ListInvitations returned error: %v", err) 30 } 31 32 want := []*RepositoryInvitation{{ID: Int64(1)}, {ID: Int64(2)}} 33 if !reflect.DeepEqual(got, want) { 34 t.Errorf("Repositories.ListInvitations = %+v, want %+v", got, want) 35 } 36 } 37 38 func TestRepositoriesService_DeleteInvitation(t *testing.T) { 39 client, mux, _, teardown := setup() 40 defer teardown() 41 42 mux.HandleFunc("/repos/o/r/invitations/2", func(w http.ResponseWriter, r *http.Request) { 43 testMethod(t, r, "DELETE") 44 w.WriteHeader(http.StatusNoContent) 45 }) 46 47 _, err := client.Repositories.DeleteInvitation(context.Background(), "o", "r", 2) 48 if err != nil { 49 t.Errorf("Repositories.DeleteInvitation returned error: %v", err) 50 } 51 } 52 53 func TestRepositoriesService_UpdateInvitation(t *testing.T) { 54 client, mux, _, teardown := setup() 55 defer teardown() 56 57 mux.HandleFunc("/repos/o/r/invitations/2", func(w http.ResponseWriter, r *http.Request) { 58 testMethod(t, r, "PATCH") 59 fmt.Fprintf(w, `{"id":1}`) 60 }) 61 62 got, _, err := client.Repositories.UpdateInvitation(context.Background(), "o", "r", 2, "write") 63 if err != nil { 64 t.Errorf("Repositories.UpdateInvitation returned error: %v", err) 65 } 66 67 want := &RepositoryInvitation{ID: Int64(1)} 68 if !reflect.DeepEqual(got, want) { 69 t.Errorf("Repositories.UpdateInvitation = %+v, want %+v", got, want) 70 } 71 }