github.com/google/go-github/v68@v68.0.0/github/actions_runners_test.go (about) 1 // Copyright 2020 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 "time" 15 16 "github.com/google/go-cmp/cmp" 17 ) 18 19 func TestActionsService_ListRunnerApplicationDownloads(t *testing.T) { 20 t.Parallel() 21 client, mux, _ := setup(t) 22 23 mux.HandleFunc("/repos/o/r/actions/runners/downloads", func(w http.ResponseWriter, r *http.Request) { 24 testMethod(t, r, "GET") 25 fmt.Fprint(w, `[{"os":"osx","architecture":"x64","download_url":"https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-osx-x64-2.164.0.tar.gz","filename":"actions-runner-osx-x64-2.164.0.tar.gz"},{"os":"linux","architecture":"x64","download_url":"https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-linux-x64-2.164.0.tar.gz","filename":"actions-runner-linux-x64-2.164.0.tar.gz"},{"os": "linux","architecture":"arm","download_url":"https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-linux-arm-2.164.0.tar.gz","filename":"actions-runner-linux-arm-2.164.0.tar.gz"},{"os":"win","architecture":"x64","download_url":"https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-win-x64-2.164.0.zip","filename":"actions-runner-win-x64-2.164.0.zip"},{"os":"linux","architecture":"arm64","download_url":"https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-linux-arm64-2.164.0.tar.gz","filename":"actions-runner-linux-arm64-2.164.0.tar.gz"}]`) 26 }) 27 28 ctx := context.Background() 29 downloads, _, err := client.Actions.ListRunnerApplicationDownloads(ctx, "o", "r") 30 if err != nil { 31 t.Errorf("Actions.ListRunnerApplicationDownloads returned error: %v", err) 32 } 33 34 want := []*RunnerApplicationDownload{ 35 {OS: Ptr("osx"), Architecture: Ptr("x64"), DownloadURL: Ptr("https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-osx-x64-2.164.0.tar.gz"), Filename: Ptr("actions-runner-osx-x64-2.164.0.tar.gz")}, 36 {OS: Ptr("linux"), Architecture: Ptr("x64"), DownloadURL: Ptr("https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-linux-x64-2.164.0.tar.gz"), Filename: Ptr("actions-runner-linux-x64-2.164.0.tar.gz")}, 37 {OS: Ptr("linux"), Architecture: Ptr("arm"), DownloadURL: Ptr("https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-linux-arm-2.164.0.tar.gz"), Filename: Ptr("actions-runner-linux-arm-2.164.0.tar.gz")}, 38 {OS: Ptr("win"), Architecture: Ptr("x64"), DownloadURL: Ptr("https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-win-x64-2.164.0.zip"), Filename: Ptr("actions-runner-win-x64-2.164.0.zip")}, 39 {OS: Ptr("linux"), Architecture: Ptr("arm64"), DownloadURL: Ptr("https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-linux-arm64-2.164.0.tar.gz"), Filename: Ptr("actions-runner-linux-arm64-2.164.0.tar.gz")}, 40 } 41 if !cmp.Equal(downloads, want) { 42 t.Errorf("Actions.ListRunnerApplicationDownloads returned %+v, want %+v", downloads, want) 43 } 44 45 const methodName = "ListRunnerApplicationDownloads" 46 testBadOptions(t, methodName, func() (err error) { 47 _, _, err = client.Actions.ListRunnerApplicationDownloads(ctx, "\n", "\n") 48 return err 49 }) 50 51 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 52 got, resp, err := client.Actions.ListRunnerApplicationDownloads(ctx, "o", "r") 53 if got != nil { 54 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) 55 } 56 return resp, err 57 }) 58 } 59 60 func TestActionsService_GenerateOrgJITConfig(t *testing.T) { 61 t.Parallel() 62 client, mux, _ := setup(t) 63 64 input := &GenerateJITConfigRequest{Name: "test", RunnerGroupID: 1, Labels: []string{"one", "two"}} 65 66 mux.HandleFunc("/orgs/o/actions/runners/generate-jitconfig", func(w http.ResponseWriter, r *http.Request) { 67 v := new(GenerateJITConfigRequest) 68 assertNilError(t, json.NewDecoder(r.Body).Decode(v)) 69 70 testMethod(t, r, "POST") 71 if !cmp.Equal(v, input) { 72 t.Errorf("Request body = %+v, want %+v", v, input) 73 } 74 75 fmt.Fprint(w, `{"encoded_jit_config":"foo"}`) 76 }) 77 78 ctx := context.Background() 79 jitConfig, _, err := client.Actions.GenerateOrgJITConfig(ctx, "o", input) 80 if err != nil { 81 t.Errorf("Actions.GenerateOrgJITConfig returned error: %v", err) 82 } 83 84 want := &JITRunnerConfig{EncodedJITConfig: Ptr("foo")} 85 if !cmp.Equal(jitConfig, want) { 86 t.Errorf("Actions.GenerateOrgJITConfig returned %+v, want %+v", jitConfig, want) 87 } 88 89 const methodName = "GenerateOrgJITConfig" 90 testBadOptions(t, methodName, func() (err error) { 91 _, _, err = client.Actions.GenerateOrgJITConfig(ctx, "\n", input) 92 return err 93 }) 94 95 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 96 got, resp, err := client.Actions.GenerateOrgJITConfig(ctx, "o", input) 97 if got != nil { 98 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) 99 } 100 return resp, err 101 }) 102 } 103 104 func TestActionsService_GenerateRepoJITConfig(t *testing.T) { 105 t.Parallel() 106 client, mux, _ := setup(t) 107 108 input := &GenerateJITConfigRequest{Name: "test", RunnerGroupID: 1, Labels: []string{"one", "two"}} 109 110 mux.HandleFunc("/repos/o/r/actions/runners/generate-jitconfig", func(w http.ResponseWriter, r *http.Request) { 111 v := new(GenerateJITConfigRequest) 112 assertNilError(t, json.NewDecoder(r.Body).Decode(v)) 113 114 testMethod(t, r, "POST") 115 if !cmp.Equal(v, input) { 116 t.Errorf("Request body = %+v, want %+v", v, input) 117 } 118 119 fmt.Fprint(w, `{"encoded_jit_config":"foo"}`) 120 }) 121 122 ctx := context.Background() 123 jitConfig, _, err := client.Actions.GenerateRepoJITConfig(ctx, "o", "r", input) 124 if err != nil { 125 t.Errorf("Actions.GenerateRepoJITConfig returned error: %v", err) 126 } 127 128 want := &JITRunnerConfig{EncodedJITConfig: Ptr("foo")} 129 if !cmp.Equal(jitConfig, want) { 130 t.Errorf("Actions.GenerateRepoJITConfig returned %+v, want %+v", jitConfig, want) 131 } 132 133 const methodName = "GenerateRepoJITConfig" 134 testBadOptions(t, methodName, func() (err error) { 135 _, _, err = client.Actions.GenerateRepoJITConfig(ctx, "\n", "\n", input) 136 return err 137 }) 138 139 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 140 got, resp, err := client.Actions.GenerateRepoJITConfig(ctx, "o", "r", input) 141 if got != nil { 142 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) 143 } 144 return resp, err 145 }) 146 } 147 148 func TestActionsService_CreateRegistrationToken(t *testing.T) { 149 t.Parallel() 150 client, mux, _ := setup(t) 151 152 mux.HandleFunc("/repos/o/r/actions/runners/registration-token", func(w http.ResponseWriter, r *http.Request) { 153 testMethod(t, r, "POST") 154 fmt.Fprint(w, `{"token":"LLBF3JGZDX3P5PMEXLND6TS6FCWO6","expires_at":"2020-01-22T12:13:35.123Z"}`) 155 }) 156 157 ctx := context.Background() 158 token, _, err := client.Actions.CreateRegistrationToken(ctx, "o", "r") 159 if err != nil { 160 t.Errorf("Actions.CreateRegistrationToken returned error: %v", err) 161 } 162 163 want := &RegistrationToken{Token: Ptr("LLBF3JGZDX3P5PMEXLND6TS6FCWO6"), 164 ExpiresAt: &Timestamp{time.Date(2020, time.January, 22, 12, 13, 35, 165 123000000, time.UTC)}} 166 if !cmp.Equal(token, want) { 167 t.Errorf("Actions.CreateRegistrationToken returned %+v, want %+v", token, want) 168 } 169 170 const methodName = "CreateRegistrationToken" 171 testBadOptions(t, methodName, func() (err error) { 172 _, _, err = client.Actions.CreateRegistrationToken(ctx, "\n", "\n") 173 return err 174 }) 175 176 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 177 got, resp, err := client.Actions.CreateRegistrationToken(ctx, "o", "r") 178 if got != nil { 179 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) 180 } 181 return resp, err 182 }) 183 } 184 185 func TestActionsService_ListRunners(t *testing.T) { 186 t.Parallel() 187 client, mux, _ := setup(t) 188 189 mux.HandleFunc("/repos/o/r/actions/runners", func(w http.ResponseWriter, r *http.Request) { 190 testMethod(t, r, "GET") 191 testFormValues(t, r, values{"name": "MBP", "per_page": "2", "page": "2"}) 192 fmt.Fprint(w, `{"total_count":1,"runners":[{"id":23,"name":"MBP","os":"macos","status":"online"}]}`) 193 }) 194 195 opts := &ListRunnersOptions{ 196 Name: Ptr("MBP"), 197 ListOptions: ListOptions{Page: 2, PerPage: 2}, 198 } 199 ctx := context.Background() 200 runners, _, err := client.Actions.ListRunners(ctx, "o", "r", opts) 201 if err != nil { 202 t.Errorf("Actions.ListRunners returned error: %v", err) 203 } 204 205 want := &Runners{ 206 TotalCount: 1, 207 Runners: []*Runner{ 208 {ID: Ptr(int64(23)), Name: Ptr("MBP"), OS: Ptr("macos"), Status: Ptr("online")}, 209 }, 210 } 211 if !cmp.Equal(runners, want) { 212 t.Errorf("Actions.ListRunners returned %+v, want %+v", runners, want) 213 } 214 215 const methodName = "ListRunners" 216 testBadOptions(t, methodName, func() (err error) { 217 _, _, err = client.Actions.ListRunners(ctx, "\n", "\n", opts) 218 return err 219 }) 220 221 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 222 got, resp, err := client.Actions.ListRunners(ctx, "o", "r", opts) 223 if got != nil { 224 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) 225 } 226 return resp, err 227 }) 228 } 229 230 func TestActionsService_GetRunner(t *testing.T) { 231 t.Parallel() 232 client, mux, _ := setup(t) 233 234 mux.HandleFunc("/repos/o/r/actions/runners/23", func(w http.ResponseWriter, r *http.Request) { 235 testMethod(t, r, "GET") 236 fmt.Fprint(w, `{"id":23,"name":"MBP","os":"macos","status":"online"}`) 237 }) 238 239 ctx := context.Background() 240 runner, _, err := client.Actions.GetRunner(ctx, "o", "r", 23) 241 if err != nil { 242 t.Errorf("Actions.GetRunner returned error: %v", err) 243 } 244 245 want := &Runner{ 246 ID: Ptr(int64(23)), 247 Name: Ptr("MBP"), 248 OS: Ptr("macos"), 249 Status: Ptr("online"), 250 } 251 if !cmp.Equal(runner, want) { 252 t.Errorf("Actions.GetRunner returned %+v, want %+v", runner, want) 253 } 254 255 const methodName = "GetRunner" 256 testBadOptions(t, methodName, func() (err error) { 257 _, _, err = client.Actions.GetRunner(ctx, "\n", "\n", 23) 258 return err 259 }) 260 261 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 262 got, resp, err := client.Actions.GetRunner(ctx, "o", "r", 23) 263 if got != nil { 264 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) 265 } 266 return resp, err 267 }) 268 } 269 270 func TestActionsService_CreateRemoveToken(t *testing.T) { 271 t.Parallel() 272 client, mux, _ := setup(t) 273 274 mux.HandleFunc("/repos/o/r/actions/runners/remove-token", func(w http.ResponseWriter, r *http.Request) { 275 testMethod(t, r, "POST") 276 fmt.Fprint(w, `{"token":"AABF3JGZDX3P5PMEXLND6TS6FCWO6","expires_at":"2020-01-29T12:13:35.123Z"}`) 277 }) 278 279 ctx := context.Background() 280 token, _, err := client.Actions.CreateRemoveToken(ctx, "o", "r") 281 if err != nil { 282 t.Errorf("Actions.CreateRemoveToken returned error: %v", err) 283 } 284 285 want := &RemoveToken{Token: Ptr("AABF3JGZDX3P5PMEXLND6TS6FCWO6"), ExpiresAt: &Timestamp{time.Date(2020, time.January, 29, 12, 13, 35, 123000000, time.UTC)}} 286 if !cmp.Equal(token, want) { 287 t.Errorf("Actions.CreateRemoveToken returned %+v, want %+v", token, want) 288 } 289 290 const methodName = "CreateRemoveToken" 291 testBadOptions(t, methodName, func() (err error) { 292 _, _, err = client.Actions.CreateRemoveToken(ctx, "\n", "\n") 293 return err 294 }) 295 296 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 297 got, resp, err := client.Actions.CreateRemoveToken(ctx, "o", "r") 298 if got != nil { 299 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) 300 } 301 return resp, err 302 }) 303 } 304 305 func TestActionsService_RemoveRunner(t *testing.T) { 306 t.Parallel() 307 client, mux, _ := setup(t) 308 309 mux.HandleFunc("/repos/o/r/actions/runners/21", func(w http.ResponseWriter, r *http.Request) { 310 testMethod(t, r, "DELETE") 311 }) 312 313 ctx := context.Background() 314 _, err := client.Actions.RemoveRunner(ctx, "o", "r", 21) 315 if err != nil { 316 t.Errorf("Actions.RemoveRunner returned error: %v", err) 317 } 318 319 const methodName = "RemoveRunner" 320 testBadOptions(t, methodName, func() (err error) { 321 _, err = client.Actions.RemoveRunner(ctx, "\n", "\n", 21) 322 return err 323 }) 324 325 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 326 return client.Actions.RemoveRunner(ctx, "o", "r", 21) 327 }) 328 } 329 330 func TestActionsService_ListOrganizationRunnerApplicationDownloads(t *testing.T) { 331 t.Parallel() 332 client, mux, _ := setup(t) 333 334 mux.HandleFunc("/orgs/o/actions/runners/downloads", func(w http.ResponseWriter, r *http.Request) { 335 testMethod(t, r, "GET") 336 fmt.Fprint(w, `[{"os":"osx","architecture":"x64","download_url":"https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-osx-x64-2.164.0.tar.gz","filename":"actions-runner-osx-x64-2.164.0.tar.gz"},{"os":"linux","architecture":"x64","download_url":"https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-linux-x64-2.164.0.tar.gz","filename":"actions-runner-linux-x64-2.164.0.tar.gz"},{"os": "linux","architecture":"arm","download_url":"https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-linux-arm-2.164.0.tar.gz","filename":"actions-runner-linux-arm-2.164.0.tar.gz"},{"os":"win","architecture":"x64","download_url":"https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-win-x64-2.164.0.zip","filename":"actions-runner-win-x64-2.164.0.zip"},{"os":"linux","architecture":"arm64","download_url":"https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-linux-arm64-2.164.0.tar.gz","filename":"actions-runner-linux-arm64-2.164.0.tar.gz"}]`) 337 }) 338 339 ctx := context.Background() 340 downloads, _, err := client.Actions.ListOrganizationRunnerApplicationDownloads(ctx, "o") 341 if err != nil { 342 t.Errorf("Actions.ListRunnerApplicationDownloads returned error: %v", err) 343 } 344 345 want := []*RunnerApplicationDownload{ 346 {OS: Ptr("osx"), Architecture: Ptr("x64"), DownloadURL: Ptr("https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-osx-x64-2.164.0.tar.gz"), Filename: Ptr("actions-runner-osx-x64-2.164.0.tar.gz")}, 347 {OS: Ptr("linux"), Architecture: Ptr("x64"), DownloadURL: Ptr("https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-linux-x64-2.164.0.tar.gz"), Filename: Ptr("actions-runner-linux-x64-2.164.0.tar.gz")}, 348 {OS: Ptr("linux"), Architecture: Ptr("arm"), DownloadURL: Ptr("https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-linux-arm-2.164.0.tar.gz"), Filename: Ptr("actions-runner-linux-arm-2.164.0.tar.gz")}, 349 {OS: Ptr("win"), Architecture: Ptr("x64"), DownloadURL: Ptr("https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-win-x64-2.164.0.zip"), Filename: Ptr("actions-runner-win-x64-2.164.0.zip")}, 350 {OS: Ptr("linux"), Architecture: Ptr("arm64"), DownloadURL: Ptr("https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-linux-arm64-2.164.0.tar.gz"), Filename: Ptr("actions-runner-linux-arm64-2.164.0.tar.gz")}, 351 } 352 if !cmp.Equal(downloads, want) { 353 t.Errorf("Actions.ListOrganizationRunnerApplicationDownloads returned %+v, want %+v", downloads, want) 354 } 355 356 const methodName = "ListOrganizationRunnerApplicationDownloads" 357 testBadOptions(t, methodName, func() (err error) { 358 _, _, err = client.Actions.ListOrganizationRunnerApplicationDownloads(ctx, "\n") 359 return err 360 }) 361 362 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 363 got, resp, err := client.Actions.ListOrganizationRunnerApplicationDownloads(ctx, "o") 364 if got != nil { 365 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) 366 } 367 return resp, err 368 }) 369 } 370 371 func TestActionsService_CreateOrganizationRegistrationToken(t *testing.T) { 372 t.Parallel() 373 client, mux, _ := setup(t) 374 375 mux.HandleFunc("/orgs/o/actions/runners/registration-token", func(w http.ResponseWriter, r *http.Request) { 376 testMethod(t, r, "POST") 377 fmt.Fprint(w, `{"token":"LLBF3JGZDX3P5PMEXLND6TS6FCWO6","expires_at":"2020-01-22T12:13:35.123Z"}`) 378 }) 379 380 ctx := context.Background() 381 token, _, err := client.Actions.CreateOrganizationRegistrationToken(ctx, "o") 382 if err != nil { 383 t.Errorf("Actions.CreateRegistrationToken returned error: %v", err) 384 } 385 386 want := &RegistrationToken{Token: Ptr("LLBF3JGZDX3P5PMEXLND6TS6FCWO6"), 387 ExpiresAt: &Timestamp{time.Date(2020, time.January, 22, 12, 13, 35, 388 123000000, time.UTC)}} 389 if !cmp.Equal(token, want) { 390 t.Errorf("Actions.CreateRegistrationToken returned %+v, want %+v", token, want) 391 } 392 393 const methodName = "CreateOrganizationRegistrationToken" 394 testBadOptions(t, methodName, func() (err error) { 395 _, _, err = client.Actions.CreateOrganizationRegistrationToken(ctx, "\n") 396 return err 397 }) 398 399 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 400 got, resp, err := client.Actions.CreateOrganizationRegistrationToken(ctx, "o") 401 if got != nil { 402 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) 403 } 404 return resp, err 405 }) 406 } 407 408 func TestActionsService_ListOrganizationRunners(t *testing.T) { 409 t.Parallel() 410 client, mux, _ := setup(t) 411 412 mux.HandleFunc("/orgs/o/actions/runners", func(w http.ResponseWriter, r *http.Request) { 413 testMethod(t, r, "GET") 414 testFormValues(t, r, values{"per_page": "2", "page": "2"}) 415 fmt.Fprint(w, `{"total_count":2,"runners":[{"id":23,"name":"MBP","os":"macos","status":"online"},{"id":24,"name":"iMac","os":"macos","status":"offline"}]}`) 416 }) 417 418 opts := &ListRunnersOptions{ 419 ListOptions: ListOptions{Page: 2, PerPage: 2}, 420 } 421 ctx := context.Background() 422 runners, _, err := client.Actions.ListOrganizationRunners(ctx, "o", opts) 423 if err != nil { 424 t.Errorf("Actions.ListRunners returned error: %v", err) 425 } 426 427 want := &Runners{ 428 TotalCount: 2, 429 Runners: []*Runner{ 430 {ID: Ptr(int64(23)), Name: Ptr("MBP"), OS: Ptr("macos"), Status: Ptr("online")}, 431 {ID: Ptr(int64(24)), Name: Ptr("iMac"), OS: Ptr("macos"), Status: Ptr("offline")}, 432 }, 433 } 434 if !cmp.Equal(runners, want) { 435 t.Errorf("Actions.ListRunners returned %+v, want %+v", runners, want) 436 } 437 438 const methodName = "ListOrganizationRunners" 439 testBadOptions(t, methodName, func() (err error) { 440 _, _, err = client.Actions.ListOrganizationRunners(ctx, "\n", opts) 441 return err 442 }) 443 444 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 445 got, resp, err := client.Actions.ListOrganizationRunners(ctx, "o", opts) 446 if got != nil { 447 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) 448 } 449 return resp, err 450 }) 451 } 452 453 func TestActionsService_GetOrganizationRunner(t *testing.T) { 454 t.Parallel() 455 client, mux, _ := setup(t) 456 457 mux.HandleFunc("/orgs/o/actions/runners/23", func(w http.ResponseWriter, r *http.Request) { 458 testMethod(t, r, "GET") 459 fmt.Fprint(w, `{"id":23,"name":"MBP","os":"macos","status":"online"}`) 460 }) 461 462 ctx := context.Background() 463 runner, _, err := client.Actions.GetOrganizationRunner(ctx, "o", 23) 464 if err != nil { 465 t.Errorf("Actions.GetRunner returned error: %v", err) 466 } 467 468 want := &Runner{ 469 ID: Ptr(int64(23)), 470 Name: Ptr("MBP"), 471 OS: Ptr("macos"), 472 Status: Ptr("online"), 473 } 474 if !cmp.Equal(runner, want) { 475 t.Errorf("Actions.GetRunner returned %+v, want %+v", runner, want) 476 } 477 478 const methodName = "GetOrganizationRunner" 479 testBadOptions(t, methodName, func() (err error) { 480 _, _, err = client.Actions.GetOrganizationRunner(ctx, "\n", 23) 481 return err 482 }) 483 484 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 485 got, resp, err := client.Actions.GetOrganizationRunner(ctx, "o", 23) 486 if got != nil { 487 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) 488 } 489 return resp, err 490 }) 491 } 492 493 func TestActionsService_CreateOrganizationRemoveToken(t *testing.T) { 494 t.Parallel() 495 client, mux, _ := setup(t) 496 497 mux.HandleFunc("/orgs/o/actions/runners/remove-token", func(w http.ResponseWriter, r *http.Request) { 498 testMethod(t, r, "POST") 499 fmt.Fprint(w, `{"token":"AABF3JGZDX3P5PMEXLND6TS6FCWO6","expires_at":"2020-01-29T12:13:35.123Z"}`) 500 }) 501 502 ctx := context.Background() 503 token, _, err := client.Actions.CreateOrganizationRemoveToken(ctx, "o") 504 if err != nil { 505 t.Errorf("Actions.CreateRemoveToken returned error: %v", err) 506 } 507 508 want := &RemoveToken{Token: Ptr("AABF3JGZDX3P5PMEXLND6TS6FCWO6"), ExpiresAt: &Timestamp{time.Date(2020, time.January, 29, 12, 13, 35, 123000000, time.UTC)}} 509 if !cmp.Equal(token, want) { 510 t.Errorf("Actions.CreateRemoveToken returned %+v, want %+v", token, want) 511 } 512 513 const methodName = "CreateOrganizationRemoveToken" 514 testBadOptions(t, methodName, func() (err error) { 515 _, _, err = client.Actions.CreateOrganizationRemoveToken(ctx, "\n") 516 return err 517 }) 518 519 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 520 got, resp, err := client.Actions.CreateOrganizationRemoveToken(ctx, "o") 521 if got != nil { 522 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) 523 } 524 return resp, err 525 }) 526 } 527 528 func TestActionsService_RemoveOrganizationRunner(t *testing.T) { 529 t.Parallel() 530 client, mux, _ := setup(t) 531 532 mux.HandleFunc("/orgs/o/actions/runners/21", func(w http.ResponseWriter, r *http.Request) { 533 testMethod(t, r, "DELETE") 534 }) 535 536 ctx := context.Background() 537 _, err := client.Actions.RemoveOrganizationRunner(ctx, "o", 21) 538 if err != nil { 539 t.Errorf("Actions.RemoveOrganizationRunner returned error: %v", err) 540 } 541 542 const methodName = "RemoveOrganizationRunner" 543 testBadOptions(t, methodName, func() (err error) { 544 _, err = client.Actions.RemoveOrganizationRunner(ctx, "\n", 21) 545 return err 546 }) 547 548 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 549 return client.Actions.RemoveOrganizationRunner(ctx, "o", 21) 550 }) 551 } 552 553 func TestRunnerApplicationDownload_Marshal(t *testing.T) { 554 t.Parallel() 555 testJSONMarshal(t, &RunnerApplicationDownload{}, "{}") 556 557 u := &RunnerApplicationDownload{ 558 OS: Ptr("o"), 559 Architecture: Ptr("a"), 560 DownloadURL: Ptr("d"), 561 Filename: Ptr("f"), 562 TempDownloadToken: Ptr("t"), 563 SHA256Checksum: Ptr("s"), 564 } 565 566 want := `{ 567 "os": "o", 568 "architecture": "a", 569 "download_url": "d", 570 "filename": "f", 571 "temp_download_token": "t", 572 "sha256_checksum": "s" 573 }` 574 575 testJSONMarshal(t, u, want) 576 } 577 578 func TestActionsEnabledOnOrgRepos_Marshal(t *testing.T) { 579 t.Parallel() 580 testJSONMarshal(t, &ActionsEnabledOnOrgRepos{}, "{}") 581 582 u := &ActionsEnabledOnOrgRepos{ 583 TotalCount: 1, 584 Repositories: []*Repository{ 585 { 586 ID: Ptr(int64(1)), 587 URL: Ptr("u"), 588 Name: Ptr("n"), 589 }, 590 }, 591 } 592 593 want := `{ 594 "total_count": 1, 595 "repositories": [ 596 { 597 "id": 1, 598 "url": "u", 599 "name": "n" 600 } 601 ] 602 }` 603 604 testJSONMarshal(t, u, want) 605 } 606 607 func TestRegistrationToken_Marshal(t *testing.T) { 608 t.Parallel() 609 testJSONMarshal(t, &RegistrationToken{}, "{}") 610 611 u := &RegistrationToken{ 612 Token: Ptr("t"), 613 ExpiresAt: &Timestamp{referenceTime}, 614 } 615 616 want := `{ 617 "token": "t", 618 "expires_at": ` + referenceTimeStr + ` 619 }` 620 621 testJSONMarshal(t, u, want) 622 } 623 624 func TestRunnerLabels_Marshal(t *testing.T) { 625 t.Parallel() 626 testJSONMarshal(t, &RunnerLabels{}, "{}") 627 628 u := &RunnerLabels{ 629 ID: Ptr(int64(1)), 630 Name: Ptr("n"), 631 Type: Ptr("t"), 632 } 633 634 want := `{ 635 "id": 1, 636 "name": "n", 637 "type": "t" 638 }` 639 640 testJSONMarshal(t, u, want) 641 } 642 643 func TestRunner_Marshal(t *testing.T) { 644 t.Parallel() 645 testJSONMarshal(t, &Runner{}, "{}") 646 647 u := &Runner{ 648 ID: Ptr(int64(1)), 649 Name: Ptr("n"), 650 OS: Ptr("o"), 651 Status: Ptr("s"), 652 Busy: Ptr(false), 653 Labels: []*RunnerLabels{ 654 { 655 ID: Ptr(int64(1)), 656 Name: Ptr("n"), 657 Type: Ptr("t"), 658 }, 659 }, 660 } 661 662 want := `{ 663 "id": 1, 664 "name": "n", 665 "os": "o", 666 "status": "s", 667 "busy": false, 668 "labels": [ 669 { 670 "id": 1, 671 "name": "n", 672 "type": "t" 673 } 674 ] 675 }` 676 677 testJSONMarshal(t, u, want) 678 } 679 680 func TestRunners_Marshal(t *testing.T) { 681 t.Parallel() 682 testJSONMarshal(t, &Runners{}, "{}") 683 684 u := &Runners{ 685 TotalCount: 1, 686 Runners: []*Runner{ 687 { 688 ID: Ptr(int64(1)), 689 Name: Ptr("n"), 690 OS: Ptr("o"), 691 Status: Ptr("s"), 692 Busy: Ptr(false), 693 Labels: []*RunnerLabels{ 694 { 695 ID: Ptr(int64(1)), 696 Name: Ptr("n"), 697 Type: Ptr("t"), 698 }, 699 }, 700 }, 701 }, 702 } 703 704 want := `{ 705 "total_count": 1, 706 "runners": [ 707 { 708 "id": 1, 709 "name": "n", 710 "os": "o", 711 "status": "s", 712 "busy": false, 713 "labels": [ 714 { 715 "id": 1, 716 "name": "n", 717 "type": "t" 718 } 719 ] 720 } 721 ] 722 }` 723 724 testJSONMarshal(t, u, want) 725 } 726 727 func TestRemoveToken_Marshal(t *testing.T) { 728 t.Parallel() 729 testJSONMarshal(t, &RemoveToken{}, "{}") 730 731 u := &RemoveToken{ 732 Token: Ptr("t"), 733 ExpiresAt: &Timestamp{referenceTime}, 734 } 735 736 want := `{ 737 "token": "t", 738 "expires_at": ` + referenceTimeStr + ` 739 }` 740 741 testJSONMarshal(t, u, want) 742 }