@@ -9,11 +9,9 @@ import (
99)
1010
1111func TestAccGithubBranchDefault (t * testing.T ) {
12-
1312 randomID := acctest .RandStringFromCharSet (5 , acctest .CharSetAlphaNum )
1413
1514 t .Run ("creates and manages branch defaults" , func (t * testing.T ) {
16-
1715 config := fmt .Sprintf (`
1816
1917 resource "github_repository" "test" {
@@ -62,22 +60,20 @@ func TestAccGithubBranchDefault(t *testing.T) {
6260 t .Run ("with an organization account" , func (t * testing.T ) {
6361 testCase (t , organization )
6462 })
65-
6663 })
6764
6865 t .Run ("replaces the default_branch of a repository" , func (t * testing.T ) {
69-
7066 config := fmt .Sprintf (`
7167 resource "github_repository" "test" {
7268 name = "tf-acc-test-%s"
7369 auto_init = true
7470 }
75-
71+
7672 resource "github_branch" "test" {
7773 repository = github_repository.test.name
7874 branch = "test"
7975 }
80-
76+
8177 resource "github_branch_default" "test"{
8278 repository = github_repository.test.name
8379 branch = github_branch.test.branch
@@ -116,17 +112,67 @@ func TestAccGithubBranchDefault(t *testing.T) {
116112 t .Run ("with an organization account" , func (t * testing.T ) {
117113 testCase (t , organization )
118114 })
115+ })
116+
117+ t .Run ("creates and manages branch defaults even if rename is set" , func (t * testing.T ) {
118+ config := fmt .Sprintf (`
119+
120+ resource "github_repository" "test" {
121+ name = "tf-acc-test-%s"
122+ auto_init = true
123+ }
124+
125+ resource "github_branch_default" "test" {
126+ repository = github_repository.test.name
127+ branch = "main"
128+ rename = true
129+ }
130+ ` , randomID )
131+
132+ check := resource .ComposeTestCheckFunc (
133+ resource .TestCheckResourceAttr (
134+ "github_branch_default.test" , "branch" ,
135+ "main" ,
136+ ),
137+ resource .TestCheckResourceAttr (
138+ "github_branch_default.test" , "repository" ,
139+ fmt .Sprintf ("tf-acc-test-%s" , randomID ),
140+ ),
141+ )
142+
143+ testCase := func (t * testing.T , mode string ) {
144+ resource .Test (t , resource.TestCase {
145+ PreCheck : func () { skipUnlessMode (t , mode ) },
146+ Providers : testAccProviders ,
147+ Steps : []resource.TestStep {
148+ {
149+ Config : config ,
150+ Check : check ,
151+ },
152+ },
153+ })
154+ }
155+
156+ t .Run ("with an anonymous account" , func (t * testing.T ) {
157+ t .Skip ("anonymous account not supported for this operation" )
158+ })
159+
160+ t .Run ("with an individual account" , func (t * testing.T ) {
161+ testCase (t , individual )
162+ })
119163
164+ t .Run ("with an organization account" , func (t * testing.T ) {
165+ testCase (t , organization )
166+ })
120167 })
121168
122169 t .Run ("replaces the default_branch of a repository without creating a branch resource prior to" , func (t * testing.T ) {
123-
124170 config := fmt .Sprintf (`
125171 resource "github_repository" "test" {
126172 name = "tf-acc-test-%s"
127173 auto_init = true
128174 }
129-
175+
130176 resource "github_branch_default" "test"{
131177 repository = github_repository.test.name
132178 branch = "development"
@@ -166,6 +212,5 @@ func TestAccGithubBranchDefault(t *testing.T) {
166212 t .Run ("with an organization account" , func (t * testing.T ) {
167213 testCase (t , organization )
168214 })
169-
170215 })
171216}
0 commit comments