github.com/google/go-github/v33@v33.0.0/github/users_administration_test.go (about) 1 // Copyright 2014 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 "encoding/json" 11 "net/http" 12 "reflect" 13 "testing" 14 ) 15 16 func TestUsersService_PromoteSiteAdmin(t *testing.T) { 17 client, mux, _, teardown := setup() 18 defer teardown() 19 20 mux.HandleFunc("/users/u/site_admin", func(w http.ResponseWriter, r *http.Request) { 21 testMethod(t, r, "PUT") 22 w.WriteHeader(http.StatusNoContent) 23 }) 24 25 _, err := client.Users.PromoteSiteAdmin(context.Background(), "u") 26 if err != nil { 27 t.Errorf("Users.PromoteSiteAdmin returned error: %v", err) 28 } 29 } 30 31 func TestUsersService_DemoteSiteAdmin(t *testing.T) { 32 client, mux, _, teardown := setup() 33 defer teardown() 34 35 mux.HandleFunc("/users/u/site_admin", func(w http.ResponseWriter, r *http.Request) { 36 testMethod(t, r, "DELETE") 37 w.WriteHeader(http.StatusNoContent) 38 }) 39 40 _, err := client.Users.DemoteSiteAdmin(context.Background(), "u") 41 if err != nil { 42 t.Errorf("Users.DemoteSiteAdmin returned error: %v", err) 43 } 44 } 45 46 func TestUsersService_Suspend(t *testing.T) { 47 client, mux, _, teardown := setup() 48 defer teardown() 49 50 mux.HandleFunc("/users/u/suspended", func(w http.ResponseWriter, r *http.Request) { 51 testMethod(t, r, "PUT") 52 w.WriteHeader(http.StatusNoContent) 53 }) 54 55 _, err := client.Users.Suspend(context.Background(), "u", nil) 56 if err != nil { 57 t.Errorf("Users.Suspend returned error: %v", err) 58 } 59 } 60 61 func TestUsersServiceReason_Suspend(t *testing.T) { 62 client, mux, _, teardown := setup() 63 defer teardown() 64 65 input := &UserSuspendOptions{Reason: String("test")} 66 67 mux.HandleFunc("/users/u/suspended", func(w http.ResponseWriter, r *http.Request) { 68 v := new(UserSuspendOptions) 69 json.NewDecoder(r.Body).Decode(v) 70 71 testMethod(t, r, "PUT") 72 if !reflect.DeepEqual(v, input) { 73 t.Errorf("Request body = %+v, want %+v", v, input) 74 } 75 76 w.WriteHeader(http.StatusNoContent) 77 }) 78 79 _, err := client.Users.Suspend(context.Background(), "u", input) 80 if err != nil { 81 t.Errorf("Users.Suspend returned error: %v", err) 82 } 83 } 84 85 func TestUsersService_Unsuspend(t *testing.T) { 86 client, mux, _, teardown := setup() 87 defer teardown() 88 89 mux.HandleFunc("/users/u/suspended", func(w http.ResponseWriter, r *http.Request) { 90 testMethod(t, r, "DELETE") 91 w.WriteHeader(http.StatusNoContent) 92 }) 93 94 _, err := client.Users.Unsuspend(context.Background(), "u") 95 if err != nil { 96 t.Errorf("Users.Unsuspend returned error: %v", err) 97 } 98 }