github.com/google/go-github/v64@v64.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 client, mux, _, teardown := setup() 21 defer teardown() 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: String("osx"), Architecture: String("x64"), DownloadURL: String("https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-osx-x64-2.164.0.tar.gz"), Filename: String("actions-runner-osx-x64-2.164.0.tar.gz")}, 36 {OS: String("linux"), Architecture: String("x64"), DownloadURL: String("https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-linux-x64-2.164.0.tar.gz"), Filename: String("actions-runner-linux-x64-2.164.0.tar.gz")}, 37 {OS: String("linux"), Architecture: String("arm"), DownloadURL: String("https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-linux-arm-2.164.0.tar.gz"), Filename: String("actions-runner-linux-arm-2.164.0.tar.gz")}, 38 {OS: String("win"), Architecture: String("x64"), DownloadURL: String("https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-win-x64-2.164.0.zip"), Filename: String("actions-runner-win-x64-2.164.0.zip")}, 39 {OS: String("linux"), Architecture: String("arm64"), DownloadURL: String("https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-linux-arm64-2.164.0.tar.gz"), Filename: String("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 client, mux, _, teardown := setup() 62 defer teardown() 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: String("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 client, mux, _, teardown := setup() 106 defer teardown() 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: String("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 client, mux, _, teardown := setup() 150 defer teardown() 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: String("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 client, mux, _, teardown := setup() 187 defer teardown() 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: String("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: Int64(23), Name: String("MBP"), OS: String("macos"), Status: String("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 client, mux, _, teardown := setup() 232 defer teardown() 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: Int64(23), 247 Name: String("MBP"), 248 OS: String("macos"), 249 Status: String("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 client, mux, _, teardown := setup() 272 defer teardown() 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: String("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 client, mux, _, teardown := setup() 307 defer teardown() 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 client, mux, _, teardown := setup() 332 defer teardown() 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: String("osx"), Architecture: String("x64"), DownloadURL: String("https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-osx-x64-2.164.0.tar.gz"), Filename: String("actions-runner-osx-x64-2.164.0.tar.gz")}, 347 {OS: String("linux"), Architecture: String("x64"), DownloadURL: String("https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-linux-x64-2.164.0.tar.gz"), Filename: String("actions-runner-linux-x64-2.164.0.tar.gz")}, 348 {OS: String("linux"), Architecture: String("arm"), DownloadURL: String("https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-linux-arm-2.164.0.tar.gz"), Filename: String("actions-runner-linux-arm-2.164.0.tar.gz")}, 349 {OS: String("win"), Architecture: String("x64"), DownloadURL: String("https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-win-x64-2.164.0.zip"), Filename: String("actions-runner-win-x64-2.164.0.zip")}, 350 {OS: String("linux"), Architecture: String("arm64"), DownloadURL: String("https://github.com/actions/runner/releases/download/v2.164.0/actions-runner-linux-arm64-2.164.0.tar.gz"), Filename: String("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 client, mux, _, teardown := setup() 373 defer teardown() 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: String("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 client, mux, _, teardown := setup() 410 defer teardown() 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: Int64(23), Name: String("MBP"), OS: String("macos"), Status: String("online")}, 431 {ID: Int64(24), Name: String("iMac"), OS: String("macos"), Status: String("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 client, mux, _, teardown := setup() 455 defer teardown() 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: Int64(23), 470 Name: String("MBP"), 471 OS: String("macos"), 472 Status: String("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 client, mux, _, teardown := setup() 495 defer teardown() 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: String("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 client, mux, _, teardown := setup() 530 defer teardown() 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.RemoveOganizationRunner 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 testJSONMarshal(t, &RunnerApplicationDownload{}, "{}") 555 556 u := &RunnerApplicationDownload{ 557 OS: String("o"), 558 Architecture: String("a"), 559 DownloadURL: String("d"), 560 Filename: String("f"), 561 TempDownloadToken: String("t"), 562 SHA256Checksum: String("s"), 563 } 564 565 want := `{ 566 "os": "o", 567 "architecture": "a", 568 "download_url": "d", 569 "filename": "f", 570 "temp_download_token": "t", 571 "sha256_checksum": "s" 572 }` 573 574 testJSONMarshal(t, u, want) 575 } 576 577 func TestActionsEnabledOnOrgRepos_Marshal(t *testing.T) { 578 testJSONMarshal(t, &ActionsEnabledOnOrgRepos{}, "{}") 579 580 u := &ActionsEnabledOnOrgRepos{ 581 TotalCount: 1, 582 Repositories: []*Repository{ 583 { 584 ID: Int64(1), 585 URL: String("u"), 586 Name: String("n"), 587 }, 588 }, 589 } 590 591 want := `{ 592 "total_count": 1, 593 "repositories": [ 594 { 595 "id": 1, 596 "url": "u", 597 "name": "n" 598 } 599 ] 600 }` 601 602 testJSONMarshal(t, u, want) 603 } 604 605 func TestRegistrationToken_Marshal(t *testing.T) { 606 testJSONMarshal(t, &RegistrationToken{}, "{}") 607 608 u := &RegistrationToken{ 609 Token: String("t"), 610 ExpiresAt: &Timestamp{referenceTime}, 611 } 612 613 want := `{ 614 "token": "t", 615 "expires_at": ` + referenceTimeStr + ` 616 }` 617 618 testJSONMarshal(t, u, want) 619 } 620 621 func TestRunnerLabels_Marshal(t *testing.T) { 622 testJSONMarshal(t, &RunnerLabels{}, "{}") 623 624 u := &RunnerLabels{ 625 ID: Int64(1), 626 Name: String("n"), 627 Type: String("t"), 628 } 629 630 want := `{ 631 "id": 1, 632 "name": "n", 633 "type": "t" 634 }` 635 636 testJSONMarshal(t, u, want) 637 } 638 639 func TestRunner_Marshal(t *testing.T) { 640 testJSONMarshal(t, &Runner{}, "{}") 641 642 u := &Runner{ 643 ID: Int64(1), 644 Name: String("n"), 645 OS: String("o"), 646 Status: String("s"), 647 Busy: Bool(false), 648 Labels: []*RunnerLabels{ 649 { 650 ID: Int64(1), 651 Name: String("n"), 652 Type: String("t"), 653 }, 654 }, 655 } 656 657 want := `{ 658 "id": 1, 659 "name": "n", 660 "os": "o", 661 "status": "s", 662 "busy": false, 663 "labels": [ 664 { 665 "id": 1, 666 "name": "n", 667 "type": "t" 668 } 669 ] 670 }` 671 672 testJSONMarshal(t, u, want) 673 } 674 675 func TestRunners_Marshal(t *testing.T) { 676 testJSONMarshal(t, &Runners{}, "{}") 677 678 u := &Runners{ 679 TotalCount: 1, 680 Runners: []*Runner{ 681 { 682 ID: Int64(1), 683 Name: String("n"), 684 OS: String("o"), 685 Status: String("s"), 686 Busy: Bool(false), 687 Labels: []*RunnerLabels{ 688 { 689 ID: Int64(1), 690 Name: String("n"), 691 Type: String("t"), 692 }, 693 }, 694 }, 695 }, 696 } 697 698 want := `{ 699 "total_count": 1, 700 "runners": [ 701 { 702 "id": 1, 703 "name": "n", 704 "os": "o", 705 "status": "s", 706 "busy": false, 707 "labels": [ 708 { 709 "id": 1, 710 "name": "n", 711 "type": "t" 712 } 713 ] 714 } 715 ] 716 }` 717 718 testJSONMarshal(t, u, want) 719 } 720 721 func TestRemoveToken_Marshal(t *testing.T) { 722 testJSONMarshal(t, &RemoveToken{}, "{}") 723 724 u := &RemoveToken{ 725 Token: String("t"), 726 ExpiresAt: &Timestamp{referenceTime}, 727 } 728 729 want := `{ 730 "token": "t", 731 "expires_at": ` + referenceTimeStr + ` 732 }` 733 734 testJSONMarshal(t, u, want) 735 }