Skip to content

Commit

Permalink
Added Integration test to prove functionality
Browse files Browse the repository at this point in the history
Co-authored-by: JoshWilsonWTG <[email protected]>
  • Loading branch information
CEbbinghaus and JoshWilsonWTG committed Dec 3, 2024
1 parent 4ab392a commit 85abb4b
Showing 1 changed file with 122 additions and 0 deletions.
122 changes: 122 additions & 0 deletions github/resource_github_branch_default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,126 @@ func TestAccGithubBranchDefault(t *testing.T) {
})

})

t.Run("replaces the default_branch of a repository without creating a branch resource prior to", func(t *testing.T) {

config := fmt.Sprintf(`
resource "github_repository" "test" {
name = "tf-acc-test-%s"
auto_init = true
}
resource "github_branch_default" "test"{
repository = github_repository.test.name
branch = "development"
rename = true
}
`, randomID)

check := resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"github_branch_default.test", "branch",
"development",
),
)

testCase := func(t *testing.T, mode string) {

ts := githubApiMock([]*mockResponse{})
defer ts.Close()

d := resourceGithubBranchDefault().Data(nil)
meta := testAccProvider.Meta()
err := resourceGithubBranchDefaultUpdate(d, meta)

if err != nil {
t.Logf("Unexpected error: %s", err)
t.Fail()
}

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) {
testCase(t, individual)
})

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

})

t.Run("uses the rename functionality of the default_branch where the default_branch is already set as expected", func(t *testing.T) {

initial_config := fmt.Sprintf(`
resource "github_repository" "test" {
name = "tf-acc-test-%s"
auto_init = true
}
resource "github_branch_default" "test"{
repository = github_repository.test.name
branch = "main"
rename = false
}
`, randomID)

updated_config := fmt.Sprintf(`
resource "github_repository" "test" {
name = "tf-acc-test-%s"
auto_init = true
}
resource "github_branch_default" "test"{
repository = github_repository.test.name
branch = "main"
rename = true
}
`, randomID)

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

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) {
testCase(t, individual)
})

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

})
}

0 comments on commit 85abb4b

Please sign in to comment.