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
6 changes: 3 additions & 3 deletions github/actions_oidc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func TestActionsService_SetOrgOIDCSubjectClaimCustomTemplate(t *testing.T) {
mux.HandleFunc("/orgs/o/actions/oidc/customization/sub", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")
testHeader(t, r, "Content-Type", "application/json")
testBody(t, r, `{"include_claim_keys":["repo","context"]}`+"\n")
testJSONBody(t, r, `{"include_claim_keys":["repo","context"]}`)
w.WriteHeader(http.StatusCreated)
})

Expand Down Expand Up @@ -122,7 +122,7 @@ func TestActionsService_SetRepoOIDCSubjectClaimCustomTemplate(t *testing.T) {
mux.HandleFunc("/repos/o/r/actions/oidc/customization/sub", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")
testHeader(t, r, "Content-Type", "application/json")
testBody(t, r, `{"use_default":false,"include_claim_keys":["repo","context"]}`+"\n")
testJSONBody(t, r, `{"use_default":false,"include_claim_keys":["repo","context"]}`)
w.WriteHeader(http.StatusCreated)
})

Expand Down Expand Up @@ -155,7 +155,7 @@ func TestActionService_SetRepoOIDCSubjectClaimCustomTemplateToDefault(t *testing
mux.HandleFunc("/repos/o/r/actions/oidc/customization/sub", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")
testHeader(t, r, "Content-Type", "application/json")
testBody(t, r, `{"use_default":true}`+"\n")
testJSONBody(t, r, `{"use_default":true}`)
w.WriteHeader(http.StatusCreated)
})

Expand Down
56 changes: 12 additions & 44 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)
}
testJSONBody(t, r, `{"enabled_organizations":"all","allowed_actions":"selected"}`)

fmt.Fprint(w, `{"enabled_organizations": "all", "allowed_actions": "selected"}`)
})
Expand Down Expand Up @@ -143,7 +137,7 @@ func TestActionsService_SetEnabledOrgsInEnterprise(t *testing.T) {
mux.HandleFunc("/enterprises/e/actions/permissions/organizations", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")
testHeader(t, r, "Content-Type", "application/json")
testBody(t, r, `{"selected_organization_ids":[123,1234]}`+"\n")
testJSONBody(t, r, `{"selected_organization_ids":[123,1234]}`)
w.WriteHeader(http.StatusNoContent)
})

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)
}
testJSONBody(t, r, `{"github_owned_allowed":true,"verified_allowed":false,"patterns_allowed":["a/b"]}`)

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)
}
testJSONBody(t, r, `{"default_workflow_permissions":"read","can_approve_pull_request_reviews":true}`)

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)
}
testJSONBody(t, r, `{"days":90}`)

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)
}
testJSONBody(t, r, `{"disable_self_hosted_runners_for_all_orgs":false}`)

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)
}
testJSONBody(t, r, `{"run_workflows_from_fork_pull_requests":true,"send_write_tokens_to_workflows":false,"send_secrets_and_variables":true}`)

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)
}
testJSONBody(t, r, `{"approval_policy":"require_approval"}`)

w.WriteHeader(http.StatusNoContent)
})

Expand Down
58 changes: 13 additions & 45 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)
}
testJSONBody(t, r, `{"enabled_repositories":"all","allowed_actions":"selected","sha_pinning_required":true}`)

fmt.Fprint(w, `{"enabled_repositories": "all", "allowed_actions": "selected", "sha_pinning_required": true}`)
})
Expand Down Expand Up @@ -143,7 +137,7 @@ func TestActionsService_SetEnabledReposInOrg(t *testing.T) {
mux.HandleFunc("/orgs/o/actions/permissions/repositories", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")
testHeader(t, r, "Content-Type", "application/json")
testBody(t, r, `{"selected_repository_ids":[123,1234]}`+"\n")
testJSONBody(t, r, `{"selected_repository_ids":[123,1234]}`)
w.WriteHeader(http.StatusNoContent)
})

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)
}
testJSONBody(t, r, `{"github_owned_allowed":true,"verified_allowed":false,"patterns_allowed":["a/b"]}`)

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)
}
testJSONBody(t, r, `{"default_workflow_permissions":"read","can_approve_pull_request_reviews":true}`)

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)
}
testJSONBody(t, r, `{"days":90}`)

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)
}
testJSONBody(t, r, `{"enabled_repositories":"selected"}`)

