Skip to content

Commit daceb44

Browse files
committed
Add acceptance tests for data sources gitlab_project_protected_branch(es)
Signed-off-by: Sune Keller <[email protected]>
1 parent 0fc2249 commit daceb44

File tree

2 files changed

+113
-0
lines changed

2 files changed

+113
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package gitlab
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
8+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
9+
)
10+
11+
func TestAccDataGitlabProjectProtectedBranchSearch(t *testing.T) {
12+
projectName := fmt.Sprintf("tf-%s", acctest.RandString(5))
13+
14+
resource.Test(t, resource.TestCase{
15+
PreCheck: func() { testAccPreCheck(t) },
16+
Providers: testAccProviders,
17+
Steps: []resource.TestStep{
18+
{
19+
Config: testAccDataGitlabProjectProtectedBranchConfigGetProjectSearch(projectName),
20+
Check: resource.ComposeAggregateTestCheckFunc(
21+
resource.TestCheckResourceAttr(
22+
"data.gitlab_project_protected_branches.test",
23+
"name",
24+
"master",
25+
),
26+
resource.TestCheckResourceAttr(
27+
"data.gitlab_project_protected_branch.test",
28+
"push_access_levels.0.access_level",
29+
"40",
30+
),
31+
),
32+
},
33+
},
34+
})
35+
}
36+
37+
func testAccDataGitlabProjectProtectedBranchConfigGetProjectSearch(projectName string) string {
38+
return fmt.Sprintf(`
39+
resource "gitlab_project" "test" {
40+
name = "%s"
41+
path = "%s"
42+
default_branch = "master"
43+
}
44+
45+
resource "gitlab_branch_protection" "test" {
46+
project = gitlab_project.test.id
47+
branch = gitlab_project.test.default_branch
48+
push_access_level = "maintainer"
49+
merge_access_level = "developer"
50+
}
51+
52+
data "gitlab_project_protected_branch" "test" {
53+
project_id = gitlab_project.test.id
54+
name = gitlab_project.test.default_branch
55+
}
56+
`, projectName, projectName)
57+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package gitlab
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
8+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
9+
)
10+
11+
func TestAccDataGitlabProjectProtectedBranchesSearch(t *testing.T) {
12+
projectName := fmt.Sprintf("tf-%s", acctest.RandString(5))
13+
14+
resource.Test(t, resource.TestCase{
15+
PreCheck: func() { testAccPreCheck(t) },
16+
Providers: testAccProviders,
17+
Steps: []resource.TestStep{
18+
{
19+
Config: testAccDataGitlabProjectProtectedBranchesConfigGetProjectSearch(projectName),
20+
Check: resource.ComposeAggregateTestCheckFunc(
21+
resource.TestCheckResourceAttr(
22+
"data.gitlab_project_protected_branches.test",
23+
"protected_branches.0.name",
24+
"master",
25+
),
26+
resource.TestCheckResourceAttr(
27+
"data.gitlab_project_protected_branches.test",
28+
"protected_branches.0.push_access_levels.0.access_level",
29+
"40",
30+
),
31+
),
32+
},
33+
},
34+
})
35+
}
36+
37+
func testAccDataGitlabProjectProtectedBranchesConfigGetProjectSearch(projectName string) string {
38+
return fmt.Sprintf(`
39+
resource "gitlab_project" "test" {
40+
name = "%s"
41+
path = "%s"
42+
default_branch = "master"
43+
}
44+
45+
resource "gitlab_branch_protection" "test" {
46+
project = gitlab_project.test.id
47+
branch = gitlab_project.test.default_branch
48+
push_access_level = "maintainer"
49+
merge_access_level = "developer"
50+
}
51+
52+
data "gitlab_project_protected_branches" "test" {
53+
project_id = gitlab_project.test.id
54+
}
55+
`, projectName, projectName)
56+
}

0 commit comments

Comments
 (0)