Skip to content

Commit

Permalink
Do not destroy the repository when you change the repository name (#699)
Browse files Browse the repository at this point in the history
* Don't make name a force new field for the github_repository resource

* Add a unit test

* fix up lint
  • Loading branch information
k24dizzle authored Apr 17, 2021
1 parent aa0422b commit fc0363a
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
1 change: 0 additions & 1 deletion github/resource_github_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ func resourceGithubRepository() *schema.Resource {
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"description": {
Type: schema.TypeString,
Expand Down
62 changes: 62 additions & 0 deletions github/resource_github_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,68 @@ func TestAccGithubRepositories(t *testing.T) {

})

t.Run("updates a repositories name without error", func(t *testing.T) {

oldName := fmt.Sprintf(`tf-acc-test-rename-%[1]s`, randomID)
newName := fmt.Sprintf(`%[1]s-renamed`, oldName)

config := fmt.Sprintf(`
resource "github_repository" "test" {
name = "%[1]s"
description = "Terraform acceptance tests %[2]s"
}
`, oldName, randomID)

checks := map[string]resource.TestCheckFunc{
"before": resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"github_repository.test", "name",
oldName,
),
),
"after": resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"github_repository.test", "name",
newName,
),
),
}

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: checks["before"],
},
{
// Rename the repo to something else
Config: strings.Replace(
config,
oldName,
newName, 1),
Check: checks["after"],
},
},
})
}

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("imports repositories without error", func(t *testing.T) {

config := fmt.Sprintf(`
Expand Down

0 comments on commit fc0363a

Please sign in to comment.