w.WriteHeader(http.StatusNoContent)
})

Expand Down Expand Up @@ -619,7 +595,7 @@ func TestActionsService_SetRepositoriesSelfHostedRunnersAllowedInOrganization(t
mux.HandleFunc("/orgs/o/actions/permissions/self-hosted-runners/repositories", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")
testHeader(t, r, "Content-Type", "application/json")
testBody(t, r, `{"selected_repository_ids":[123,1234]}`+"\n")
testJSONBody(t, r, `{"selected_repository_ids":[123,1234]}`)
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)
}
testJSONBody(t, r, `{"run_workflows_from_fork_pull_requests":true,"send_write_tokens_to_workflows":false,"send_secrets_and_variables":true}`)

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)
}
testJSONBody(t, r, `{"approval_policy":"require_approval"}`)

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)
}
testJSONBody(t, r, `{"name":"test","runner_group_id":1,"labels":["one","two"]}`)

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)
}
testJSONBody(t, r, `{"name":"test","runner_group_id":1,"labels":["one","two"]}`)

fmt.Fprint(w, `{"encoded_jit_config":"foo"}`)
})
Expand Down
8 changes: 4 additions & 4 deletions github/actions_secrets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func TestActionsService_CreateOrUpdateRepoSecret(t *testing.T) {
mux.HandleFunc("/repos/o/r/actions/secrets/NAME", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")
testHeader(t, r, "Content-Type", "application/json")
testBody(t, r, `{"key_id":"1234","encrypted_value":"QIv="}`+"\n")
testJSONBody(t, r, `{"key_id":"1234","encrypted_value":"QIv="}`)
w.WriteHeader(http.StatusCreated)
})

Expand Down Expand Up @@ -476,7 +476,7 @@ func TestActionsService_CreateOrUpdateOrgSecret(t *testing.T) {
mux.HandleFunc("/orgs/o/actions/secrets/NAME", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")
testHeader(t, r, "Content-Type", "application/json")
testBody(t, r, `{"key_id":"1234","encrypted_value":"QIv=","visibility":"selected","selected_repository_ids":[1296269,1269280]}`+"\n")
testJSONBody(t, r, `{"key_id":"1234","encrypted_value":"QIv=","visibility":"selected","selected_repository_ids":[1296269,1269280]}`)
w.WriteHeader(http.StatusCreated)
})

Expand Down Expand Up @@ -556,7 +556,7 @@ func TestActionsService_SetSelectedReposForOrgSecret(t *testing.T) {
mux.HandleFunc("/orgs/o/actions/secrets/NAME/repositories", func(_ http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")
testHeader(t, r, "Content-Type", "application/json")
testBody(t, r, `{"selected_repository_ids":[64780797]}`+"\n")
testJSONBody(t, r, `{"selected_repository_ids":[64780797]}`)
})

ctx := t.Context()
Expand Down Expand Up @@ -820,7 +820,7 @@ func TestActionsService_CreateOrUpdateEnvSecret(t *testing.T) {
mux.HandleFunc("/repositories/1/environments/e/secrets/secret", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")
testHeader(t, r, "Content-Type", "application/json")
testBody(t, r, `{"key_id":"1234","encrypted_value":"QIv="}`+"\n")
testJSONBody(t, r, `{"key_id":"1234","encrypted_value":"QIv="}`)
w.WriteHeader(http.StatusCreated)
})

Expand Down
Loading
Loading