github.com/google/go-github/v71@v71.0.0/github/enterprise_actions_runner_groups_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 "fmt" 11 "net/http" 12 "testing" 13 14 "github.com/google/go-cmp/cmp" 15 ) 16 17 func TestEnterpriseService_ListRunnerGroups(t *testing.T) { 18 t.Parallel() 19 client, mux, _ := setup(t) 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: Ptr(3), 36 RunnerGroups: []*EnterpriseRunnerGroup{ 37 {ID: Ptr(int64(1)), Name: Ptr("Default"), Visibility: Ptr("all"), Default: Ptr(true), RunnersURL: Ptr("https://api.github.com/enterprises/octo-enterprise/actions/runner_groups/1/runners"), Inherited: Ptr(false), AllowsPublicRepositories: Ptr(true), RestrictedToWorkflows: Ptr(true), SelectedWorkflows: []string{"a", "b"}}, 38 {ID: Ptr(int64(2)), Name: Ptr("octo-runner-group"), Visibility: Ptr("selected"), Default: Ptr(false), SelectedOrganizationsURL: Ptr("https://api.github.com/enterprises/octo-enterprise/actions/runner_groups/2/organizations"), RunnersURL: Ptr("https://api.github.com/enterprises/octo-enterprise/actions/runner_groups/2/runners"), Inherited: Ptr(true), AllowsPublicRepositories: Ptr(true), RestrictedToWorkflows: Ptr(false), SelectedWorkflows: []string{}}, 39 {ID: Ptr(int64(3)), Name: Ptr("expensive-hardware"), Visibility: Ptr("private"), Default: Ptr(false), RunnersURL: Ptr("https://api.github.com/enterprises/octo-enterprise/actions/runner_groups/3/runners"), Inherited: Ptr(false), AllowsPublicRepositories: Ptr(true), RestrictedToWorkflows: Ptr(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 t.Parallel() 63 client, mux, _ := setup(t) 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: Ptr(3), 80 RunnerGroups: []*EnterpriseRunnerGroup{ 81 {ID: Ptr(int64(1)), Name: Ptr("Default"), Visibility: Ptr("all"), Default: Ptr(true), RunnersURL: Ptr("https://api.github.com/enterprises/octo-enterprise/actions/runner_groups/1/runners"), Inherited: Ptr(false), AllowsPublicRepositories: Ptr(true), RestrictedToWorkflows: Ptr(false), SelectedWorkflows: []string{}}, 82 {ID: Ptr(int64(2)), Name: Ptr("octo-runner-group"), Visibility: Ptr("selected"), Default: Ptr(false), SelectedOrganizationsURL: Ptr("https://api.github.com/enterprises/octo-enterprise/actions/runner_groups/2/organizations"), RunnersURL: Ptr("https://api.github.com/enterprises/octo-enterprise/actions/runner_groups/2/runners"), Inherited: Ptr(true), AllowsPublicRepositories: Ptr(true), RestrictedToWorkflows: Ptr(false), SelectedWorkflows: []string{}}, 83 {ID: Ptr(int64(3)), Name: Ptr("expensive-hardware"), Visibility: Ptr("private"), Default: Ptr(false), RunnersURL: Ptr("https://api.github.com/enterprises/octo-enterprise/actions/runner_groups/3/runners"), Inherited: Ptr(false), AllowsPublicRepositories: Ptr(true), RestrictedToWorkflows: Ptr(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 t.Parallel() 107 client, mux, _ := setup(t) 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: Ptr(int64(2)), 122 Name: Ptr("octo-runner-group"), 123 Visibility: Ptr("selected"), 124 Default: Ptr(false), 125 SelectedOrganizationsURL: Ptr("https://api.github.com/enterprises/octo-enterprise/actions/runner_groups/2/organizations"), 126 RunnersURL: Ptr("https://api.github.com/enterprises/octo-enterprise/actions/runner_groups/2/runners"), 127 Inherited: Ptr(false), 128 AllowsPublicRepositories: Ptr(true), 129 RestrictedToWorkflows: Ptr(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 t.Parallel() 154 client, mux, _ := setup(t) 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 t.Parallel() 179 client, mux, _ := setup(t) 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: Ptr("octo-runner-group"), 189 Visibility: Ptr("selected"), 190 AllowsPublicRepositories: Ptr(true), 191 RestrictedToWorkflows: Ptr(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: Ptr(int64(2)), 201 Name: Ptr("octo-runner-group"), 202 Visibility: Ptr("selected"), 203 Default: Ptr(false), 204 SelectedOrganizationsURL: Ptr("https://api.github.com/enterprises/octo-enterprise/actions/runner_groups/2/organizations"), 205 RunnersURL: Ptr("https://api.github.com/enterprises/octo-enterprise/actions/runner_groups/2/runners"), 206 Inherited: Ptr(false), 207 AllowsPublicRepositories: Ptr(true), 208 RestrictedToWorkflows: Ptr(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 t.Parallel() 233 client, mux, _ := setup(t) 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: Ptr("octo-runner-group"), 243 Visibility: Ptr("selected"), 244 AllowsPublicRepositories: Ptr(true), 245 RestrictedToWorkflows: Ptr(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: Ptr(int64(2)), 255 Name: Ptr("octo-runner-group"), 256 Visibility: Ptr("selected"), 257 Default: Ptr(false), 258 SelectedOrganizationsURL: Ptr("https://api.github.com/enterprises/octo-enterprise/actions/runner_groups/2/organizations"), 259 RunnersURL: Ptr("https://api.github.com/enterprises/octo-enterprise/actions/runner_groups/2/runners"), 260 Inherited: Ptr(false), 261 AllowsPublicRepositories: Ptr(true), 262 RestrictedToWorkflows: Ptr(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 t.Parallel() 287 client, mux, _ := setup(t) 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: Ptr(1), 304 Organizations: []*Organization{ 305 {ID: Ptr(int64(43)), NodeID: Ptr("MDEwOlJlcG9zaXRvcnkxMjk2MjY5"), Name: Ptr("Hello-World"), Login: Ptr("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 t.Parallel() 329 client, mux, _ := setup(t) 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 t.Parallel() 361 client, mux, _ := setup(t) 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 t.Parallel() 386 client, mux, _ := setup(t) 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 t.Parallel() 411 client, mux, _ := setup(t) 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: Ptr(int64(23)), Name: Ptr("MBP"), OS: Ptr("macos"), Status: Ptr("online")}, 430 {ID: Ptr(int64(24)), Name: Ptr("iMac"), OS: Ptr("macos"), Status: Ptr("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 t.Parallel() 454 client, mux, _ := setup(t) 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 t.Parallel() 486 client, mux, _ := setup(t) 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 t.Parallel() 511 client, mux, _ := setup(t) 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 t.Parallel() 536 testJSONMarshal(t, &EnterpriseRunnerGroup{}, "{}") 537 538 u := &EnterpriseRunnerGroup{ 539 ID: Ptr(int64(1)), 540 Name: Ptr("n"), 541 Visibility: Ptr("v"), 542 Default: Ptr(true), 543 SelectedOrganizationsURL: Ptr("s"), 544 RunnersURL: Ptr("r"), 545 Inherited: Ptr(true), 546 AllowsPublicRepositories: Ptr(true), 547 RestrictedToWorkflows: Ptr(false), 548 SelectedWorkflows: []string{}, 549 } 550 551 want := `{ 552 "id": 1, 553 "name": "n", 554 "visibility": "v", 555 "default": true, 556 "selected_organizations_url": "s", 557 "runners_url": "r", 558 "inherited": true, 559 "allows_public_repositories": true, 560 "restricted_to_workflows": false, 561 "selected_workflows": [] 562 }` 563 564 testJSONMarshal(t, u, want) 565 } 566 567 func TestEnterpriseRunnerGroups_Marshal(t *testing.T) { 568 t.Parallel() 569 testJSONMarshal(t, &EnterpriseRunnerGroups{}, "{}") 570 571 u := &EnterpriseRunnerGroups{ 572 TotalCount: Ptr(1), 573 RunnerGroups: []*EnterpriseRunnerGroup{ 574 { 575 ID: Ptr(int64(1)), 576 Name: Ptr("n"), 577 Visibility: Ptr("v"), 578 Default: Ptr(true), 579 SelectedOrganizationsURL: Ptr("s"), 580 RunnersURL: Ptr("r"), 581 Inherited: Ptr(true), 582 AllowsPublicRepositories: Ptr(true), 583 RestrictedToWorkflows: Ptr(false), 584 SelectedWorkflows: []string{}, 585 }, 586 }, 587 } 588 589 want := `{ 590 "total_count": 1, 591 "runner_groups": [{ 592 "id": 1, 593 "name": "n", 594 "visibility": "v", 595 "default": true, 596 "selected_organizations_url": "s", 597 "runners_url": "r", 598 "inherited": true, 599 "allows_public_repositories": true, 600 "restricted_to_workflows": false, 601 "selected_workflows": [] 602 }] 603 }` 604 605 testJSONMarshal(t, u, want) 606 } 607 608 func TestCreateEnterpriseRunnerGroupRequest_Marshal(t *testing.T) { 609 t.Parallel() 610 testJSONMarshal(t, &CreateEnterpriseRunnerGroupRequest{}, "{}") 611 612 u := &CreateEnterpriseRunnerGroupRequest{ 613 Name: Ptr("n"), 614 Visibility: Ptr("v"), 615 SelectedOrganizationIDs: []int64{1}, 616 Runners: []int64{1}, 617 AllowsPublicRepositories: Ptr(true), 618 RestrictedToWorkflows: Ptr(true), 619 SelectedWorkflows: []string{"a", "b"}, 620 } 621 622 want := `{ 623 "name": "n", 624 "visibility": "v", 625 "selected_organization_ids": [1], 626 "runners": [1], 627 "allows_public_repositories": true, 628 "restricted_to_workflows": true, 629 "selected_workflows": ["a","b"] 630 }` 631 632 testJSONMarshal(t, u, want) 633 } 634 635 func TestUpdateEnterpriseRunnerGroupRequest_Marshal(t *testing.T) { 636 t.Parallel() 637 testJSONMarshal(t, &UpdateEnterpriseRunnerGroupRequest{}, "{}") 638 639 u := &UpdateEnterpriseRunnerGroupRequest{ 640 Name: Ptr("n"), 641 Visibility: Ptr("v"), 642 AllowsPublicRepositories: Ptr(true), 643 RestrictedToWorkflows: Ptr(false), 644 SelectedWorkflows: []string{}, 645 } 646 647 want := `{ 648 "name": "n", 649 "visibility": "v", 650 "allows_public_repositories": true, 651 "restricted_to_workflows": false, 652 "selected_workflows": [] 653 }` 654 655 testJSONMarshal(t, u, want) 656 } 657 658 func TestSetOrgAccessRunnerGroupRequest_Marshal(t *testing.T) { 659 t.Parallel() 660 testJSONMarshal(t, &SetOrgAccessRunnerGroupRequest{}, "{}") 661 662 u := &SetOrgAccessRunnerGroupRequest{ 663 SelectedOrganizationIDs: []int64{1}, 664 } 665 666 want := `{ 667 "selected_organization_ids": [1] 668 }` 669 670 testJSONMarshal(t, u, want) 671 }