|
6 | 6 | package github |
7 | 7 |
|
8 | 8 | import ( |
9 | | - "encoding/json" |
10 | 9 | "fmt" |
11 | 10 | "net/http" |
12 | 11 | "testing" |
@@ -55,14 +54,8 @@ func TestActionsService_UpdateActionsPermissionsInEnterprise(t *testing.T) { |
55 | 54 | input := &ActionsPermissionsEnterprise{EnabledOrganizations: Ptr("all"), AllowedActions: Ptr("selected")} |
56 | 55 |
|
57 | 56 | mux.HandleFunc("/enterprises/e/actions/permissions", func(w http.ResponseWriter, r *http.Request) { |
58 | | - var v *ActionsPermissionsEnterprise |
59 | | - assertNilError(t, json.NewDecoder(r.Body).Decode(&v)) |
60 | | - |
61 | 57 | testMethod(t, r, "PUT") |
62 | | - if !cmp.Equal(v, input) { |
63 | | - t.Errorf("Request body = %+v, want %+v", v, input) |
64 | | - } |
65 | | - |
| 58 | + testJSONBody(t, r, input) |
66 | 59 | fmt.Fprint(w, `{"enabled_organizations": "all", "allowed_actions": "selected"}`) |
67 | 60 | }) |
68 | 61 |
|
@@ -140,28 +133,34 @@ func TestActionsService_SetEnabledOrgsInEnterprise(t *testing.T) { |
140 | 133 | t.Parallel() |
141 | 134 | client, mux, _ := setup(t) |
142 | 135 |
|
| 136 | + input := []int64{123, 1234} |
| 137 | + |
143 | 138 | mux.HandleFunc("/enterprises/e/actions/permissions/organizations", func(w http.ResponseWriter, r *http.Request) { |
144 | 139 | testMethod(t, r, "PUT") |
145 | 140 | testHeader(t, r, "Content-Type", "application/json") |
146 | | - testBody(t, r, `{"selected_organization_ids":[123,1234]}`+"\n") |
| 141 | + testJSONBody(t, r, struct { |
| 142 | + IDs []int64 `json:"selected_organization_ids"` |
| 143 | + }{ |
| 144 | + IDs: input, |
| 145 | + }) |
147 | 146 | w.WriteHeader(http.StatusNoContent) |
148 | 147 | }) |
149 | 148 |
|
150 | 149 | ctx := t.Context() |
151 | | - _, err := client.Actions.SetEnabledOrgsInEnterprise(ctx, "e", []int64{123, 1234}) |
| 150 | + _, err := client.Actions.SetEnabledOrgsInEnterprise(ctx, "e", input) |
152 | 151 | if err != nil { |
153 | 152 | t.Errorf("Actions.SetEnabledOrgsInEnterprise returned error: %v", err) |
154 | 153 | } |
155 | 154 |
|
156 | 155 | const methodName = "SetEnabledOrgsInEnterprise" |
157 | 156 |
|
158 | 157 | testBadOptions(t, methodName, func() (err error) { |
159 | | - _, err = client.Actions.SetEnabledOrgsInEnterprise(ctx, "\n", []int64{123, 1234}) |
| 158 | + _, err = client.Actions.SetEnabledOrgsInEnterprise(ctx, "\n", input) |
160 | 159 | return err |
161 | 160 | }) |
162 | 161 |
|
163 | 162 | testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { |
164 | | - return client.Actions.SetEnabledOrgsInEnterprise(ctx, "e", []int64{123, 1234}) |
| 163 | + return client.Actions.SetEnabledOrgsInEnterprise(ctx, "e", input) |
165 | 164 | }) |
166 | 165 | } |
167 | 166 |
|
@@ -260,14 +259,8 @@ func TestActionsService_UpdateActionsAllowedInEnterprise(t *testing.T) { |
260 | 259 | input := &ActionsAllowed{GithubOwnedAllowed: Ptr(true), VerifiedAllowed: Ptr(false), PatternsAllowed: []string{"a/b"}} |
261 | 260 |
|
262 | 261 | mux.HandleFunc("/enterprises/e/actions/permissions/selected-actions", func(w http.ResponseWriter, r *http.Request) { |
263 | | - var v *ActionsAllowed |
264 | | - assertNilError(t, json.NewDecoder(r.Body).Decode(&v)) |
265 | | - |
266 | 262 | testMethod(t, r, "PUT") |
267 | | - if !cmp.Equal(v, input) { |
268 | | - t.Errorf("Request body = %+v, want %+v", v, input) |
269 | | - } |
270 | | - |
| 263 | + testJSONBody(t, r, input) |
271 | 264 | fmt.Fprint(w, `{"github_owned_allowed":true, "verified_allowed":false, "patterns_allowed":["a/b"]}`) |
272 | 265 | }) |
273 | 266 |
|
@@ -338,14 +331,8 @@ func TestActionsService_UpdateDefaultWorkflowPermissionsInEnterprise(t *testing. |
338 | 331 | input := &DefaultWorkflowPermissionEnterprise{DefaultWorkflowPermissions: Ptr("read"), CanApprovePullRequestReviews: Ptr(true)} |
339 | 332 |
|
340 | 333 | mux.HandleFunc("/enterprises/e/actions/permissions/workflow", func(w http.ResponseWriter, r *http.Request) { |
341 | | - var v *DefaultWorkflowPermissionEnterprise |
342 | | - assertNilError(t, json.NewDecoder(r.Body).Decode(&v)) |
343 | | - |
344 | 334 | testMethod(t, r, "PUT") |
345 | | - if !cmp.Equal(v, input) { |
346 | | - t.Errorf("Request body = %+v, want %+v", v, input) |
347 | | - } |
348 | | - |
| 335 | + testJSONBody(t, r, input) |
349 | 336 | fmt.Fprint(w, `{ "default_workflow_permissions": "read", "can_approve_pull_request_reviews": true }`) |
350 | 337 | }) |
351 | 338 |
|
@@ -420,13 +407,8 @@ func TestActionsService_UpdateArtifactAndLogRetentionPeriodInEnterprise(t *testi |
420 | 407 | input := &ArtifactPeriodOpt{Days: Ptr(90)} |
421 | 408 |
|
422 | 409 | mux.HandleFunc("/enterprises/e/actions/permissions/artifact-and-log-retention", func(w http.ResponseWriter, r *http.Request) { |
423 | | - var v *ArtifactPeriodOpt |
424 | | - assertNilError(t, json.NewDecoder(r.Body).Decode(&v)) |
425 | | - |
426 | 410 | testMethod(t, r, "PUT") |
427 | | - if !cmp.Equal(v, input) { |
428 | | - t.Errorf("Request body = %+v, want %+v", v, input) |
429 | | - } |
| 411 | + testJSONBody(t, r, input) |
430 | 412 | w.WriteHeader(http.StatusNoContent) |
431 | 413 | }) |
432 | 414 |
|
@@ -492,13 +474,8 @@ func TestActionsService_UpdateSelfHostedRunnerPermissionsInEnterprise(t *testing |
492 | 474 | input := &SelfHostRunnerPermissionsEnterprise{DisableSelfHostedRunnersForAllOrgs: Ptr(false)} |
493 | 475 |
|
494 | 476 | mux.HandleFunc("/enterprises/e/actions/permissions/self-hosted-runners", func(w http.ResponseWriter, r *http.Request) { |
495 | | - var v *SelfHostRunnerPermissionsEnterprise |
496 | | - assertNilError(t, json.NewDecoder(r.Body).Decode(&v)) |
497 | | - |
498 | 477 | testMethod(t, r, "PUT") |
499 | | - if !cmp.Equal(v, input) { |
500 | | - t.Errorf("Request body = %+v, want %+v", v, input) |
501 | | - } |
| 478 | + testJSONBody(t, r, input) |
502 | 479 | w.WriteHeader(http.StatusNoContent) |
503 | 480 | }) |
504 | 481 |
|
@@ -573,13 +550,8 @@ func TestActionsService_UpdatePrivateRepoForkPRWorkflowSettingsInEnterprise(t *t |
573 | 550 | } |
574 | 551 |
|
575 | 552 | mux.HandleFunc("/enterprises/e/actions/permissions/fork-pr-workflows-private-repos", func(w http.ResponseWriter, r *http.Request) { |
576 | | - var v *WorkflowsPermissionsOpt |
577 | | - assertNilError(t, json.NewDecoder(r.Body).Decode(&v)) |
578 | | - |
579 | 553 | testMethod(t, r, "PUT") |
580 | | - if !cmp.Equal(v, input) { |
581 | | - t.Errorf("Request body = %+v, want %+v", v, input) |
582 | | - } |
| 554 | + testJSONBody(t, r, input) |
583 | 555 | w.WriteHeader(http.StatusNoContent) |
584 | 556 | }) |
585 | 557 |
|
@@ -645,13 +617,8 @@ func TestActionsService_UpdateEnterpriseForkPRContributorApprovalPermissions(t * |
645 | 617 | input := ContributorApprovalPermissions{ApprovalPolicy: "require_approval"} |
646 | 618 |
|
647 | 619 | mux.HandleFunc("/enterprises/e/actions/permissions/fork-pr-contributor-approval", func(w http.ResponseWriter, r *http.Request) { |
648 | | - var v *ContributorApprovalPermissions |
649 | | - assertNilError(t, json.NewDecoder(r.Body).Decode(&v)) |
650 | | - |
651 | 620 | testMethod(t, r, "PUT") |
652 | | - if !cmp.Equal(v, &input) { |
653 | | - t.Errorf("Request body = %+v, want %+v", v, &input) |
654 | | - } |
| 621 | + testJSONBody(t, r, input) |
655 | 622 | w.WriteHeader(http.StatusNoContent) |
656 | 623 | }) |
657 | 624 |
|
|
0 commit comments