| 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 |
"fmt" |
| 11 |
"net/http" |
| 12 |
"testing" |
| 13 |
|
| 14 |
"github.com/google/go-cmp/cmp" |
| 15 |
) |
| 16 |
|
| 17 |
func TestEnterpriseService_ListRunnerGroups(t *testing.T) { |
| 18 |
client, mux, _, teardown := setup() |
| 19 |
defer teardown() |
| 20 |
|
| 21 |
mux.HandleFunc("/enterprises/o/actions/runner-groups", func(w http.ResponseWriter, r *http.Request) { |
| 22 |
testMethod(t, r, "GET") |
| 23 |
testFormValues(t, r, values{"per_page": "2", "page": "2"}) |
| 24 |
fmt.Fprint(w, `{"total_count":3,"runner_groups":[{"id":1,"name":"Default","visibility":"all","default":true,"runners_url":"https://api.github.com/enterprises/octo-enterprise/actions/runner_groups/1/runners","inherited":false,"allows_public_repositories":true,"restricted_to_workflows":true,"selected_workflows":["a","b"]},{"id":2,"name":"octo-runner-group","visibility":"selected","default":false,"selected_organizations_url":"https://api.github.com/enterprises/octo-enterprise/actions/runner_groups/2/organizations","runners_url":"https://api.github.com/enterprises/octo-enterprise/actions/runner_groups/2/runners","inherited":true,"allows_public_repositories":true,"restricted_to_workflows":false,"selected_workflows":[]},{"id":3,"name":"expensive-hardware","visibility":"private","default":false,"runners_url":"https://api.github.com/enterprises/octo-enterprise/actions/runner_groups/3/runners","inherited":false,"allows_public_repositories":true,"restricted_to_workflows":false,"selected_workflows":[]}]}`) |
| 25 |
}) |
| 26 |
|
| 27 |
opts := &ListEnterpriseRunnerGroupOptions{ListOptions: ListOptions{Page: 2, PerPage: 2}} |
| 28 |
ctx := context.Background() |
| 29 |
groups, _, err := client.Enterprise.ListRunnerGroups(ctx, "o", opts) |
| 30 |
if err != nil { |
| 31 |
t.Errorf("Enterprise.ListRunnerGroups returned error: %v", err) |
| 32 |
} |
| 33 |
|
| 34 |
want := &EnterpriseRunnerGroups{ |
| 35 |
TotalCount: Int(3), |
| 36 |
RunnerGroups: []*EnterpriseRunnerGroup{ |
| 37 |
{ID: Int64(1), Name: String("Default"), Visibility: String("all"), Default: Bool(true), RunnersURL: String("https://api.github.com/enterprises/octo-enterprise/actions/runner_groups/1/runners"), Inherited: Bool(false), AllowsPublicRepositories: Bool(true), RestrictedToWorkflows: Bool(true), SelectedWorkflows: []string{"a", "b"}}, |
| 38 |
{ID: Int64(2), Name: String("octo-runner-group"), Visibility: String("selected"), Default: Bool(false), SelectedOrganizationsURL: String("https://api.github.com/enterprises/octo-enterprise/actions/runner_groups/2/organizations"), RunnersURL: String("https://api.github.com/enterprises/octo-enterprise/actions/runner_groups/2/runners"), Inherited: Bool(true), AllowsPublicRepositories: Bool(true), RestrictedToWorkflows: Bool(false), SelectedWorkflows: []string{}}, |
| 39 |
{ID: Int64(3), Name: String("expensive-hardware"), Visibility: String("private"), Default: Bool(false), RunnersURL: String("https://api.github.com/enterprises/octo-enterprise/actions/runner_groups/3/runners"), Inherited: Bool(false), AllowsPublicRepositories: Bool(true), RestrictedToWorkflows: Bool(false), SelectedWorkflows: []string{}}, |
| 40 |
}, |
| 41 |
} |
| 42 |
if !cmp.Equal(groups, want) { |
| 43 |
t.Errorf("Enterprise.ListRunnerGroups returned %+v, want %+v", groups, want) |
| 44 |
} |
| 45 |
|
| 46 |
const methodName = "ListRunnerGroups" |
| 47 |
testBadOptions(t, methodName, func() (err error) { |
| 48 |
_, _, err = client.Enterprise.ListRunnerGroups(ctx, "\n", opts) |
| 49 |
return err |
| 50 |
}) |
| 51 |
|
| 52 |
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { |
| 53 |
got, resp, err := client.Enterprise.ListRunnerGroups(ctx, "o", opts) |
| 54 |
if got != nil { |
| 55 |
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) |
| 56 |
} |
| 57 |
return resp, err |
| 58 |
}) |
| 59 |
} |
| 60 |
|
| 61 |
func TestEnterpriseService_ListRunnerGroupsVisibleToOrganization(t *testing.T) { |
| 62 |
client, mux, _, teardown := setup() |
| 63 |
defer teardown() |
| 64 |
|
| 65 |
mux.HandleFunc("/enterprises/o/actions/runner-groups", func(w http.ResponseWriter, r *http.Request) { |
| 66 |
testMethod(t, r, "GET") |
| 67 |
testFormValues(t, r, values{"per_page": "2", "page": "2", "visible_to_organization": "github"}) |
| 68 |
fmt.Fprint(w, `{"total_count":3,"runner_groups":[{"id":1,"name":"Default","visibility":"all","default":true,"runners_url":"https://api.github.com/enterprises/octo-enterprise/actions/runner_groups/1/runners","inherited":false,"allows_public_repositories":true,"restricted_to_workflows":false,"selected_workflows":[]},{"id":2,"name":"octo-runner-group","visibility":"selected","default":false,"selected_organizations_url":"https://api.github.com/enterprises/octo-enterprise/actions/runner_groups/2/organizations","runners_url":"https://api.github.com/enterprises/octo-enterprise/actions/runner_groups/2/runners","inherited":true,"allows_public_repositories":true,"restricted_to_workflows":false,"selected_workflows":[]},{"id":3,"name":"expensive-hardware","visibility":"private","default":false,"runners_url":"https://api.github.com/enterprises/octo-enterprise/actions/runner_groups/3/runners","inherited":false,"allows_public_repositories":true,"restricted_to_workflows":false,"selected_workflows":[]}]}`) |
| 69 |
}) |
| 70 |
|
| 71 |
opts := &ListEnterpriseRunnerGroupOptions{ListOptions: ListOptions{Page: 2, PerPage: 2}, VisibleToOrganization: "github"} |
| 72 |
ctx := context.Background() |
| 73 |
groups, _, err := client.Enterprise.ListRunnerGroups(ctx, "o", opts) |
| 74 |
if err != nil { |
| 75 |
t.Errorf("Enterprise.ListRunnerGroups returned error: %v", err) |
| 76 |
} |
| 77 |
|
| 78 |
want := &EnterpriseRunnerGroups{ |
| 79 |
TotalCount: Int(3), |
| 80 |
RunnerGroups: []*EnterpriseRunnerGroup{ |
| 81 |
{ID: Int64(1), Name: String("Default"), Visibility: String("all"), Default: Bool(true), RunnersURL: String("https://api.github.com/enterprises/octo-enterprise/actions/runner_groups/1/runners"), Inherited: Bool(false), AllowsPublicRepositories: Bool(true), RestrictedToWorkflows: Bool(false), SelectedWorkflows: []string{}}, |
| 82 |
{ID: Int64(2), Name: String("octo-runner-group"), Visibility: String("selected"), Default: Bool(false), SelectedOrganizationsURL: String("https://api.github.com/enterprises/octo-enterprise/actions/runner_groups/2/organizations"), RunnersURL: String("https://api.github.com/enterprises/octo-enterprise/actions/runner_groups/2/runners"), Inherited: Bool(true), AllowsPublicRepositories: Bool(true), RestrictedToWorkflows: Bool(false), SelectedWorkflows: []string{}}, |
| 83 |
{ID: Int64(3), Name: String("expensive-hardware"), Visibility: String("private"), Default: Bool(false), RunnersURL: String("https://api.github.com/enterprises/octo-enterprise/actions/runner_groups/3/runners"), Inherited: Bool(false), AllowsPublicRepositories: Bool(true), RestrictedToWorkflows: Bool(false), SelectedWorkflows: []string{}}, |
| 84 |
}, |
| 85 |
} |
| 86 |
if !cmp.Equal(groups, want) { |
| 87 |
t.Errorf("Enterprise.ListRunnerGroups returned %+v, want %+v", groups, want) |
| 88 |
} |
| 89 |
|
| 90 |
const methodName = "ListRunnerGroups" |
| 91 |
testBadOptions(t, methodName, func() (err error) { |
| 92 |
_, _, err = client.Enterprise.ListRunnerGroups(ctx, "\n", opts) |
| 93 |
return err |
| 94 |
}) |
| 95 |
|
| 96 |
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { |
| 97 |
got, resp, err := client.Enterprise.ListRunnerGroups(ctx, "o", opts) |
| 98 |
if got != nil { |
| 99 |
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) |
| 100 |
} |
| 101 |
return resp, err |
| 102 |
}) |
| 103 |
} |
| 104 |
|
| 105 |
func TestEnterpriseService_GetRunnerGroup(t *testing.T) { |
| 106 |
client, mux, _, teardown := setup() |
| 107 |
defer teardown() |
| 108 |
|
| 109 |
mux.HandleFunc("/enterprises/o/actions/runner-groups/2", func(w http.ResponseWriter, r *http.Request) { |
| 110 |
testMethod(t, r, "GET") |
| 111 |
fmt.Fprint(w, `{"id":2,"name":"octo-runner-group","visibility":"selected","default":false,"selected_organizations_url":"https://api.github.com/enterprises/octo-enterprise/actions/runner_groups/2/organizations","runners_url":"https://api.github.com/enterprises/octo-enterprise/actions/runner_groups/2/runners","inherited":false,"allows_public_repositories":true,"restricted_to_workflows":false,"selected_workflows":[]}`) |
| 112 |
}) |
| 113 |
|
| 114 |
ctx := context.Background() |
| 115 |
group, _, err := client.Enterprise.GetEnterpriseRunnerGroup(ctx, "o", 2) |
| 116 |
if err != nil { |
| 117 |
t.Errorf("Enterprise.GetRunnerGroup returned error: %v", err) |
| 118 |
} |
| 119 |
|
| 120 |
want := &EnterpriseRunnerGroup{ |
| 121 |
ID: Int64(2), |
| 122 |
Name: String("octo-runner-group"), |
| 123 |
Visibility: String("selected"), |
| 124 |
Default: Bool(false), |
| 125 |
SelectedOrganizationsURL: String("https://api.github.com/enterprises/octo-enterprise/actions/runner_groups/2/organizations"), |
| 126 |
RunnersURL: String("https://api.github.com/enterprises/octo-enterprise/actions/runner_groups/2/runners"), |
| 127 |
Inherited: Bool(false), |
| 128 |
AllowsPublicRepositories: Bool(true), |
| 129 |
RestrictedToWorkflows: Bool(false), |
| 130 |
SelectedWorkflows: []string{}, |
| 131 |
} |
| 132 |
|
| 133 |
if !cmp.Equal(group, want) { |
| 134 |
t.Errorf("Enterprise.GetRunnerGroup returned %+v, want %+v", group, want) |
| 135 |
} |
| 136 |
|
| 137 |
const methodName = "GetRunnerGroup" |
| 138 |
testBadOptions(t, methodName, func() (err error) { |
| 139 |
_, _, err = client.Enterprise.GetEnterpriseRunnerGroup(ctx, "\n", 2) |
| 140 |
return err |
| 141 |
}) |
| 142 |
|
| 143 |
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { |
| 144 |
got, resp, err := client.Enterprise.GetEnterpriseRunnerGroup(ctx, "o", 2) |
| 145 |
if got != nil { |
| 146 |
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) |
| 147 |
} |
| 148 |
return resp, err |
| 149 |
}) |
| 150 |
} |
| 151 |
|
| 152 |
func TestEnterpriseService_DeleteRunnerGroup(t *testing.T) { |
| 153 |
client, mux, _, teardown := setup() |
| 154 |
defer teardown() |
| 155 |
|
| 156 |
mux.HandleFunc("/enterprises/o/actions/runner-groups/2", func(w http.ResponseWriter, r *http.Request) { |
| 157 |
testMethod(t, r, "DELETE") |
| 158 |
}) |
| 159 |
|
| 160 |
ctx := context.Background() |
| 161 |
_, err := client.Enterprise.DeleteEnterpriseRunnerGroup(ctx, "o", 2) |
| 162 |
if err != nil { |
| 163 |
t.Errorf("Enterprise.DeleteRunnerGroup returned error: %v", err) |
| 164 |
} |
| 165 |
|
| 166 |
const methodName = "DeleteRunnerGroup" |
| 167 |
testBadOptions(t, methodName, func() (err error) { |
| 168 |
_, err = client.Enterprise.DeleteEnterpriseRunnerGroup(ctx, "\n", 2) |
| 169 |
return err |
| 170 |
}) |
| 171 |
|
| 172 |
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { |
| 173 |
return client.Enterprise.DeleteEnterpriseRunnerGroup(ctx, "o", 2) |
| 174 |
}) |
| 175 |
} |
| 176 |
|
| 177 |
func TestEnterpriseService_CreateRunnerGroup(t *testing.T) { |
| 178 |
client, mux, _, teardown := setup() |
| 179 |
defer teardown() |
| 180 |
|
| 181 |
mux.HandleFunc("/enterprises/o/actions/runner-groups", func(w http.ResponseWriter, r *http.Request) { |
| 182 |
testMethod(t, r, "POST") |
| 183 |
fmt.Fprint(w, `{"id":2,"name":"octo-runner-group","visibility":"selected","default":false,"selected_organizations_url":"https://api.github.com/enterprises/octo-enterprise/actions/runner_groups/2/organizations","runners_url":"https://api.github.com/enterprises/octo-enterprise/actions/runner_groups/2/runners","inherited":false,"allows_public_repositories":true,"restricted_to_workflows":false,"selected_workflows":[]}`) |
| 184 |
}) |
| 185 |
|
| 186 |
ctx := context.Background() |
| 187 |
req := CreateEnterpriseRunnerGroupRequest{ |
| 188 |
Name: String("octo-runner-group"), |
| 189 |
Visibility: String("selected"), |
| 190 |
AllowsPublicRepositories: Bool(true), |
| 191 |
RestrictedToWorkflows: Bool(false), |
| 192 |
SelectedWorkflows: []string{}, |
| 193 |
} |
| 194 |
group, _, err := client.Enterprise.CreateEnterpriseRunnerGroup(ctx, "o", req) |
| 195 |
if err != nil { |
| 196 |
t.Errorf("Enterprise.CreateRunnerGroup returned error: %v", err) |
| 197 |
} |
| 198 |
|
| 199 |
want := &EnterpriseRunnerGroup{ |
| 200 |
ID: Int64(2), |
| 201 |
Name: String("octo-runner-group"), |
| 202 |
Visibility: String("selected"), |
| 203 |
Default: Bool(false), |
| 204 |
SelectedOrganizationsURL: String("https://api.github.com/enterprises/octo-enterprise/actions/runner_groups/2/organizations"), |
| 205 |
RunnersURL: String("https://api.github.com/enterprises/octo-enterprise/actions/runner_groups/2/runners"), |
| 206 |
Inherited: Bool(false), |
| 207 |
AllowsPublicRepositories: Bool(true), |
| 208 |
RestrictedToWorkflows: Bool(false), |
| 209 |
SelectedWorkflows: []string{}, |
| 210 |
} |
| 211 |
|
| 212 |
if !cmp.Equal(group, want) { |
| 213 |
t.Errorf("Enterprise.CreateRunnerGroup returned %+v, want %+v", group, want) |
| 214 |
} |
| 215 |
|
| 216 |
const methodName = "CreateRunnerGroup" |
| 217 |
testBadOptions(t, methodName, func() (err error) { |
| 218 |
_, _, err = client.Enterprise.CreateEnterpriseRunnerGroup(ctx, "\n", req) |
| 219 |
return err |
| 220 |
}) |
| 221 |
|
| 222 |
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { |
| 223 |
got, resp, err := client.Enterprise.CreateEnterpriseRunnerGroup(ctx, "o", req) |
| 224 |
if got != nil { |
| 225 |
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) |
| 226 |
} |
| 227 |
return resp, err |
| 228 |
}) |
| 229 |
} |
| 230 |
|
| 231 |
func TestEnterpriseService_UpdateRunnerGroup(t *testing.T) { |
| 232 |
client, mux, _, teardown := setup() |
| 233 |
defer teardown() |
| 234 |
|
| 235 |
mux.HandleFunc("/enterprises/o/actions/runner-groups/2", func(w http.ResponseWriter, r *http.Request) { |
| 236 |
testMethod(t, r, "PATCH") |
| 237 |
fmt.Fprint(w, `{"id":2,"name":"octo-runner-group","visibility":"selected","default":false,"selected_organizations_url":"https://api.github.com/enterprises/octo-enterprise/actions/runner_groups/2/organizations","runners_url":"https://api.github.com/enterprises/octo-enterprise/actions/runner_groups/2/runners","inherited":false,"allows_public_repositories":true,"restricted_to_workflows":false,"selected_workflows":[]}`) |
| 238 |
}) |
| 239 |
|
| 240 |
ctx := context.Background() |
| 241 |
req := UpdateEnterpriseRunnerGroupRequest{ |
| 242 |
Name: String("octo-runner-group"), |
| 243 |
Visibility: String("selected"), |
| 244 |
AllowsPublicRepositories: Bool(true), |
| 245 |
RestrictedToWorkflows: Bool(false), |
| 246 |
SelectedWorkflows: []string{}, |
| 247 |
} |
| 248 |
group, _, err := client.Enterprise.UpdateEnterpriseRunnerGroup(ctx, "o", 2, req) |
| 249 |
if err != nil { |
| 250 |
t.Errorf("Enterprise.UpdateRunnerGroup returned error: %v", err) |
| 251 |
} |
| 252 |
|
| 253 |
want := &EnterpriseRunnerGroup{ |
| 254 |
ID: Int64(2), |
| 255 |
Name: String("octo-runner-group"), |
| 256 |
Visibility: String("selected"), |
| 257 |
Default: Bool(false), |
| 258 |
SelectedOrganizationsURL: String("https://api.github.com/enterprises/octo-enterprise/actions/runner_groups/2/organizations"), |
| 259 |
RunnersURL: String("https://api.github.com/enterprises/octo-enterprise/actions/runner_groups/2/runners"), |
| 260 |
Inherited: Bool(false), |
| 261 |
AllowsPublicRepositories: Bool(true), |
| 262 |
RestrictedToWorkflows: Bool(false), |
| 263 |
SelectedWorkflows: []string{}, |
| 264 |
} |
| 265 |
|
| 266 |
if !cmp.Equal(group, want) { |
| 267 |
t.Errorf("Enterprise.UpdateRunnerGroup returned %+v, want %+v", group, want) |
| 268 |
} |
| 269 |
|
| 270 |
const methodName = "UpdateRunnerGroup" |
| 271 |
testBadOptions(t, methodName, func() (err error) { |
| 272 |
_, _, err = client.Enterprise.UpdateEnterpriseRunnerGroup(ctx, "\n", 2, req) |
| 273 |
return err |
| 274 |
}) |
| 275 |
|
| 276 |
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { |
| 277 |
got, resp, err := client.Enterprise.UpdateEnterpriseRunnerGroup(ctx, "o", 2, req) |
| 278 |
if got != nil { |
| 279 |
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) |
| 280 |
} |
| 281 |
return resp, err |
| 282 |
}) |
| 283 |
} |
| 284 |
|
| 285 |
func TestEnterpriseService_ListOrganizationAccessRunnerGroup(t *testing.T) { |
| 286 |
client, mux, _, teardown := setup() |
| 287 |
defer teardown() |
| 288 |
|
| 289 |
mux.HandleFunc("/enterprises/o/actions/runner-groups/2/organizations", func(w http.ResponseWriter, r *http.Request) { |
| 290 |
testMethod(t, r, "GET") |
| 291 |
testFormValues(t, r, values{"per_page": "1", "page": "1"}) |
| 292 |
fmt.Fprint(w, `{"total_count": 1, "organizations": [{"id": 43, "node_id": "MDEwOlJlcG9zaXRvcnkxMjk2MjY5", "name": "Hello-World", "login": "octocat"}]}`) |
| 293 |
}) |
| 294 |
|
| 295 |
ctx := context.Background() |
| 296 |
opts := &ListOptions{Page: 1, PerPage: 1} |
| 297 |
groups, _, err := client.Enterprise.ListOrganizationAccessRunnerGroup(ctx, "o", 2, opts) |
| 298 |
if err != nil { |
| 299 |
t.Errorf("Enterprise.ListOrganizationAccessRunnerGroup returned error: %v", err) |
| 300 |
} |
| 301 |
|
| 302 |
want := &ListOrganizations{ |
| 303 |
TotalCount: Int(1), |
| 304 |
Organizations: []*Organization{ |
| 305 |
{ID: Int64(43), NodeID: String("MDEwOlJlcG9zaXRvcnkxMjk2MjY5"), Name: String("Hello-World"), Login: String("octocat")}, |
| 306 |
}, |
| 307 |
} |
| 308 |
if !cmp.Equal(groups, want) { |
| 309 |
t.Errorf("Enterprise.ListOrganizationAccessRunnerGroup returned %+v, want %+v", groups, want) |
| 310 |
} |
| 311 |
|
| 312 |
const methodName = "ListOrganizationAccessRunnerGroup" |
| 313 |
testBadOptions(t, methodName, func() (err error) { |
| 314 |
_, _, err = client.Enterprise.ListOrganizationAccessRunnerGroup(ctx, "\n", 2, opts) |
| 315 |
return err |
| 316 |
}) |
| 317 |
|
| 318 |
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { |
| 319 |
got, resp, err := client.Enterprise.ListOrganizationAccessRunnerGroup(ctx, "o", 2, opts) |
| 320 |
if got != nil { |
| 321 |
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) |
| 322 |
} |
| 323 |
return resp, err |
| 324 |
}) |
| 325 |
} |
| 326 |
|
| 327 |
func TestEnterpriseService_SetOrganizationAccessRunnerGroup(t *testing.T) { |
| 328 |
client, mux, _, teardown := setup() |
| 329 |
defer teardown() |
| 330 |
|
| 331 |
mux.HandleFunc("/enterprises/o/actions/runner-groups/2/organizations", func(w http.ResponseWriter, r *http.Request) { |
| 332 |
testMethod(t, r, "PUT") |
| 333 |
}) |
| 334 |
|
| 335 |
req := SetOrgAccessRunnerGroupRequest{ |
| 336 |
SelectedOrganizationIDs: []int64{ |
| 337 |
1, |
| 338 |
2, |
| 339 |
}, |
| 340 |
} |
| 341 |
|
| 342 |
ctx := context.Background() |
| 343 |
_, err := client.Enterprise.SetOrganizationAccessRunnerGroup(ctx, "o", 2, req) |
| 344 |
if err != nil { |
| 345 |
t.Errorf("Enterprise.SetOrganizationAccessRunnerGroup returned error: %v", err) |
| 346 |
} |
| 347 |
|
| 348 |
const methodName = "SetRepositoryAccessRunnerGroup" |
| 349 |
testBadOptions(t, methodName, func() (err error) { |
| 350 |
_, err = client.Enterprise.SetOrganizationAccessRunnerGroup(ctx, "\n", 2, req) |
| 351 |
return err |
| 352 |
}) |
| 353 |
|
| 354 |
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { |
| 355 |
return client.Enterprise.SetOrganizationAccessRunnerGroup(ctx, "o", 2, req) |
| 356 |
}) |
| 357 |
} |
| 358 |
|
| 359 |
func TestEnterpriseService_AddOrganizationAccessRunnerGroup(t *testing.T) { |
| 360 |
client, mux, _, teardown := setup() |
| 361 |
defer teardown() |
| 362 |
|
| 363 |
mux.HandleFunc("/enterprises/o/actions/runner-groups/2/organizations/42", func(w http.ResponseWriter, r *http.Request) { |
| 364 |
testMethod(t, r, "PUT") |
| 365 |
}) |
| 366 |
|
| 367 |
ctx := context.Background() |
| 368 |
_, err := client.Enterprise.AddOrganizationAccessRunnerGroup(ctx, "o", 2, 42) |
| 369 |
if err != nil { |
| 370 |
t.Errorf("Enterprise.AddOrganizationAccessRunnerGroup returned error: %v", err) |
| 371 |
} |
| 372 |
|
| 373 |
const methodName = "AddOrganizationAccessRunnerGroup" |
| 374 |
testBadOptions(t, methodName, func() (err error) { |
| 375 |
_, err = client.Enterprise.AddOrganizationAccessRunnerGroup(ctx, "\n", 2, 42) |
| 376 |
return err |
| 377 |
}) |
| 378 |
|
| 379 |
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { |
| 380 |
return client.Enterprise.AddOrganizationAccessRunnerGroup(ctx, "o", 2, 42) |
| 381 |
}) |
| 382 |
} |
| 383 |
|
| 384 |
func TestEnterpriseService_RemoveOrganizationAccessRunnerGroup(t *testing.T) { |
| 385 |
client, mux, _, teardown := setup() |
| 386 |
defer teardown() |
| 387 |
|
| 388 |
mux.HandleFunc("/enterprises/o/actions/runner-groups/2/organizations/42", func(w http.ResponseWriter, r *http.Request) { |
| 389 |
testMethod(t, r, "DELETE") |
| 390 |
}) |
| 391 |
|
| 392 |
ctx := context.Background() |
| 393 |
_, err := client.Enterprise.RemoveOrganizationAccessRunnerGroup(ctx, "o", 2, 42) |
| 394 |
if err != nil { |
| 395 |
t.Errorf("Enterprise.RemoveOrganizationAccessRunnerGroup returned error: %v", err) |
| 396 |
} |
| 397 |
|
| 398 |
const methodName = "RemoveOrganizationAccessRunnerGroup" |
| 399 |
testBadOptions(t, methodName, func() (err error) { |
| 400 |
_, err = client.Enterprise.RemoveOrganizationAccessRunnerGroup(ctx, "\n", 2, 42) |
| 401 |
return err |
| 402 |
}) |
| 403 |
|
| 404 |
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { |
| 405 |
return client.Enterprise.RemoveOrganizationAccessRunnerGroup(ctx, "o", 2, 42) |
| 406 |
}) |
| 407 |
} |
| 408 |
|
| 409 |
func TestEnterpriseService_ListEnterpriseRunnerGroupRunners(t *testing.T) { |
| 410 |
client, mux, _, teardown := setup() |
| 411 |
defer teardown() |
| 412 |
|
| 413 |
mux.HandleFunc("/enterprises/o/actions/runner-groups/2/runners", func(w http.ResponseWriter, r *http.Request) { |
| 414 |
testMethod(t, r, "GET") |
| 415 |
testFormValues(t, r, values{"per_page": "2", "page": "2"}) |
| 416 |
fmt.Fprint(w, `{"total_count":2,"runners":[{"id":23,"name":"MBP","os":"macos","status":"online"},{"id":24,"name":"iMac","os":"macos","status":"offline"}]}`) |
| 417 |
}) |
| 418 |
|
| 419 |
opts := &ListOptions{Page: 2, PerPage: 2} |
| 420 |
ctx := context.Background() |
| 421 |
runners, _, err := client.Enterprise.ListRunnerGroupRunners(ctx, "o", 2, opts) |
| 422 |
if err != nil { |
| 423 |
t.Errorf("Enterprise.ListEnterpriseRunnerGroupRunners returned error: %v", err) |
| 424 |
} |
| 425 |
|
| 426 |
want := &Runners{ |
| 427 |
TotalCount: 2, |
| 428 |
Runners: []*Runner{ |
| 429 |
{ID: Int64(23), Name: String("MBP"), OS: String("macos"), Status: String("online")}, |
| 430 |
{ID: Int64(24), Name: String("iMac"), OS: String("macos"), Status: String("offline")}, |
| 431 |
}, |
| 432 |
} |
| 433 |
if !cmp.Equal(runners, want) { |
| 434 |
t.Errorf("Enterprise.ListEnterpriseRunnerGroupRunners returned %+v, want %+v", runners, want) |
| 435 |
} |
| 436 |
|
| 437 |
const methodName = "ListEnterpriseRunnerGroupRunners" |
| 438 |
testBadOptions(t, methodName, func() (err error) { |
| 439 |
_, _, err = client.Enterprise.ListRunnerGroupRunners(ctx, "\n", 2, opts) |
| 440 |
return err |
| 441 |
}) |
| 442 |
|
| 443 |
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { |
| 444 |
got, resp, err := client.Enterprise.ListRunnerGroupRunners(ctx, "o", 2, opts) |
| 445 |
if got != nil { |
| 446 |
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) |
| 447 |
} |
| 448 |
return resp, err |
| 449 |
}) |
| 450 |
} |
| 451 |
|
| 452 |
func TestEnterpriseService_SetEnterpriseRunnerGroupRunners(t *testing.T) { |
| 453 |
client, mux, _, teardown := setup() |
| 454 |
defer teardown() |
| 455 |
|
| 456 |
mux.HandleFunc("/enterprises/o/actions/runner-groups/2/runners", func(w http.ResponseWriter, r *http.Request) { |
| 457 |
testMethod(t, r, "PUT") |
| 458 |
}) |
| 459 |
|
| 460 |
req := SetRunnerGroupRunnersRequest{ |
| 461 |
Runners: []int64{ |
| 462 |
1, |
| 463 |
2, |
| 464 |
}, |
| 465 |
} |
| 466 |
|
| 467 |
ctx := context.Background() |
| 468 |
_, err := client.Enterprise.SetRunnerGroupRunners(ctx, "o", 2, req) |
| 469 |
if err != nil { |
| 470 |
t.Errorf("Enterprise.SetEnterpriseRunnerGroupRunners returned error: %v", err) |
| 471 |
} |
| 472 |
|
| 473 |
const methodName = "SetEnterpriseRunnerGroupRunners" |
| 474 |
testBadOptions(t, methodName, func() (err error) { |
| 475 |
_, err = client.Enterprise.SetRunnerGroupRunners(ctx, "\n", 2, req) |
| 476 |
return err |
| 477 |
}) |
| 478 |
|
| 479 |
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { |
| 480 |
return client.Enterprise.SetRunnerGroupRunners(ctx, "o", 2, req) |
| 481 |
}) |
| 482 |
} |
| 483 |
|
| 484 |
func TestEnterpriseService_AddEnterpriseRunnerGroupRunners(t *testing.T) { |
| 485 |
client, mux, _, teardown := setup() |
| 486 |
defer teardown() |
| 487 |
|
| 488 |
mux.HandleFunc("/enterprises/o/actions/runner-groups/2/runners/42", func(w http.ResponseWriter, r *http.Request) { |
| 489 |
testMethod(t, r, "PUT") |
| 490 |
}) |
| 491 |
|
| 492 |
ctx := context.Background() |
| 493 |
_, err := client.Enterprise.AddRunnerGroupRunners(ctx, "o", 2, 42) |
| 494 |
if err != nil { |
| 495 |
t.Errorf("Enterprise.AddEnterpriseRunnerGroupRunners returned error: %v", err) |
| 496 |
} |
| 497 |
|
| 498 |
const methodName = "AddEnterpriseRunnerGroupRunners" |
| 499 |
testBadOptions(t, methodName, func() (err error) { |
| 500 |
_, err = client.Enterprise.AddRunnerGroupRunners(ctx, "\n", 2, 42) |
| 501 |
return err |
| 502 |
}) |
| 503 |
|
| 504 |
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { |
| 505 |
return client.Enterprise.AddRunnerGroupRunners(ctx, "o", 2, 42) |
| 506 |
}) |
| 507 |
} |
| 508 |
|
| 509 |
func TestEnterpriseService_RemoveEnterpriseRunnerGroupRunners(t *testing.T) { |
| 510 |
client, mux, _, teardown := setup() |
| 511 |
defer teardown() |
| 512 |
|
| 513 |
mux.HandleFunc("/enterprises/o/actions/runner-groups/2/runners/42", func(w http.ResponseWriter, r *http.Request) { |
| 514 |
testMethod(t, r, "DELETE") |
| 515 |
}) |
| 516 |
|
| 517 |
ctx := context.Background() |
| 518 |
_, err := client.Enterprise.RemoveRunnerGroupRunners(ctx, "o", 2, 42) |
| 519 |
if err != nil { |
| 520 |
t.Errorf("Enterprise.RemoveEnterpriseRunnerGroupRunners returned error: %v", err) |
| 521 |
} |
| 522 |
|
| 523 |
const methodName = "RemoveEnterpriseRunnerGroupRunners" |
| 524 |
testBadOptions(t, methodName, func() (err error) { |
| 525 |
_, err = client.Enterprise.RemoveRunnerGroupRunners(ctx, "\n", 2, 42) |
| 526 |
return err |
| 527 |
}) |
| 528 |
|
| 529 |
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { |
| 530 |
return client.Enterprise.RemoveRunnerGroupRunners(ctx, "o", 2, 42) |
| 531 |
}) |
| 532 |
} |
| 533 |
|
| 534 |
func TestEnterpriseRunnerGroup_Marshal(t *testing.T) { |
| 535 |
testJSONMarshal(t, &EnterpriseRunnerGroup{}, "{}") |
| 536 |
|
| 537 |
u := &EnterpriseRunnerGroup{ |
| 538 |
ID: Int64(1), |
| 539 |
Name: String("n"), |
| 540 |
Visibility: String("v"), |
| 541 |
Default: Bool(true), |
| 542 |
SelectedOrganizationsURL: String("s"), |
| 543 |
RunnersURL: String("r"), |
| 544 |
Inherited: Bool(true), |
| 545 |
AllowsPublicRepositories: Bool(true), |
| 546 |
RestrictedToWorkflows: Bool(false), |
| 547 |
SelectedWorkflows: []string{}, |
| 548 |
} |
| 549 |
|
| 550 |
want := `{ |
| 551 |
"id": 1, |
| 552 |
"name": "n", |
| 553 |
"visibility": "v", |
| 554 |
"default": true, |
| 555 |
"selected_organizations_url": "s", |
| 556 |
"runners_url": "r", |
| 557 |
"inherited": true, |
| 558 |
"allows_public_repositories": true, |
| 559 |
"restricted_to_workflows": false, |
| 560 |
"selected_workflows": [] |
| 561 |
}` |
| 562 |
|
| 563 |
testJSONMarshal(t, u, want) |
| 564 |
} |
| 565 |
|
| 566 |
func TestEnterpriseRunnerGroups_Marshal(t *testing.T) { |
| 567 |
testJSONMarshal(t, &EnterpriseRunnerGroups{}, "{}") |
| 568 |
|
| 569 |
u := &EnterpriseRunnerGroups{ |
| 570 |
TotalCount: Int(1), |
| 571 |
RunnerGroups: []*EnterpriseRunnerGroup{ |
| 572 |
{ |
| 573 |
ID: Int64(1), |
| 574 |
Name: String("n"), |
| 575 |
Visibility: String("v"), |
| 576 |
Default: Bool(true), |
| 577 |
SelectedOrganizationsURL: String("s"), |
| 578 |
RunnersURL: String("r"), |
| 579 |
Inherited: Bool(true), |
| 580 |
AllowsPublicRepositories: Bool(true), |
| 581 |
RestrictedToWorkflows: Bool(false), |
| 582 |
SelectedWorkflows: []string{}, |
| 583 |
}, |
| 584 |
}, |
| 585 |
} |
| 586 |
|
| 587 |
want := `{ |
| 588 |
"total_count": 1, |
| 589 |
"runner_groups": [{ |
| 590 |
"id": 1, |
| 591 |
"name": "n", |
| 592 |
"visibility": "v", |
| 593 |
"default": true, |
| 594 |
"selected_organizations_url": "s", |
| 595 |
"runners_url": "r", |
| 596 |
"inherited": true, |
| 597 |
"allows_public_repositories": true, |
| 598 |
"restricted_to_workflows": false, |
| 599 |
"selected_workflows": [] |
| 600 |
}] |
| 601 |
}` |
| 602 |
|
| 603 |
testJSONMarshal(t, u, want) |
| 604 |
} |
| 605 |
|
| 606 |
func TestCreateEnterpriseRunnerGroupRequest_Marshal(t *testing.T) { |
| 607 |
testJSONMarshal(t, &CreateEnterpriseRunnerGroupRequest{}, "{}") |
| 608 |
|
| 609 |
u := &CreateEnterpriseRunnerGroupRequest{ |
| 610 |
Name: String("n"), |
| 611 |
Visibility: String("v"), |
| 612 |
SelectedOrganizationIDs: []int64{1}, |
| 613 |
Runners: []int64{1}, |
| 614 |
AllowsPublicRepositories: Bool(true), |
| 615 |
RestrictedToWorkflows: Bool(true), |
| 616 |
SelectedWorkflows: []string{"a", "b"}, |
| 617 |
} |
| 618 |
|
| 619 |
want := `{ |
| 620 |
"name": "n", |
| 621 |
"visibility": "v", |
| 622 |
"selected_organization_ids": [1], |
| 623 |
"runners": [1], |
| 624 |
"allows_public_repositories": true, |
| 625 |
"restricted_to_workflows": true, |
| 626 |
"selected_workflows": ["a","b"] |
| 627 |
}` |
| 628 |
|
| 629 |
testJSONMarshal(t, u, want) |
| 630 |
} |
| 631 |
|
| 632 |
func TestUpdateEnterpriseRunnerGroupRequest_Marshal(t *testing.T) { |
| 633 |
testJSONMarshal(t, &UpdateEnterpriseRunnerGroupRequest{}, "{}") |
| 634 |
|
| 635 |
u := &UpdateEnterpriseRunnerGroupRequest{ |
| 636 |
Name: String("n"), |
| 637 |
Visibility: String("v"), |
| 638 |
AllowsPublicRepositories: Bool(true), |
| 639 |
RestrictedToWorkflows: Bool(false), |
| 640 |
SelectedWorkflows: []string{}, |
| 641 |
} |
| 642 |
|
| 643 |
want := `{ |
| 644 |
"name": "n", |
| 645 |
"visibility": "v", |
| 646 |
"allows_public_repositories": true, |
| 647 |
"restricted_to_workflows": false, |
| 648 |
"selected_workflows": [] |
| 649 |
}` |
| 650 |
|
| 651 |
testJSONMarshal(t, u, want) |
| 652 |
} |
| 653 |
|
| 654 |
func TestSetOrgAccessRunnerGroupRequest_Marshal(t *testing.T) { |
| 655 |
testJSONMarshal(t, &SetOrgAccessRunnerGroupRequest{}, "{}") |
| 656 |
|
| 657 |
u := &SetOrgAccessRunnerGroupRequest{ |
| 658 |
SelectedOrganizationIDs: []int64{1}, |
| 659 |
} |
| 660 |
|
| 661 |
want := `{ |
| 662 |
"selected_organization_ids": [1] |
| 663 |
}` |
| 664 |
|
| 665 |
testJSONMarshal(t, u, want) |
| 666 |
} |