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