Skip to content

Commit

Permalink
fix doc for integrations#2054: Clarify how allows_force_pushes is wor…
Browse files Browse the repository at this point in the history
…king
  • Loading branch information
bpaquet committed Feb 7, 2024
1 parent 414299f commit b4235f7
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
58 changes: 58 additions & 0 deletions github/resource_github_branch_protection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,64 @@ func TestAccGithubBranchProtection(t *testing.T) {

})

t.Run("configures allow force push with a team as bypasser", func(t *testing.T) {

config := fmt.Sprintf(`
resource "github_repository" "test" {
name = "tf-acc-test-%s"
auto_init = true
}
resource "github_team" "test" {
name = "tf-acc-test-%s"
}
resource "github_team_repository" "test" {
team_id = github_team.test.id
repository = github_repository.test.name
permission = "admin"
}
resource "github_branch_protection" "test" {
repository_id = github_repository.test.node_id
pattern = "main"
force_push_bypassers = [
"%s/${github_team.test.slug}"
]
}
`, randomID, randomID, testOrganization)

check := resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(
"github_branch_protection.test", "force_push_bypassers.#", "1",
),
resource.TestCheckResourceAttr(
"github_branch_protection.test", "allows_force_pushes", "false",
),
)

testCase := func(t *testing.T, mode string) {
resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessMode(t, mode) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: config,
Check: check,
},
},
})
}

// This test only works with an organization account
t.Run("with an organization account", func(t *testing.T) {
testCase(t, organization)
})

})

t.Run("configures empty list of force push bypassers", func(t *testing.T) {

config := fmt.Sprintf(`
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/branch_protection.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ The following arguments are supported:
* `push_restrictions` - (Optional) The list of actor Names/IDs that may push to the branch. Actor names must either begin with a "/" for users or the organization name followed by a "/" for teams.
* `force_push_bypassers` - (Optional) The list of actor Names/IDs that are allowed to bypass force push restrictions. Actor names must either begin with a "/" for users or the organization name followed by a "/" for teams.
* `allows_deletions` - (Optional) Boolean, setting this to `true` to allow the branch to be deleted.
* `allows_force_pushes` - (Optional) Boolean, setting this to `true` to allow force pushes on the branch.
* `allows_force_pushes` - (Optional) Boolean, setting this to `true` to allow force pushes on the branch to everyone. Set it to `false` if you specify `force_push_bypassers`.
* `blocks_creations` - (Optional) Boolean, setting this to `true` to block creating the branch.
* `lock_branch` - (Optional) Boolean, Setting this to `true` will make the branch read-only and preventing any pushes to it. Defaults to `false`

Expand Down

0 comments on commit b4235f7

Please sign in to comment.