Skip to content

Commit 7a6a188

Browse files
committed
Test creating project in group without default branch protection. Closes #759, #760
Closes #759 Closes #760
1 parent 087f021 commit 7a6a188

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

internal/provider/resource_gitlab_project.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,8 +600,8 @@ func resourceGitlabProjectCreate(ctx context.Context, d *schema.ResourceData, me
600600
}
601601

602602
log.Printf("[DEBUG] check for protection on old default branch %q for project %q", oldDefaultBranch, d.Id())
603-
branch, resp, err := client.ProtectedBranches.GetProtectedBranch(project.ID, oldDefaultBranch, gitlab.WithContext(ctx))
604-
if err != nil && resp.StatusCode != http.StatusNotFound {
603+
branch, _, err := client.ProtectedBranches.GetProtectedBranch(project.ID, oldDefaultBranch, gitlab.WithContext(ctx))
604+
if err != nil && !is404(err) {
605605
return diag.Errorf("Failed to check for protected default branch %q for project %q: %v", oldDefaultBranch, d.Id(), err)
606606
}
607607
if branch == nil {

internal/provider/resource_gitlab_project_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,23 @@ member_check = false
411411
})
412412
}
413413

414+
func TestAccGitlabProject_groupWithoutDefaultBranchProtection(t *testing.T) {
415+
var project gitlab.Project
416+
rInt := acctest.RandInt()
417+
418+
resource.Test(t, resource.TestCase{
419+
PreCheck: func() { testAccPreCheck(t) },
420+
ProviderFactories: providerFactories,
421+
CheckDestroy: testAccCheckGitlabProjectDestroy,
422+
Steps: []resource.TestStep{
423+
{
424+
Config: testAccGitlabProjectConfigWithoutDefaultBranchProtection(rInt),
425+
Check: testAccCheckGitlabProjectExists("gitlab_project.foo", &project),
426+
},
427+
},
428+
})
429+
}
430+
414431
func TestAccGitlabProject_IssueMergeRequestTemplates(t *testing.T) {
415432
var project gitlab.Project
416433
rInt := acctest.RandInt()
@@ -1075,6 +1092,23 @@ resource "gitlab_project" "foo" {
10751092
`, rInt, rInt, rInt)
10761093
}
10771094

1095+
func testAccGitlabProjectConfigWithoutDefaultBranchProtection(rInt int) string {
1096+
return fmt.Sprintf(`
1097+
resource "gitlab_group" "foo" {
1098+
name = "foogroup-%d"
1099+
path = "foogroup-%d"
1100+
default_branch_protection = 0
1101+
visibility_level = "public"
1102+
}
1103+
1104+
resource "gitlab_project" "foo" {
1105+
name = "foo-%d"
1106+
description = "Terraform acceptance tests"
1107+
namespace_id = "${gitlab_group.foo.id}"
1108+
}
1109+
`, rInt, rInt, rInt)
1110+
}
1111+
10781112
func testAccGitlabProjectTransferBetweenGroups(rInt int) string {
10791113
return fmt.Sprintf(`
10801114
resource "gitlab_group" "foo" {

0 commit comments

Comments
 (0)