Skip to content
This repository has been archived by the owner on Jan 8, 2021. It is now read-only.

Commit

Permalink
add test for deletions and force pushes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Udit committed Dec 10, 2020
1 parent 09a48fb commit edd6395
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions github/resource_github_branch_protection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,65 @@ func TestAccGithubBranchProtection(t *testing.T) {
})

})

t.Run("configures force pushes and deletions", func(t *testing.T) {

config := fmt.Sprintf(`
resource "github_repository" "test" {
name = "tf-acc-test-%s"
auto_init = true
}
data "github_user" "test" {
username = "%s"
}
resource "github_branch_protection" "test" {
repository_id = github_repository.test.name
pattern = "main"
allows_deletions = true
allows_force_pushes = true
}
`, randomID, testOwnerFunc())

check := resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(
"github_branch_protection.test", "allows_deletions", "true",
),
resource.TestCheckResourceAttr(
"github_branch_protection.test", "allows_force_pushes", "true",
),
)

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,
},
},
})
}

t.Run("with an anonymous account", func(t *testing.T) {
t.Skip("anonymous account not supported for this operation")
})

t.Run("with an individual account", func(t *testing.T) {
t.Skip("individual account not supported for this operation")
})

t.Run("with an organization account", func(t *testing.T) {
testCase(t, organization)
})

})

}

func branchProtectionImportStateIdFunc(repo, pattern string) resource.ImportStateIdFunc {
Expand Down

0 comments on commit edd6395

Please sign in to comment.