@@ -81,6 +81,71 @@ func TestAccGitlabBranchProtection_basic(t *testing.T) {
81
81
SkipFunc : isRunningInEE ,
82
82
Config : testAccGitlabBranchProtectionUpdateConfigCodeOwnerTrue (rInt ),
83
83
ExpectError : regexp .MustCompile ("feature unavailable: code owner approvals" ),
84
+ Check : resource .ComposeTestCheckFunc (
85
+ testAccCheckGitlabBranchProtectionExists ("gitlab_branch_protection.BranchProtect" , & pb ),
86
+ testAccCheckGitlabBranchProtectionPersistsInStateCorrectly ("gitlab_branch_protection.BranchProtect" , & pb ),
87
+ testAccCheckGitlabBranchProtectionAttributes (& pb , & testAccGitlabBranchProtectionExpectedAttributes {
88
+ Name : fmt .Sprintf ("BranchProtect-%d" , rInt ),
89
+ PushAccessLevel : accessLevel [gitlab .DeveloperPermissions ],
90
+ MergeAccessLevel : accessLevel [gitlab .DeveloperPermissions ],
91
+ }),
92
+ ),
93
+ },
94
+ // Update the Branch Protection to get back to initial settings
95
+ {
96
+ Config : testAccGitlabBranchProtectionConfig (rInt ),
97
+ Check : resource .ComposeTestCheckFunc (
98
+ testAccCheckGitlabBranchProtectionExists ("gitlab_branch_protection.BranchProtect" , & pb ),
99
+ testAccCheckGitlabBranchProtectionPersistsInStateCorrectly ("gitlab_branch_protection.BranchProtect" , & pb ),
100
+ testAccCheckGitlabBranchProtectionAttributes (& pb , & testAccGitlabBranchProtectionExpectedAttributes {
101
+ Name : fmt .Sprintf ("BranchProtect-%d" , rInt ),
102
+ PushAccessLevel : accessLevel [gitlab .DeveloperPermissions ],
103
+ MergeAccessLevel : accessLevel [gitlab .DeveloperPermissions ],
104
+ }),
105
+ ),
106
+ },
107
+ },
108
+ })
109
+ }
110
+
111
+ func TestAccGitlabBranchProtection_createWithCodeOwnerApproval (t * testing.T ) {
112
+ var pb gitlab.ProtectedBranch
113
+ rInt := acctest .RandInt ()
114
+
115
+ resource .Test (t , resource.TestCase {
116
+ PreCheck : func () { testAccPreCheck (t ) },
117
+ Providers : testAccProviders ,
118
+ CheckDestroy : testAccCheckGitlabBranchProtectionDestroy ,
119
+ Steps : []resource.TestStep {
120
+ // Create a project and Branch Protection with code owner approval enabled
121
+ {
122
+ SkipFunc : isRunningInCE ,
123
+ Config : testAccGitlabBranchProtectionUpdateConfigCodeOwnerTrue (rInt ),
124
+ Check : resource .ComposeTestCheckFunc (
125
+ testAccCheckGitlabBranchProtectionExists ("gitlab_branch_protection.BranchProtect" , & pb ),
126
+ testAccCheckGitlabBranchProtectionPersistsInStateCorrectly ("gitlab_branch_protection.BranchProtect" , & pb ),
127
+ testAccCheckGitlabBranchProtectionAttributes (& pb , & testAccGitlabBranchProtectionExpectedAttributes {
128
+ Name : fmt .Sprintf ("BranchProtect-%d" , rInt ),
129
+ PushAccessLevel : accessLevel [gitlab .DeveloperPermissions ],
130
+ MergeAccessLevel : accessLevel [gitlab .DeveloperPermissions ],
131
+ CodeOwnerApprovalRequired : true ,
132
+ }),
133
+ ),
134
+ },
135
+ // Attempting to update code owner approval setting on CE should fail safely and with an informative error message
136
+ {
137
+ SkipFunc : isRunningInEE ,
138
+ Config : testAccGitlabBranchProtectionUpdateConfigCodeOwnerTrue (rInt ),
139
+ ExpectError : regexp .MustCompile ("feature unavailable: code owner approvals" ),
140
+ Check : resource .ComposeTestCheckFunc (
141
+ testAccCheckGitlabBranchProtectionExists ("gitlab_branch_protection.BranchProtect" , & pb ),
142
+ testAccCheckGitlabBranchProtectionPersistsInStateCorrectly ("gitlab_branch_protection.BranchProtect" , & pb ),
143
+ testAccCheckGitlabBranchProtectionAttributes (& pb , & testAccGitlabBranchProtectionExpectedAttributes {
144
+ Name : fmt .Sprintf ("BranchProtect-%d" , rInt ),
145
+ PushAccessLevel : accessLevel [gitlab .DeveloperPermissions ],
146
+ MergeAccessLevel : accessLevel [gitlab .DeveloperPermissions ],
147
+ }),
148
+ ),
84
149
},
85
150
// Update the Branch Protection to get back to initial settings
86
151
{
0 commit comments