Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 11 additions & 43 deletions github/actions_permissions_enterprise_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package github

import (
"encoding/json"
"fmt"
"net/http"
"testing"
Expand Down Expand Up @@ -55,13 +54,8 @@ func TestActionsService_UpdateActionsPermissionsInEnterprise(t *testing.T) {
input := &ActionsPermissionsEnterprise{EnabledOrganizations: Ptr("all"), AllowedActions: Ptr("selected")}

mux.HandleFunc("/enterprises/e/actions/permissions", func(w http.ResponseWriter, r *http.Request) {
var v *ActionsPermissionsEnterprise
assertNilError(t, json.NewDecoder(r.Body).Decode(&v))

testMethod(t, r, "PUT")
if !cmp.Equal(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}
testBody(t, r, `{"enabled_organizations":"all","allowed_actions":"selected"}`+"\n")

fmt.Fprint(w, `{"enabled_organizations": "all", "allowed_actions": "selected"}`)
})
Expand Down Expand Up @@ -260,13 +254,8 @@ func TestActionsService_UpdateActionsAllowedInEnterprise(t *testing.T) {
input := &ActionsAllowed{GithubOwnedAllowed: Ptr(true), VerifiedAllowed: Ptr(false), PatternsAllowed: []string{"a/b"}}

mux.HandleFunc("/enterprises/e/actions/permissions/selected-actions", func(w http.ResponseWriter, r *http.Request) {
var v *ActionsAllowed
assertNilError(t, json.NewDecoder(r.Body).Decode(&v))

testMethod(t, r, "PUT")
if !cmp.Equal(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}
testBody(t, r, `{"github_owned_allowed":true,"verified_allowed":false,"patterns_allowed":["a/b"]}`+"\n")

fmt.Fprint(w, `{"github_owned_allowed":true, "verified_allowed":false, "patterns_allowed":["a/b"]}`)
})
Expand Down Expand Up @@ -338,13 +327,8 @@ func TestActionsService_UpdateDefaultWorkflowPermissionsInEnterprise(t *testing.
input := &DefaultWorkflowPermissionEnterprise{DefaultWorkflowPermissions: Ptr("read"), CanApprovePullRequestReviews: Ptr(true)}

mux.HandleFunc("/enterprises/e/actions/permissions/workflow", func(w http.ResponseWriter, r *http.Request) {
var v *DefaultWorkflowPermissionEnterprise
assertNilError(t, json.NewDecoder(r.Body).Decode(&v))

testMethod(t, r, "PUT")
if !cmp.Equal(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}
testBody(t, r, `{"default_workflow_permissions":"read","can_approve_pull_request_reviews":true}`+"\n")

fmt.Fprint(w, `{ "default_workflow_permissions": "read", "can_approve_pull_request_reviews": true }`)
})
Expand Down Expand Up @@ -420,13 +404,9 @@ func TestActionsService_UpdateArtifactAndLogRetentionPeriodInEnterprise(t *testi
input := &ArtifactPeriodOpt{Days: Ptr(90)}

mux.HandleFunc("/enterprises/e/actions/permissions/artifact-and-log-retention", func(w http.ResponseWriter, r *http.Request) {
var v *ArtifactPeriodOpt
assertNilError(t, json.NewDecoder(r.Body).Decode(&v))

testMethod(t, r, "PUT")
if !cmp.Equal(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}
testBody(t, r, `{"days":90}`+"\n")

w.WriteHeader(http.StatusNoContent)
})

Expand Down Expand Up @@ -492,13 +472,9 @@ func TestActionsService_UpdateSelfHostedRunnerPermissionsInEnterprise(t *testing
input := &SelfHostRunnerPermissionsEnterprise{DisableSelfHostedRunnersForAllOrgs: Ptr(false)}

mux.HandleFunc("/enterprises/e/actions/permissions/self-hosted-runners", func(w http.ResponseWriter, r *http.Request) {
var v *SelfHostRunnerPermissionsEnterprise
assertNilError(t, json.NewDecoder(r.Body).Decode(&v))

testMethod(t, r, "PUT")
if !cmp.Equal(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}
testBody(t, r, `{"disable_self_hosted_runners_for_all_orgs":false}`+"\n")

w.WriteHeader(http.StatusNoContent)
})

Expand Down Expand Up @@ -573,13 +549,9 @@ func TestActionsService_UpdatePrivateRepoForkPRWorkflowSettingsInEnterprise(t *t
}

mux.HandleFunc("/enterprises/e/actions/permissions/fork-pr-workflows-private-repos", func(w http.ResponseWriter, r *http.Request) {
var v *WorkflowsPermissionsOpt
assertNilError(t, json.NewDecoder(r.Body).Decode(&v))

testMethod(t, r, "PUT")
if !cmp.Equal(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}
testBody(t, r, `{"run_workflows_from_fork_pull_requests":true,"send_write_tokens_to_workflows":false,"send_secrets_and_variables":true}`+"\n")

w.WriteHeader(http.StatusNoContent)
})

Expand Down Expand Up @@ -645,13 +617,9 @@ func TestActionsService_UpdateEnterpriseForkPRContributorApprovalPermissions(t *
input := ContributorApprovalPermissions{ApprovalPolicy: "require_approval"}

mux.HandleFunc("/enterprises/e/actions/permissions/fork-pr-contributor-approval", func(w http.ResponseWriter, r *http.Request) {
var v *ContributorApprovalPermissions
assertNilError(t, json.NewDecoder(r.Body).Decode(&v))

testMethod(t, r, "PUT")
if !cmp.Equal(v, &input) {
t.Errorf("Request body = %+v, want %+v", v, &input)
}
testBody(t, r, `{"approval_policy":"require_approval"}`+"\n")

w.WriteHeader(http.StatusNoContent)
})

Expand Down
54 changes: 11 additions & 43 deletions github/actions_permissions_orgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package github

import (
"encoding/json"
"fmt"
"net/http"
"testing"
Expand Down Expand Up @@ -55,13 +54,8 @@ func TestActionsService_UpdateActionsPermissions(t *testing.T) {
input := &ActionsPermissions{EnabledRepositories: Ptr("all"), AllowedActions: Ptr("selected"), SHAPinningRequired: Ptr(true)}

mux.HandleFunc("/orgs/o/actions/permissions", func(w http.ResponseWriter, r *http.Request) {
var v *ActionsPermissions
assertNilError(t, json.NewDecoder(r.Body).Decode(&v))

testMethod(t, r, "PUT")
if !cmp.Equal(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}
testBody(t, r, `{"enabled_repositories":"all","allowed_actions":"selected","sha_pinning_required":true}`+"\n")

fmt.Fprint(w, `{"enabled_repositories": "all", "allowed_actions": "selected", "sha_pinning_required": true}`)
})
Expand Down Expand Up @@ -260,13 +254,8 @@ func TestActionsService_UpdateActionsAllowed(t *testing.T) {
input := &ActionsAllowed{GithubOwnedAllowed: Ptr(true), VerifiedAllowed: Ptr(false), PatternsAllowed: []string{"a/b"}}

mux.HandleFunc("/orgs/o/actions/permissions/selected-actions", func(w http.ResponseWriter, r *http.Request) {
var v *ActionsAllowed
assertNilError(t, json.NewDecoder(r.Body).Decode(&v))

testMethod(t, r, "PUT")
if !cmp.Equal(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}
testBody(t, r, `{"github_owned_allowed":true,"verified_allowed":false,"patterns_allowed":["a/b"]}`+"\n")

fmt.Fprint(w, `{"github_owned_allowed":true, "verified_allowed":false, "patterns_allowed":["a/b"]}`)
})
Expand Down Expand Up @@ -380,13 +369,8 @@ func TestActionsService_UpdateDefaultWorkflowPermissionsInOrganization(t *testin
input := &DefaultWorkflowPermissionOrganization{DefaultWorkflowPermissions: Ptr("read"), CanApprovePullRequestReviews: Ptr(true)}

mux.HandleFunc("/orgs/o/actions/permissions/workflow", func(w http.ResponseWriter, r *http.Request) {
var v *DefaultWorkflowPermissionOrganization
assertNilError(t, json.NewDecoder(r.Body).Decode(&v))

testMethod(t, r, "PUT")
if !cmp.Equal(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}
testBody(t, r, `{"default_workflow_permissions":"read","can_approve_pull_request_reviews":true}`+"\n")

fmt.Fprint(w, `{ "default_workflow_permissions": "read", "can_approve_pull_request_reviews": true }`)
})
Expand Down Expand Up @@ -462,13 +446,9 @@ func TestActionsService_UpdateArtifactAndLogRetentionPeriodInOrganization(t *tes
input := &ArtifactPeriodOpt{Days: Ptr(90)}

mux.HandleFunc("/orgs/o/actions/permissions/artifact-and-log-retention", func(w http.ResponseWriter, r *http.Request) {
var v *ArtifactPeriodOpt
assertNilError(t, json.NewDecoder(r.Body).Decode(&v))

testMethod(t, r, "PUT")
if !cmp.Equal(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}
testBody(t, r, `{"days":90}`+"\n")

w.WriteHeader(http.StatusNoContent)
})

Expand Down Expand Up @@ -537,13 +517,9 @@ func TestActionsService_UpdateSelfHostedRunnersSettingsInOrganization(t *testing
input := &SelfHostedRunnersSettingsOrganizationOpt{EnabledRepositories: Ptr("selected")}

mux.HandleFunc("/orgs/o/actions/permissions/self-hosted-runners", func(w http.ResponseWriter, r *http.Request) {
var v *SelfHostedRunnersSettingsOrganizationOpt
assertNilError(t, json.NewDecoder(r.Body).Decode(&v))

testMethod(t, r, "PUT")
if !cmp.Equal(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}
testBody(t, r, `{"enabled_repositories":"selected"}`+"\n")

w.WriteHeader(http.StatusNoContent)
})

Expand Down Expand Up @@ -745,13 +721,9 @@ func TestActionsService_UpdatePrivateRepoForkPRWorkflowSettingsInOrganization(t
}

mux.HandleFunc("/orgs/o/actions/permissions/fork-pr-workflows-private-repos", func(w http.ResponseWriter, r *http.Request) {
var v *WorkflowsPermissionsOpt
assertNilError(t, json.NewDecoder(r.Body).Decode(&v))

testMethod(t, r, "PUT")
if !cmp.Equal(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}
testBody(t, r, `{"run_workflows_from_fork_pull_requests":true,"send_write_tokens_to_workflows":false,"send_secrets_and_variables":true}`+"\n")

w.WriteHeader(http.StatusNoContent)
})

Expand Down Expand Up @@ -817,13 +789,9 @@ func TestActionsService_UpdateOrganizationForkPRContributorApprovalPermissions(t
input := ContributorApprovalPermissions{ApprovalPolicy: "require_approval"}

mux.HandleFunc("/orgs/o/actions/permissions/fork-pr-contributor-approval", func(w http.ResponseWriter, r *http.Request) {
var v *ContributorApprovalPermissions
assertNilError(t, json.NewDecoder(r.Body).Decode(&v))

testMethod(t, r, "PUT")
if !cmp.Equal(v, &input) {
t.Errorf("Request body = %+v, want %+v", v, &input)
}
testBody(t, r, `{"approval_policy":"require_approval"}`+"\n")

w.WriteHeader(http.StatusNoContent)
})

Expand Down
15 changes: 2 additions & 13 deletions github/actions_runners_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package github

import (
"encoding/json"
"fmt"
"net/http"
"testing"
Expand Down Expand Up @@ -63,13 +62,8 @@ func TestActionsService_GenerateOrgJITConfig(t *testing.T) {
input := &GenerateJITConfigRequest{Name: "test", RunnerGroupID: 1, Labels: []string{"one", "two"}}

mux.HandleFunc("/orgs/o/actions/runners/generate-jitconfig", func(w http.ResponseWriter, r *http.Request) {
var v *GenerateJITConfigRequest
assertNilError(t, json.NewDecoder(r.Body).Decode(&v))

testMethod(t, r, "POST")
if !cmp.Equal(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}
testBody(t, r, `{"name":"test","runner_group_id":1,"labels":["one","two"]}`+"\n")

fmt.Fprint(w, `{"encoded_jit_config":"foo"}`)
})
Expand Down Expand Up @@ -107,13 +101,8 @@ func TestActionsService_GenerateRepoJITConfig(t *testing.T) {
input := &GenerateJITConfigRequest{Name: "test", RunnerGroupID: 1, Labels: []string{"one", "two"}}

mux.HandleFunc("/repos/o/r/actions/runners/generate-jitconfig", func(w http.ResponseWriter, r *http.Request) {
var v *GenerateJITConfigRequest
assertNilError(t, json.NewDecoder(r.Body).Decode(&v))

testMethod(t, r, "POST")
if !cmp.Equal(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}
testBody(t, r, `{"name":"test","runner_group_id":1,"labels":["one","two"]}`+"\n")

fmt.Fprint(w, `{"encoded_jit_config":"foo"}`)
})
Expand Down
8 changes: 1 addition & 7 deletions github/actions_workflow_runs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package github

import (
"encoding/json"
"errors"
"fmt"
"net/http"
Expand Down Expand Up @@ -1604,13 +1603,8 @@ func TestActionService_PendingDeployments(t *testing.T) {
input := &PendingDeploymentsRequest{EnvironmentIDs: []int64{3, 4}, State: "approved", Comment: ""}

mux.HandleFunc("/repos/o/r/actions/runs/399444496/pending_deployments", func(w http.ResponseWriter, r *http.Request) {
var v *PendingDeploymentsRequest
assertNilError(t, json.NewDecoder(r.Body).Decode(&v))

testMethod(t, r, "POST")
if !cmp.Equal(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}
testBody(t, r, `{"environment_ids":[3,4],"state":"approved","comment":""}`+"\n")

fmt.Fprint(w, `[{"id":1}, {"id":2}]`)
})
Expand Down
29 changes: 4 additions & 25 deletions github/actions_workflows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package github

import (
"encoding/json"
"fmt"
"net/http"
"testing"
Expand Down Expand Up @@ -242,13 +241,8 @@ func TestActionsService_CreateWorkflowDispatchEventByID(t *testing.T) {
},
}
mux.HandleFunc("/repos/o/r/actions/workflows/72844/dispatches", func(w http.ResponseWriter, r *http.Request) {
var v CreateWorkflowDispatchEventRequest
assertNilError(t, json.NewDecoder(r.Body).Decode(&v))

testMethod(t, r, "POST")
if !cmp.Equal(v, event) {
t.Errorf("Request body = %+v, want %+v", v, event)
}
testBody(t, r, `{"ref":"d4cfb6e7","inputs":{"key":"value"},"return_run_details":true}`+"\n")

w.WriteHeader(http.StatusOK)
fmt.Fprint(w, `{"workflow_run_id":1,"run_url":"https://api.github.com/repos/o/r/actions/runs/1","html_url":"https://github.com/o/r/actions/runs/1"}`)
Expand Down Expand Up @@ -303,13 +297,8 @@ func TestActionsService_CreateWorkflowDispatchEventByFileName(t *testing.T) {
},
}
mux.HandleFunc("/repos/o/r/actions/workflows/main.yml/dispatches", func(w http.ResponseWriter, r *http.Request) {
var v CreateWorkflowDispatchEventRequest
assertNilError(t, json.NewDecoder(r.Body).Decode(&v))

testMethod(t, r, "POST")
if !cmp.Equal(v, event) {
t.Errorf("Request body = %+v, want %+v", v, event)
}
testBody(t, r, `{"ref":"d4cfb6e7","inputs":{"key":"value"},"return_run_details":true}`+"\n")

w.WriteHeader(http.StatusOK)
fmt.Fprint(w, `{"workflow_run_id":1,"run_url":"https://api.github.com/repos/o/r/actions/runs/1","html_url":"https://github.com/o/r/actions/runs/1"}`)
Expand Down Expand Up @@ -363,13 +352,8 @@ func TestActionsService_CreateWorkflowDispatchEventByID_noRunDetails(t *testing.
},
}
mux.HandleFunc("/repos/o/r/actions/workflows/72844/dispatches", func(w http.ResponseWriter, r *http.Request) {
var v CreateWorkflowDispatchEventRequest
assertNilError(t, json.NewDecoder(r.Body).Decode(&v))

testMethod(t, r, "POST")
if !cmp.Equal(v, event) {
t.Errorf("Request body = %+v, want %+v", v, event)
}
testBody(t, r, `{"ref":"d4cfb6e7","inputs":{"key":"value"}}`+"\n")

w.WriteHeader(http.StatusNoContent)
})
Expand All @@ -396,13 +380,8 @@ func TestActionsService_CreateWorkflowDispatchEventByFileName_noRunDetails(t *te
},
}
mux.HandleFunc("/repos/o/r/actions/workflows/main.yml/dispatches", func(w http.ResponseWriter, r *http.Request) {
var v CreateWorkflowDispatchEventRequest
assertNilError(t, json.NewDecoder(r.Body).Decode(&v))

testMethod(t, r, "POST")
if !cmp.Equal(v, event) {
t.Errorf("Request body = %+v, want %+v", v, event)
}
testBody(t, r, `{"ref":"d4cfb6e7","inputs":{"key":"value"}}`+"\n")

w.WriteHeader(http.StatusNoContent)
})
Expand Down
8 changes: 1 addition & 7 deletions github/activity_notifications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package github

import (
"encoding/json"
"fmt"
"net/http"
"testing"
Expand Down Expand Up @@ -313,13 +312,8 @@ func TestActivityService_SetThreadSubscription(t *testing.T) {
input := &Subscription{Subscribed: Ptr(true)}

mux.HandleFunc("/notifications/threads/1/subscription", func(w http.ResponseWriter, r *http.Request) {
var v *Subscription
assertNilError(t, json.NewDecoder(r.Body).Decode(&v))

testMethod(t, r, "PUT")
if !cmp.Equal(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}
testBody(t, r, `{"subscribed":true}`+"\n")

fmt.Fprint(w, `{"ignored":true}`)
})
Expand Down
Loading
Loading