github.com/google/go-github/v66@v66.0.0/github/orgs_actions_allowed_test.go (about) 1 // Copyright 2021 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 "fmt" 12 "net/http" 13 "testing" 14 15 "github.com/google/go-cmp/cmp" 16 ) 17 18 func TestOrganizationsService_GetActionsAllowed(t *testing.T) { 19 t.Parallel() 20 client, mux, _ := setup(t) 21 22 mux.HandleFunc("/orgs/o/actions/permissions/selected-actions", func(w http.ResponseWriter, r *http.Request) { 23 testMethod(t, r, "GET") 24 fmt.Fprint(w, `{"github_owned_allowed":true, "verified_allowed":false, "patterns_allowed":["a/b"]}`) 25 }) 26 27 ctx := context.Background() 28 org, _, err := client.Organizations.GetActionsAllowed(ctx, "o") 29 if err != nil { 30 t.Errorf("Organizations.GetActionsAllowed returned error: %v", err) 31 } 32 want := &ActionsAllowed{GithubOwnedAllowed: Bool(true), VerifiedAllowed: Bool(false), PatternsAllowed: []string{"a/b"}} 33 if !cmp.Equal(org, want) { 34 t.Errorf("Organizations.GetActionsAllowed returned %+v, want %+v", org, want) 35 } 36 37 const methodName = "GetActionsAllowed" 38 testBadOptions(t, methodName, func() (err error) { 39 _, _, err = client.Organizations.GetActionsAllowed(ctx, "\n") 40 return err 41 }) 42 43 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 44 got, resp, err := client.Organizations.GetActionsAllowed(ctx, "o") 45 if got != nil { 46 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) 47 } 48 return resp, err 49 }) 50 } 51 52 func TestOrganizationsService_EditActionsAllowed(t *testing.T) { 53 t.Parallel() 54 client, mux, _ := setup(t) 55 56 input := &ActionsAllowed{GithubOwnedAllowed: Bool(true), VerifiedAllowed: Bool(false), PatternsAllowed: []string{"a/b"}} 57 58 mux.HandleFunc("/orgs/o/actions/permissions/selected-actions", func(w http.ResponseWriter, r *http.Request) { 59 v := new(ActionsAllowed) 60 assertNilError(t, json.NewDecoder(r.Body).Decode(v)) 61 62 testMethod(t, r, "PUT") 63 if !cmp.Equal(v, input) { 64 t.Errorf("Request body = %+v, want %+v", v, input) 65 } 66 67 fmt.Fprint(w, `{"github_owned_allowed":true, "verified_allowed":false, "patterns_allowed":["a/b"]}`) 68 }) 69 70 ctx := context.Background() 71 org, _, err := client.Organizations.EditActionsAllowed(ctx, "o", *input) 72 if err != nil { 73 t.Errorf("Organizations.EditActionsAllowed returned error: %v", err) 74 } 75 76 want := &ActionsAllowed{GithubOwnedAllowed: Bool(true), VerifiedAllowed: Bool(false), PatternsAllowed: []string{"a/b"}} 77 if !cmp.Equal(org, want) { 78 t.Errorf("Organizations.EditActionsAllowed returned %+v, want %+v", org, want) 79 } 80 81 const methodName = "EditActionsAllowed" 82 testBadOptions(t, methodName, func() (err error) { 83 _, _, err = client.Organizations.EditActionsAllowed(ctx, "\n", *input) 84 return err 85 }) 86 87 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 88 got, resp, err := client.Organizations.EditActionsAllowed(ctx, "o", *input) 89 if got != nil { 90 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) 91 } 92 return resp, err 93 }) 94 }