1
2
3
4
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 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 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{"per_page": "2", "page": "2"})
192 fmt.Fprint(w, `{"total_count":2,"runners":[{"id":23,"name":"MBP","os":"macos","status":"online"},{"id":24,"name":"iMac","os":"macos","status":"offline"}]}`)
193 })
194
195 opts := &ListOptions{Page: 2, PerPage: 2}
196 ctx := context.Background()
197 runners, _, err := client.Actions.ListRunners(ctx, "o", "r", opts)
198 if err != nil {
199 t.Errorf("Actions.ListRunners returned error: %v", err)
200 }
201
202 want := &Runners{
203 TotalCount: 2,
204 Runners: []*Runner{
205 {ID: Int64(23), Name: String("MBP"), OS: String("macos"), Status: String("online")},
206 {ID: Int64(24), Name: String("iMac"), OS: String("macos"), Status: String("offline")},
207 },
208 }
209 if !cmp.Equal(runners, want) {
210 t.Errorf("Actions.ListRunners returned %+v, want %+v", runners, want)
211 }
212
213 const methodName = "ListRunners"
214 testBadOptions(t, methodName, func() (err error) {
215 _, _, err = client.Actions.ListRunners(ctx, "\n", "\n", opts)
216 return err
217 })
218
219 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
220 got, resp, err := client.Actions.ListRunners(ctx, "o", "r", opts)
221 if got != nil {
222 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
223 }
224 return resp, err
225 })
226 }
227
228 func TestActionsService_GetRunner(t *testing.T) {
229 client, mux, _, teardown := setup()
230 defer teardown()
231
232 mux.HandleFunc("/repos/o/r/actions/runners/23", func(w http.ResponseWriter, r *http.Request) {
233 testMethod(t, r, "GET")
234 fmt.Fprint(w, `{"id":23,"name":"MBP","os":"macos","status":"online"}`)
235 })
236
237 ctx := context.Background()
238 runner, _, err := client.Actions.GetRunner(ctx, "o", "r", 23)
239 if err != nil {
240 t.Errorf("Actions.GetRunner returned error: %v", err)
241 }
242
243 want := &Runner{
244 ID: Int64(23),
245 Name: String("MBP"),
246 OS: String("macos"),
247 Status: String("online"),
248 }
249 if !cmp.Equal(runner, want) {
250 t.Errorf("Actions.GetRunner returned %+v, want %+v", runner, want)
251 }
252
253 const methodName = "GetRunner"
254 testBadOptions(t, methodName, func() (err error) {
255 _, _, err = client.Actions.GetRunner(ctx, "\n", "\n", 23)
256 return err
257 })
258
259 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
260 got, resp, err := client.Actions.GetRunner(ctx, "o", "r", 23)
261 if got != nil {
262 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
263 }
264 return resp, err
265 })
266 }
267
268 func TestActionsService_CreateRemoveToken(t *testing.T) {
269 client, mux, _, teardown := setup()
270 defer teardown()
271
272 mux.HandleFunc("/repos/o/r/actions/runners/remove-token", func(w http.ResponseWriter, r *http.Request) {
273 testMethod(t, r, "POST")
274 fmt.Fprint(w, `{"token":"AABF3JGZDX3P5PMEXLND6TS6FCWO6","expires_at":"2020-01-29T12:13:35.123Z"}`)
275 })
276
277 ctx := context.Background()
278 token, _, err := client.Actions.CreateRemoveToken(ctx, "o", "r")
279 if err != nil {
280 t.Errorf("Actions.CreateRemoveToken returned error: %v", err)
281 }
282
283 want := &RemoveToken{Token: String("AABF3JGZDX3P5PMEXLND6TS6FCWO6"), ExpiresAt: &Timestamp{time.Date(2020, time.January, 29, 12, 13, 35, 123000000, time.UTC)}}
284 if !cmp.Equal(token, want) {
285 t.Errorf("Actions.CreateRemoveToken returned %+v, want %+v", token, want)
286 }
287
288 const methodName = "CreateRemoveToken"
289 testBadOptions(t, methodName, func() (err error) {
290 _, _, err = client.Actions.CreateRemoveToken(ctx, "\n", "\n")
291 return err
292 })
293
294 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
295 got, resp, err := client.Actions.CreateRemoveToken(ctx, "o", "r")
296 if got != nil {
297 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
298 }
299 return resp, err
300 })
301 }
302
303 func TestActionsService_RemoveRunner(t *testing.T) {
304 client, mux, _, teardown := setup()
305 defer teardown()
306
307 mux.HandleFunc("/repos/o/r/actions/runners/21", func(w http.ResponseWriter, r *http.Request) {
308 testMethod(t, r, "DELETE")
309 })
310
311 ctx := context.Background()
312 _, err := client.Actions.RemoveRunner(ctx, "o", "r", 21)
313 if err != nil {
314 t.Errorf("Actions.RemoveRunner returned error: %v", err)
315 }
316
317 const methodName = "RemoveRunner"
318 testBadOptions(t, methodName, func() (err error) {
319 _, err = client.Actions.RemoveRunner(ctx, "\n", "\n", 21)
320 return err
321 })
322
323 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
324 return client.Actions.RemoveRunner(ctx, "o", "r", 21)
325 })
326 }
327
328 func TestActionsService_ListOrganizationRunnerApplicationDownloads(t *testing.T) {
329 client, mux, _, teardown := setup()
330 defer teardown()
331
332 mux.HandleFunc("/orgs/o/actions/runners/downloads", func(w http.ResponseWriter, r *http.Request) {
333 testMethod(t, r, "GET")
334 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"}]`)
335 })
336
337 ctx := context.Background()
338 downloads, _, err := client.Actions.ListOrganizationRunnerApplicationDownloads(ctx, "o")
339 if err != nil {
340 t.Errorf("Actions.ListRunnerApplicationDownloads returned error: %v", err)
341 }
342
343 want := []*RunnerApplicationDownload{
344 {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")},
345 {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")},
346 {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")},
347 {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")},
348 {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")},
349 }
350 if !cmp.Equal(downloads, want) {
351 t.Errorf("Actions.ListOrganizationRunnerApplicationDownloads returned %+v, want %+v", downloads, want)
352 }
353
354 const methodName = "ListOrganizationRunnerApplicationDownloads"
355 testBadOptions(t, methodName, func() (err error) {
356 _, _, err = client.Actions.ListOrganizationRunnerApplicationDownloads(ctx, "\n")
357 return err
358 })
359
360 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
361 got, resp, err := client.Actions.ListOrganizationRunnerApplicationDownloads(ctx, "o")
362 if got != nil {
363 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
364 }
365 return resp, err
366 })
367 }
368
369 func TestActionsService_CreateOrganizationRegistrationToken(t *testing.T) {
370 client, mux, _, teardown := setup()
371 defer teardown()
372
373 mux.HandleFunc("/orgs/o/actions/runners/registration-token", func(w http.ResponseWriter, r *http.Request) {
374 testMethod(t, r, "POST")
375 fmt.Fprint(w, `{"token":"LLBF3JGZDX3P5PMEXLND6TS6FCWO6","expires_at":"2020-01-22T12:13:35.123Z"}`)
376 })
377
378 ctx := context.Background()
379 token, _, err := client.Actions.CreateOrganizationRegistrationToken(ctx, "o")
380 if err != nil {
381 t.Errorf("Actions.CreateRegistrationToken returned error: %v", err)
382 }
383
384 want := &RegistrationToken{Token: String("LLBF3JGZDX3P5PMEXLND6TS6FCWO6"),
385 ExpiresAt: &Timestamp{time.Date(2020, time.January, 22, 12, 13, 35,
386 123000000, time.UTC)}}
387 if !cmp.Equal(token, want) {
388 t.Errorf("Actions.CreateRegistrationToken returned %+v, want %+v", token, want)
389 }
390
391 const methodName = "CreateOrganizationRegistrationToken"
392 testBadOptions(t, methodName, func() (err error) {
393 _, _, err = client.Actions.CreateOrganizationRegistrationToken(ctx, "\n")
394 return err
395 })
396
397 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
398 got, resp, err := client.Actions.CreateOrganizationRegistrationToken(ctx, "o")
399 if got != nil {
400 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
401 }
402 return resp, err
403 })
404 }
405
406 func TestActionsService_ListOrganizationRunners(t *testing.T) {
407 client, mux, _, teardown := setup()
408 defer teardown()
409
410 mux.HandleFunc("/orgs/o/actions/runners", func(w http.ResponseWriter, r *http.Request) {
411 testMethod(t, r, "GET")
412 testFormValues(t, r, values{"per_page": "2", "page": "2"})
413 fmt.Fprint(w, `{"total_count":2,"runners":[{"id":23,"name":"MBP","os":"macos","status":"online"},{"id":24,"name":"iMac","os":"macos","status":"offline"}]}`)
414 })
415
416 opts := &ListOptions{Page: 2, PerPage: 2}
417 ctx := context.Background()
418 runners, _, err := client.Actions.ListOrganizationRunners(ctx, "o", opts)
419 if err != nil {
420 t.Errorf("Actions.ListRunners returned error: %v", err)
421 }
422
423 want := &Runners{
424 TotalCount: 2,
425 Runners: []*Runner{
426 {ID: Int64(23), Name: String("MBP"), OS: String("macos"), Status: String("online")},
427 {ID: Int64(24), Name: String("iMac"), OS: String("macos"), Status: String("offline")},
428 },
429 }
430 if !cmp.Equal(runners, want) {
431 t.Errorf("Actions.ListRunners returned %+v, want %+v", runners, want)
432 }
433
434 const methodName = "ListOrganizationRunners"
435 testBadOptions(t, methodName, func() (err error) {
436 _, _, err = client.Actions.ListOrganizationRunners(ctx, "\n", opts)
437 return err
438 })
439
440 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
441 got, resp, err := client.Actions.ListOrganizationRunners(ctx, "o", opts)
442 if got != nil {
443 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
444 }
445 return resp, err
446 })
447 }
448
449 func TestActionsService_ListEnabledReposInOrg(t *testing.T) {
450 client, mux, _, teardown := setup()
451 defer teardown()
452
453 mux.HandleFunc("/orgs/o/actions/permissions/repositories", func(w http.ResponseWriter, r *http.Request) {
454 testMethod(t, r, "GET")
455 testFormValues(t, r, values{
456 "page": "1",
457 })
458 fmt.Fprint(w, `{"total_count":2,"repositories":[{"id":2}, {"id": 3}]}`)
459 })
460
461 ctx := context.Background()
462 opt := &ListOptions{
463 Page: 1,
464 }
465 got, _, err := client.Actions.ListEnabledReposInOrg(ctx, "o", opt)
466 if err != nil {
467 t.Errorf("Actions.ListEnabledReposInOrg returned error: %v", err)
468 }
469
470 want := &ActionsEnabledOnOrgRepos{TotalCount: int(2), Repositories: []*Repository{
471 {ID: Int64(2)},
472 {ID: Int64(3)},
473 }}
474 if !cmp.Equal(got, want) {
475 t.Errorf("Actions.ListEnabledReposInOrg returned %+v, want %+v", got, want)
476 }
477
478 const methodName = "ListEnabledReposInOrg"
479 testBadOptions(t, methodName, func() (err error) {
480 _, _, err = client.Actions.ListEnabledReposInOrg(ctx, "\n", opt)
481 return err
482 })
483
484 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
485 got, resp, err := client.Actions.ListEnabledReposInOrg(ctx, "o", opt)
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_SetEnabledReposInOrg(t *testing.T) {
494 client, mux, _, teardown := setup()
495 defer teardown()
496
497 mux.HandleFunc("/orgs/o/actions/permissions/repositories", func(w http.ResponseWriter, r *http.Request) {
498 testMethod(t, r, "PUT")
499 testHeader(t, r, "Content-Type", "application/json")
500 testBody(t, r, `{"selected_repository_ids":[123,1234]}`+"\n")
501 w.WriteHeader(http.StatusNoContent)
502 })
503
504 ctx := context.Background()
505 _, err := client.Actions.SetEnabledReposInOrg(ctx, "o", []int64{123, 1234})
506 if err != nil {
507 t.Errorf("Actions.SetEnabledReposInOrg returned error: %v", err)
508 }
509
510 const methodName = "SetEnabledReposInOrg"
511
512 testBadOptions(t, methodName, func() (err error) {
513 _, err = client.Actions.SetEnabledReposInOrg(ctx, "\n", []int64{123, 1234})
514 return err
515 })
516
517 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
518 return client.Actions.SetEnabledReposInOrg(ctx, "o", []int64{123, 1234})
519 })
520 }
521
522 func TestActionsService_AddEnabledReposInOrg(t *testing.T) {
523 client, mux, _, teardown := setup()
524 defer teardown()
525
526 mux.HandleFunc("/orgs/o/actions/permissions/repositories/123", func(w http.ResponseWriter, r *http.Request) {
527 testMethod(t, r, "PUT")
528 w.WriteHeader(http.StatusNoContent)
529 })
530
531 ctx := context.Background()
532 _, err := client.Actions.AddEnabledReposInOrg(ctx, "o", 123)
533 if err != nil {
534 t.Errorf("Actions.AddEnabledReposInOrg returned error: %v", err)
535 }
536
537 const methodName = "AddEnabledReposInOrg"
538
539 testBadOptions(t, methodName, func() (err error) {
540 _, err = client.Actions.AddEnabledReposInOrg(ctx, "\n", 123)
541 return err
542 })
543
544 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
545 return client.Actions.AddEnabledReposInOrg(ctx, "o", 123)
546 })
547 }
548
549 func TestActionsService_RemoveEnabledRepoInOrg(t *testing.T) {
550 client, mux, _, teardown := setup()
551 defer teardown()
552
553 mux.HandleFunc("/orgs/o/actions/permissions/repositories/123", func(w http.ResponseWriter, r *http.Request) {
554 testMethod(t, r, "DELETE")
555 w.WriteHeader(http.StatusNoContent)
556 })
557
558 ctx := context.Background()
559 _, err := client.Actions.RemoveEnabledRepoInOrg(ctx, "o", 123)
560 if err != nil {
561 t.Errorf("Actions.RemoveEnabledRepoInOrg returned error: %v", err)
562 }
563
564 const methodName = "RemoveEnabledRepoInOrg"
565
566 testBadOptions(t, methodName, func() (err error) {
567 _, err = client.Actions.RemoveEnabledRepoInOrg(ctx, "\n", 123)
568 return err
569 })
570
571 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
572 return client.Actions.RemoveEnabledRepoInOrg(ctx, "o", 123)
573 })
574 }
575
576 func TestActionsService_GetOrganizationRunner(t *testing.T) {
577 client, mux, _, teardown := setup()
578 defer teardown()
579
580 mux.HandleFunc("/orgs/o/actions/runners/23", func(w http.ResponseWriter, r *http.Request) {
581 testMethod(t, r, "GET")
582 fmt.Fprint(w, `{"id":23,"name":"MBP","os":"macos","status":"online"}`)
583 })
584
585 ctx := context.Background()
586 runner, _, err := client.Actions.GetOrganizationRunner(ctx, "o", 23)
587 if err != nil {
588 t.Errorf("Actions.GetRunner returned error: %v", err)
589 }
590
591 want := &Runner{
592 ID: Int64(23),
593 Name: String("MBP"),
594 OS: String("macos"),
595 Status: String("online"),
596 }
597 if !cmp.Equal(runner, want) {
598 t.Errorf("Actions.GetRunner returned %+v, want %+v", runner, want)
599 }
600
601 const methodName = "GetOrganizationRunner"
602 testBadOptions(t, methodName, func() (err error) {
603 _, _, err = client.Actions.GetOrganizationRunner(ctx, "\n", 23)
604 return err
605 })
606
607 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
608 got, resp, err := client.Actions.GetOrganizationRunner(ctx, "o", 23)
609 if got != nil {
610 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
611 }
612 return resp, err
613 })
614 }
615
616 func TestActionsService_CreateOrganizationRemoveToken(t *testing.T) {
617 client, mux, _, teardown := setup()
618 defer teardown()
619
620 mux.HandleFunc("/orgs/o/actions/runners/remove-token", func(w http.ResponseWriter, r *http.Request) {
621 testMethod(t, r, "POST")
622 fmt.Fprint(w, `{"token":"AABF3JGZDX3P5PMEXLND6TS6FCWO6","expires_at":"2020-01-29T12:13:35.123Z"}`)
623 })
624
625 ctx := context.Background()
626 token, _, err := client.Actions.CreateOrganizationRemoveToken(ctx, "o")
627 if err != nil {
628 t.Errorf("Actions.CreateRemoveToken returned error: %v", err)
629 }
630
631 want := &RemoveToken{Token: String("AABF3JGZDX3P5PMEXLND6TS6FCWO6"), ExpiresAt: &Timestamp{time.Date(2020, time.January, 29, 12, 13, 35, 123000000, time.UTC)}}
632 if !cmp.Equal(token, want) {
633 t.Errorf("Actions.CreateRemoveToken returned %+v, want %+v", token, want)
634 }
635
636 const methodName = "CreateOrganizationRemoveToken"
637 testBadOptions(t, methodName, func() (err error) {
638 _, _, err = client.Actions.CreateOrganizationRemoveToken(ctx, "\n")
639 return err
640 })
641
642 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
643 got, resp, err := client.Actions.CreateOrganizationRemoveToken(ctx, "o")
644 if got != nil {
645 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
646 }
647 return resp, err
648 })
649 }
650
651 func TestActionsService_RemoveOrganizationRunner(t *testing.T) {
652 client, mux, _, teardown := setup()
653 defer teardown()
654
655 mux.HandleFunc("/orgs/o/actions/runners/21", func(w http.ResponseWriter, r *http.Request) {
656 testMethod(t, r, "DELETE")
657 })
658
659 ctx := context.Background()
660 _, err := client.Actions.RemoveOrganizationRunner(ctx, "o", 21)
661 if err != nil {
662 t.Errorf("Actions.RemoveOganizationRunner returned error: %v", err)
663 }
664
665 const methodName = "RemoveOrganizationRunner"
666 testBadOptions(t, methodName, func() (err error) {
667 _, err = client.Actions.RemoveOrganizationRunner(ctx, "\n", 21)
668 return err
669 })
670
671 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
672 return client.Actions.RemoveOrganizationRunner(ctx, "o", 21)
673 })
674 }
675
676 func TestRunnerApplicationDownload_Marshal(t *testing.T) {
677 testJSONMarshal(t, &RunnerApplicationDownload{}, "{}")
678
679 u := &RunnerApplicationDownload{
680 OS: String("o"),
681 Architecture: String("a"),
682 DownloadURL: String("d"),
683 Filename: String("f"),
684 TempDownloadToken: String("t"),
685 SHA256Checksum: String("s"),
686 }
687
688 want := `{
689 "os": "o",
690 "architecture": "a",
691 "download_url": "d",
692 "filename": "f",
693 "temp_download_token": "t",
694 "sha256_checksum": "s"
695 }`
696
697 testJSONMarshal(t, u, want)
698 }
699
700 func TestActionsEnabledOnOrgRepos_Marshal(t *testing.T) {
701 testJSONMarshal(t, &ActionsEnabledOnOrgRepos{}, "{}")
702
703 u := &ActionsEnabledOnOrgRepos{
704 TotalCount: 1,
705 Repositories: []*Repository{
706 {
707 ID: Int64(1),
708 URL: String("u"),
709 Name: String("n"),
710 },
711 },
712 }
713
714 want := `{
715 "total_count": 1,
716 "repositories": [
717 {
718 "id": 1,
719 "url": "u",
720 "name": "n"
721 }
722 ]
723 }`
724
725 testJSONMarshal(t, u, want)
726 }
727
728 func TestRegistrationToken_Marshal(t *testing.T) {
729 testJSONMarshal(t, &RegistrationToken{}, "{}")
730
731 u := &RegistrationToken{
732 Token: String("t"),
733 ExpiresAt: &Timestamp{referenceTime},
734 }
735
736 want := `{
737 "token": "t",
738 "expires_at": ` + referenceTimeStr + `
739 }`
740
741 testJSONMarshal(t, u, want)
742 }
743
744 func TestRunnerLabels_Marshal(t *testing.T) {
745 testJSONMarshal(t, &RunnerLabels{}, "{}")
746
747 u := &RunnerLabels{
748 ID: Int64(1),
749 Name: String("n"),
750 Type: String("t"),
751 }
752
753 want := `{
754 "id": 1,
755 "name": "n",
756 "type": "t"
757 }`
758
759 testJSONMarshal(t, u, want)
760 }
761
762 func TestRunner_Marshal(t *testing.T) {
763 testJSONMarshal(t, &Runner{}, "{}")
764
765 u := &Runner{
766 ID: Int64(1),
767 Name: String("n"),
768 OS: String("o"),
769 Status: String("s"),
770 Busy: Bool(false),
771 Labels: []*RunnerLabels{
772 {
773 ID: Int64(1),
774 Name: String("n"),
775 Type: String("t"),
776 },
777 },
778 }
779
780 want := `{
781 "id": 1,
782 "name": "n",
783 "os": "o",
784 "status": "s",
785 "busy": false,
786 "labels": [
787 {
788 "id": 1,
789 "name": "n",
790 "type": "t"
791 }
792 ]
793 }`
794
795 testJSONMarshal(t, u, want)
796 }
797
798 func TestRunners_Marshal(t *testing.T) {
799 testJSONMarshal(t, &Runners{}, "{}")
800
801 u := &Runners{
802 TotalCount: 1,
803 Runners: []*Runner{
804 {
805 ID: Int64(1),
806 Name: String("n"),
807 OS: String("o"),
808 Status: String("s"),
809 Busy: Bool(false),
810 Labels: []*RunnerLabels{
811 {
812 ID: Int64(1),
813 Name: String("n"),
814 Type: String("t"),
815 },
816 },
817 },
818 },
819 }
820
821 want := `{
822 "total_count": 1,
823 "runners": [
824 {
825 "id": 1,
826 "name": "n",
827 "os": "o",
828 "status": "s",
829 "busy": false,
830 "labels": [
831 {
832 "id": 1,
833 "name": "n",
834 "type": "t"
835 }
836 ]
837 }
838 ]
839 }`
840
841 testJSONMarshal(t, u, want)
842 }
843
844 func TestRemoveToken_Marshal(t *testing.T) {
845 testJSONMarshal(t, &RemoveToken{}, "{}")
846
847 u := &RemoveToken{
848 Token: String("t"),
849 ExpiresAt: &Timestamp{referenceTime},
850 }
851
852 want := `{
853 "token": "t",
854 "expires_at": ` + referenceTimeStr + `
855 }`
856
857 testJSONMarshal(t, u, want)
858 }
859
View as plain text