github.com/google/go-github/v60@v60.0.0/github/orgs_personal_access_tokens_test.go (about) 1 // Copyright 2023 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 "testing" 13 14 "github.com/google/go-cmp/cmp" 15 ) 16 17 func TestOrganizationsService_ReviewPersonalAccessTokenRequest(t *testing.T) { 18 client, mux, _, teardown := setup() 19 defer teardown() 20 21 input := ReviewPersonalAccessTokenRequestOptions{ 22 Action: "a", 23 Reason: String("r"), 24 } 25 26 mux.HandleFunc("/orgs/o/personal-access-token-requests/1", func(w http.ResponseWriter, r *http.Request) { 27 v := new(ReviewPersonalAccessTokenRequestOptions) 28 assertNilError(t, json.NewDecoder(r.Body).Decode(v)) 29 30 testMethod(t, r, http.MethodPost) 31 if !cmp.Equal(v, &input) { 32 t.Errorf("Request body = %+v, want %+v", v, input) 33 } 34 35 w.WriteHeader(http.StatusNoContent) 36 }) 37 38 ctx := context.Background() 39 res, err := client.Organizations.ReviewPersonalAccessTokenRequest(ctx, "o", 1, input) 40 if err != nil { 41 t.Errorf("Organizations.ReviewPersonalAccessTokenRequest returned error: %v", err) 42 } 43 44 if res.StatusCode != http.StatusNoContent { 45 t.Errorf("Organizations.ReviewPersonalAccessTokenRequest returned %v, want %v", res.StatusCode, http.StatusNoContent) 46 } 47 48 const methodName = "ReviewPersonalAccessTokenRequest" 49 testBadOptions(t, methodName, func() (err error) { 50 _, err = client.Organizations.ReviewPersonalAccessTokenRequest(ctx, "\n", 0, input) 51 return err 52 }) 53 54 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 55 return client.Organizations.ReviewPersonalAccessTokenRequest(ctx, "o", 1, input) 56 }) 57 } 58 59 func TestReviewPersonalAccessTokenRequestOptions_Marshal(t *testing.T) { 60 testJSONMarshal(t, &ReviewPersonalAccessTokenRequestOptions{}, "{}") 61 62 u := &ReviewPersonalAccessTokenRequestOptions{ 63 Action: "a", 64 Reason: String("r"), 65 } 66 67 want := `{ 68 "action": "a", 69 "reason": "r" 70 }` 71 72 testJSONMarshal(t, u, want) 73 }