@@ -76,6 +76,70 @@ func TestAccGithubBranch(t *testing.T) {
7676
7777 })
7878
79+ t .Run ("creates a branch named main directly and a repository with a gitignore_template" , func (t * testing.T ) {
80+
81+ config := fmt .Sprintf (`
82+ resource "github_repository" "test" {
83+ name = "tf-acc-test-%[1]s"
84+ auto_init = true
85+ gitignore_template = "Python"
86+ }
87+
88+ resource "github_branch" "test" {
89+ repository = github_repository.test.id
90+ branch = "main"
91+ }
92+ ` , randomID )
93+
94+ check := resource .ComposeTestCheckFunc (
95+ resource .TestMatchResourceAttr (
96+ "github_branch.test" , "id" ,
97+ regexp .MustCompile (fmt .Sprintf ("tf-acc-test-%s:test" , randomID )),
98+ ),
99+ )
100+
101+ testCase := func (t * testing.T , mode string ) {
102+ resource .Test (t , resource.TestCase {
103+ PreCheck : func () { skipUnlessMode (t , mode ) },
104+ Providers : testAccProviders ,
105+ Steps : []resource.TestStep {
106+ {
107+ Config : config ,
108+ Check : check ,
109+ },
110+ {
111+ ResourceName : "github_branch.test" ,
112+ ImportState : true ,
113+ ImportStateId : fmt .Sprintf ("tf-acc-test-%s:test" , randomID ),
114+ ImportStateVerify : true ,
115+ ImportStateVerifyIgnore : []string {"source_sha" },
116+ },
117+ {
118+ ResourceName : "github_branch.test" ,
119+ ImportState : true ,
120+ ImportStateId : fmt .Sprintf ("tf-acc-test-%s:nonsense" , randomID ),
121+ ExpectError : regexp .MustCompile (
122+ "Repository tf-acc-test-[a-z0-9]* does not have a branch named nonsense." ,
123+ ),
124+ },
125+ },
126+ })
127+ }
128+
129+ t .Run ("with an anonymous account" , func (t * testing.T ) {
130+ t .Skip ("anonymous account not supported for this operation" )
131+ })
132+
133+ t .Run ("with an individual account" , func (t * testing.T ) {
134+ testCase (t , individual )
135+ })
136+
137+ t .Run ("with an organization account" , func (t * testing.T ) {
138+ testCase (t , organization )
139+ })
140+
141+ })
142+
79143 t .Run ("creates a branch from a source branch" , func (t * testing.T ) {
80144
81145 config := fmt .Sprintf (`
0 commit comments