@@ -335,6 +335,46 @@ func TestAccGitlabProject_initializeWithReadme(t *testing.T) {
335
335
Check : resource .ComposeTestCheckFunc (
336
336
testAccCheckGitlabProjectExists ("gitlab_project.foo" , & project ),
337
337
testAccCheckGitlabProjectDefaultBranch (& project , nil ),
338
+ func (state * terraform.State ) error {
339
+ client := testAccProvider .Meta ().(* gitlab.Client )
340
+ _ , _ , err := client .RepositoryFiles .GetFile (project .ID , "README.md" , & gitlab.GetFileOptions {Ref : gitlab .String ("main" )}, nil )
341
+ if err != nil {
342
+ return fmt .Errorf ("failed to get 'README.md' file from project: %w" , err )
343
+ }
344
+
345
+ return nil
346
+ },
347
+ ),
348
+ },
349
+ },
350
+ })
351
+ }
352
+
353
+ func TestAccGitlabProject_initializeWithoutReadme (t * testing.T ) {
354
+ var project gitlab.Project
355
+ rInt := acctest .RandInt ()
356
+
357
+ resource .Test (t , resource.TestCase {
358
+ PreCheck : func () { testAccPreCheck (t ) },
359
+ Providers : testAccProviders ,
360
+ CheckDestroy : testAccCheckGitlabProjectDestroy ,
361
+ Steps : []resource.TestStep {
362
+ {
363
+ Config : testAccGitlabProjectConfigInitializeWithoutReadme (rInt ),
364
+ Check : resource .ComposeTestCheckFunc (
365
+ testAccCheckGitlabProjectExists ("gitlab_project.foo" , & project ),
366
+ func (s * terraform.State ) error {
367
+ client := testAccProvider .Meta ().(* gitlab.Client )
368
+ branches , _ , err := client .Branches .ListBranches (project .ID , nil )
369
+ if err != nil {
370
+ return fmt .Errorf ("failed to list branches: %w" , err )
371
+ }
372
+
373
+ if len (branches ) != 0 {
374
+ return fmt .Errorf ("expected no branch for new project when initialized without README; found %d" , len (branches ))
375
+ }
376
+ return nil
377
+ },
338
378
),
339
379
},
340
380
},
@@ -583,6 +623,18 @@ resource "gitlab_project" "foo" {
583
623
testAccCheckGitlabProjectDefaultBranch (& project , & testAccGitlabProjectExpectedAttributes {
584
624
DefaultBranch : "foo" ,
585
625
}),
626
+ func (state * terraform.State ) error {
627
+ client := testAccProvider .Meta ().(* gitlab.Client )
628
+
629
+ projectID := state .RootModule ().Resources ["gitlab_project.foo" ].Primary .ID
630
+
631
+ _ , _ , err := client .RepositoryFiles .GetFile (projectID , "README.md" , & gitlab.GetFileOptions {Ref : gitlab .String ("foo" )}, nil )
632
+ if err != nil {
633
+ return fmt .Errorf ("failed to get 'README.md' file from project: %w" , err )
634
+ }
635
+
636
+ return nil
637
+ },
586
638
),
587
639
},
588
640
},
@@ -1093,6 +1145,17 @@ resource "gitlab_project" "foo" {
1093
1145
` , rInt , rInt )
1094
1146
}
1095
1147
1148
+ func testAccGitlabProjectConfigInitializeWithoutReadme (rInt int ) string {
1149
+ return fmt .Sprintf (`
1150
+ resource "gitlab_project" "foo" {
1151
+ name = "foo-%d"
1152
+ path = "foo.%d"
1153
+ description = "Terraform acceptance tests"
1154
+ initialize_with_readme = false
1155
+ }
1156
+ ` , rInt , rInt )
1157
+ }
1158
+
1096
1159
func testAccGitlabProjectConfigImportURL (rInt int , importURL string ) string {
1097
1160
return fmt .Sprintf (`
1098
1161
resource "gitlab_project" "imported" {
0 commit comments