| 1 |
// Copyright 2022 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 |
"testing" |
| 13 |
|
| 14 |
"github.com/google/go-cmp/cmp" |
| 15 |
) |
| 16 |
|
| 17 |
func TestOrganizationsService_ListSecurityManagerTeams(t *testing.T) { |
| 18 |
client, mux, _, teardown := setup() |
| 19 |
defer teardown() |
| 20 |
|
| 21 |
mux.HandleFunc("/orgs/o/security-managers", func(w http.ResponseWriter, r *http.Request) { |
| 22 |
testMethod(t, r, "GET") |
| 23 |
fmt.Fprint(w, `[{"id":1}]`) |
| 24 |
}) |
| 25 |
|
| 26 |
ctx := context.Background() |
| 27 |
teams, _, err := client.Organizations.ListSecurityManagerTeams(ctx, "o") |
| 28 |
if err != nil { |
| 29 |
t.Errorf("Organizations.ListSecurityManagerTeams returned error: %v", err) |
| 30 |
} |
| 31 |
|
| 32 |
want := []*Team{{ID: Int64(1)}} |
| 33 |
if !cmp.Equal(teams, want) { |
| 34 |
t.Errorf("Organizations.ListSecurityManagerTeams returned %+v, want %+v", teams, want) |
| 35 |
} |
| 36 |
|
| 37 |
const methodName = "ListSecurityManagerTeams" |
| 38 |
testBadOptions(t, methodName, func() (err error) { |
| 39 |
_, _, err = client.Organizations.ListSecurityManagerTeams(ctx, "\n") |
| 40 |
return err |
| 41 |
}) |
| 42 |
|
| 43 |
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { |
| 44 |
got, resp, err := client.Organizations.ListSecurityManagerTeams(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_ListSecurityManagerTeams_invalidOrg(t *testing.T) { |
| 53 |
client, _, _, teardown := setup() |
| 54 |
defer teardown() |
| 55 |
|
| 56 |
ctx := context.Background() |
| 57 |
_, _, err := client.Organizations.ListSecurityManagerTeams(ctx, "%") |
| 58 |
testURLParseError(t, err) |
| 59 |
} |
| 60 |
|
| 61 |
func TestOrganizationsService_AddSecurityManagerTeam(t *testing.T) { |
| 62 |
client, mux, _, teardown := setup() |
| 63 |
defer teardown() |
| 64 |
|
| 65 |
mux.HandleFunc("/orgs/o/security-managers/teams/t", func(w http.ResponseWriter, r *http.Request) { |
| 66 |
testMethod(t, r, "PUT") |
| 67 |
}) |
| 68 |
|
| 69 |
ctx := context.Background() |
| 70 |
_, err := client.Organizations.AddSecurityManagerTeam(ctx, "o", "t") |
| 71 |
if err != nil { |
| 72 |
t.Errorf("Organizations.AddSecurityManagerTeam returned error: %v", err) |
| 73 |
} |
| 74 |
|
| 75 |
const methodName = "AddSecurityManagerTeam" |
| 76 |
testBadOptions(t, methodName, func() (err error) { |
| 77 |
_, err = client.Organizations.AddSecurityManagerTeam(ctx, "\n", "\n") |
| 78 |
return err |
| 79 |
}) |
| 80 |
|
| 81 |
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { |
| 82 |
return client.Organizations.AddSecurityManagerTeam(ctx, "o", "t") |
| 83 |
}) |
| 84 |
} |
| 85 |
|
| 86 |
func TestOrganizationsService_AddSecurityManagerTeam_invalidOrg(t *testing.T) { |
| 87 |
client, _, _, teardown := setup() |
| 88 |
defer teardown() |
| 89 |
|
| 90 |
ctx := context.Background() |
| 91 |
_, err := client.Organizations.AddSecurityManagerTeam(ctx, "%", "t") |
| 92 |
testURLParseError(t, err) |
| 93 |
} |
| 94 |
|
| 95 |
func TestOrganizationsService_AddSecurityManagerTeam_invalidTeam(t *testing.T) { |
| 96 |
client, _, _, teardown := setup() |
| 97 |
defer teardown() |
| 98 |
|
| 99 |
ctx := context.Background() |
| 100 |
_, err := client.Organizations.AddSecurityManagerTeam(ctx, "%", "t") |
| 101 |
testURLParseError(t, err) |
| 102 |
} |
| 103 |
|
| 104 |
func TestOrganizationsService_RemoveSecurityManagerTeam(t *testing.T) { |
| 105 |
client, mux, _, teardown := setup() |
| 106 |
defer teardown() |
| 107 |
|
| 108 |
mux.HandleFunc("/orgs/o/security-managers/teams/t", func(w http.ResponseWriter, r *http.Request) { |
| 109 |
testMethod(t, r, "DELETE") |
| 110 |
}) |
| 111 |
|
| 112 |
ctx := context.Background() |
| 113 |
_, err := client.Organizations.RemoveSecurityManagerTeam(ctx, "o", "t") |
| 114 |
if err != nil { |
| 115 |
t.Errorf("Organizations.RemoveSecurityManagerTeam returned error: %v", err) |
| 116 |
} |
| 117 |
|
| 118 |
const methodName = "RemoveSecurityManagerTeam" |
| 119 |
testBadOptions(t, methodName, func() (err error) { |
| 120 |
_, err = client.Organizations.RemoveSecurityManagerTeam(ctx, "\n", "\n") |
| 121 |
return err |
| 122 |
}) |
| 123 |
|
| 124 |
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { |
| 125 |
return client.Organizations.RemoveSecurityManagerTeam(ctx, "o", "t") |
| 126 |
}) |
| 127 |
} |
| 128 |
|
| 129 |
func TestOrganizationsService_RemoveSecurityManagerTeam_invalidOrg(t *testing.T) { |
| 130 |
client, _, _, teardown := setup() |
| 131 |
defer teardown() |
| 132 |
|
| 133 |
ctx := context.Background() |
| 134 |
_, err := client.Organizations.RemoveSecurityManagerTeam(ctx, "%", "t") |
| 135 |
testURLParseError(t, err) |
| 136 |
} |
| 137 |
|
| 138 |
func TestOrganizationsService_RemoveSecurityManagerTeam_invalidTeam(t *testing.T) { |
| 139 |
client, _, _, teardown := setup() |
| 140 |
defer teardown() |
| 141 |
|
| 142 |
ctx := context.Background() |
| 143 |
_, err := client.Organizations.RemoveSecurityManagerTeam(ctx, "%", "t") |
| 144 |
testURLParseError(t, err) |
| 145 |
} |