From 2d3520b58549ea4312e64352b9341b3d46d3fd6e Mon Sep 17 00:00:00 2001 From: Glenn Lewis Date: Wed, 6 Jul 2016 10:31:42 -0700 Subject: [PATCH] add unit tests for #342 - CreateImpersonation and DeleteImpersonation Change-Id: Ib5fd4e99b88ff01e3363e049177326b7ee97be93 --- github/authorizations_test.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/github/authorizations_test.go b/github/authorizations_test.go index b3d4e91..90a5324 100644 --- a/github/authorizations_test.go +++ b/github/authorizations_test.go @@ -306,3 +306,38 @@ func TestDeleteGrant(t *testing.T) { t.Errorf("OAuthAuthorizations.DeleteGrant returned error: %v", err) } } + +func TestAuthorizationsService_CreateImpersonation(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/admin/users/u/authorizations", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "POST") + fmt.Fprint(w, `{"id":1}`) + }) + + req := &AuthorizationRequest{Scopes: []Scope{ScopePublicRepo}} + got, _, err := client.Authorizations.CreateImpersonation("u", req) + if err != nil { + t.Errorf("Authorizations.CreateImpersonation returned error: %+v", err) + } + + want := &Authorization{ID: Int(1)} + if !reflect.DeepEqual(got, want) { + t.Errorf("Authorizations.CreateImpersonation returned %+v, want %+v", *got.ID, *want.ID) + } +} + +func TestAuthorizationsService_DeleteImpersonation(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/admin/users/u/authorizations", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "DELETE") + }) + + _, err := client.Authorizations.DeleteImpersonation("u") + if err != nil { + t.Errorf("Authorizations.DeleteImpersonation returned error: %+v", err) + } +}