@@ -2,13 +2,14 @@ package gitlab
2
2
3
3
import (
4
4
"fmt"
5
+ "net/http"
6
+ "testing"
7
+ "time"
8
+
5
9
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
6
10
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
7
11
"github.com/hashicorp/terraform-plugin-sdk/terraform"
8
12
"github.com/xanzy/go-gitlab"
9
- "net/http"
10
- "testing"
11
- "time"
12
13
)
13
14
14
15
func TestAccGitlabGroup_basic (t * testing.T ) {
@@ -26,14 +27,15 @@ func TestAccGitlabGroup_basic(t *testing.T) {
26
27
Check : resource .ComposeTestCheckFunc (
27
28
testAccCheckGitlabGroupExists ("gitlab_group.foo" , & group ),
28
29
testAccCheckGitlabGroupAttributes (& group , & testAccGitlabGroupExpectedAttributes {
29
- Name : fmt .Sprintf ("foo-name-%d" , rInt ),
30
- Path : fmt .Sprintf ("foo-path-%d" , rInt ),
31
- Description : "Terraform acceptance tests" ,
32
- LFSEnabled : true ,
33
- Visibility : "public" , // default value
34
- ProjectCreationLevel : "maintainer" , // default value
35
- SubGroupCreationLevel : "owner" , // default value
36
- TwoFactorGracePeriod : 48 , // default value
30
+ Name : fmt .Sprintf ("foo-name-%d" , rInt ),
31
+ Path : fmt .Sprintf ("foo-path-%d" , rInt ),
32
+ Description : "Terraform acceptance tests" ,
33
+ LFSEnabled : true ,
34
+ Visibility : "public" , // default value
35
+ ProjectCreationLevel : "maintainer" , // default value
36
+ SubGroupCreationLevel : "owner" , // default value
37
+ TwoFactorGracePeriod : 48 , // default value
38
+ DefaultBranchProtection : 2 , // default value
37
39
}),
38
40
),
39
41
},
@@ -43,20 +45,21 @@ func TestAccGitlabGroup_basic(t *testing.T) {
43
45
Check : resource .ComposeTestCheckFunc (
44
46
testAccCheckGitlabGroupExists ("gitlab_group.foo" , & group ),
45
47
testAccCheckGitlabGroupAttributes (& group , & testAccGitlabGroupExpectedAttributes {
46
- Name : fmt .Sprintf ("bar-name-%d" , rInt ),
47
- Path : fmt .Sprintf ("bar-path-%d" , rInt ),
48
- Description : "Terraform acceptance tests! Updated description" ,
49
- LFSEnabled : false ,
50
- Visibility : "public" , // default value
51
- RequestAccessEnabled : true ,
52
- ProjectCreationLevel : "developer" ,
53
- SubGroupCreationLevel : "maintainer" ,
54
- RequireTwoFactorAuth : true ,
55
- TwoFactorGracePeriod : 56 ,
56
- AutoDevopsEnabled : true ,
57
- EmailsDisabled : true ,
58
- MentionsDisabled : true ,
59
- ShareWithGroupLock : true ,
48
+ Name : fmt .Sprintf ("bar-name-%d" , rInt ),
49
+ Path : fmt .Sprintf ("bar-path-%d" , rInt ),
50
+ Description : "Terraform acceptance tests! Updated description" ,
51
+ LFSEnabled : false ,
52
+ Visibility : "public" , // default value
53
+ RequestAccessEnabled : true ,
54
+ ProjectCreationLevel : "developer" ,
55
+ SubGroupCreationLevel : "maintainer" ,
56
+ RequireTwoFactorAuth : true ,
57
+ TwoFactorGracePeriod : 56 ,
58
+ AutoDevopsEnabled : true ,
59
+ EmailsDisabled : true ,
60
+ MentionsDisabled : true ,
61
+ ShareWithGroupLock : true ,
62
+ DefaultBranchProtection : 1 ,
60
63
}),
61
64
),
62
65
},
@@ -66,14 +69,15 @@ func TestAccGitlabGroup_basic(t *testing.T) {
66
69
Check : resource .ComposeTestCheckFunc (
67
70
testAccCheckGitlabGroupExists ("gitlab_group.foo" , & group ),
68
71
testAccCheckGitlabGroupAttributes (& group , & testAccGitlabGroupExpectedAttributes {
69
- Name : fmt .Sprintf ("foo-name-%d" , rInt ),
70
- Path : fmt .Sprintf ("foo-path-%d" , rInt ),
71
- Description : "Terraform acceptance tests" ,
72
- LFSEnabled : true ,
73
- Visibility : "public" , // default value
74
- ProjectCreationLevel : "maintainer" , // default value
75
- SubGroupCreationLevel : "owner" , // default value
76
- TwoFactorGracePeriod : 48 , // default value
72
+ Name : fmt .Sprintf ("foo-name-%d" , rInt ),
73
+ Path : fmt .Sprintf ("foo-path-%d" , rInt ),
74
+ Description : "Terraform acceptance tests" ,
75
+ LFSEnabled : true ,
76
+ Visibility : "public" , // default value
77
+ ProjectCreationLevel : "maintainer" , // default value
78
+ SubGroupCreationLevel : "owner" , // default value
79
+ TwoFactorGracePeriod : 48 , // default value
80
+ DefaultBranchProtection : 2 , // default value
77
81
}),
78
82
),
79
83
},
@@ -120,15 +124,16 @@ func TestAccGitlabGroup_nested(t *testing.T) {
120
124
testAccCheckGitlabGroupExists ("gitlab_group.foo2" , & group2 ),
121
125
testAccCheckGitlabGroupExists ("gitlab_group.nested_foo" , & nestedGroup ),
122
126
testAccCheckGitlabGroupAttributes (& nestedGroup , & testAccGitlabGroupExpectedAttributes {
123
- Name : fmt .Sprintf ("nfoo-name-%d" , rInt ),
124
- Path : fmt .Sprintf ("nfoo-path-%d" , rInt ),
125
- Description : "Terraform acceptance tests" ,
126
- LFSEnabled : true ,
127
- Visibility : "public" , // default value
128
- ProjectCreationLevel : "maintainer" , // default value
129
- SubGroupCreationLevel : "owner" , // default value
130
- TwoFactorGracePeriod : 48 , // default value
131
- Parent : & group ,
127
+ Name : fmt .Sprintf ("nfoo-name-%d" , rInt ),
128
+ Path : fmt .Sprintf ("nfoo-path-%d" , rInt ),
129
+ Description : "Terraform acceptance tests" ,
130
+ LFSEnabled : true ,
131
+ Visibility : "public" , // default value
132
+ ProjectCreationLevel : "maintainer" , // default value
133
+ SubGroupCreationLevel : "owner" , // default value
134
+ TwoFactorGracePeriod : 48 , // default value
135
+ DefaultBranchProtection : 2 , // default value
136
+ Parent : & group ,
132
137
}),
133
138
),
134
139
},
@@ -139,15 +144,16 @@ func TestAccGitlabGroup_nested(t *testing.T) {
139
144
testAccCheckGitlabGroupExists ("gitlab_group.foo2" , & group2 ),
140
145
testAccCheckGitlabGroupExists ("gitlab_group.nested_foo" , & nestedGroup ),
141
146
testAccCheckGitlabGroupAttributes (& nestedGroup , & testAccGitlabGroupExpectedAttributes {
142
- Name : fmt .Sprintf ("nfoo-name-%d" , rInt ),
143
- Path : fmt .Sprintf ("nfoo-path-%d" , rInt ),
144
- Description : "Terraform acceptance tests - new parent" ,
145
- LFSEnabled : true ,
146
- Visibility : "public" , // default value
147
- ProjectCreationLevel : "maintainer" , // default value
148
- SubGroupCreationLevel : "owner" , // default value
149
- TwoFactorGracePeriod : 48 , // default value
150
- Parent : & group2 ,
147
+ Name : fmt .Sprintf ("nfoo-name-%d" , rInt ),
148
+ Path : fmt .Sprintf ("nfoo-path-%d" , rInt ),
149
+ Description : "Terraform acceptance tests - new parent" ,
150
+ LFSEnabled : true ,
151
+ Visibility : "public" , // default value
152
+ ProjectCreationLevel : "maintainer" , // default value
153
+ SubGroupCreationLevel : "owner" , // default value
154
+ TwoFactorGracePeriod : 48 , // default value
155
+ DefaultBranchProtection : 2 , // default value
156
+ Parent : & group2 ,
151
157
}),
152
158
),
153
159
},
@@ -158,14 +164,15 @@ func TestAccGitlabGroup_nested(t *testing.T) {
158
164
testAccCheckGitlabGroupExists ("gitlab_group.foo2" , & group2 ),
159
165
testAccCheckGitlabGroupExists ("gitlab_group.nested_foo" , & nestedGroup ),
160
166
testAccCheckGitlabGroupAttributes (& nestedGroup , & testAccGitlabGroupExpectedAttributes {
161
- Name : fmt .Sprintf ("nfoo-name-%d" , rInt ),
162
- Path : fmt .Sprintf ("nfoo-path-%d" , rInt ),
163
- Description : "Terraform acceptance tests - updated" ,
164
- LFSEnabled : true ,
165
- Visibility : "public" , // default value
166
- ProjectCreationLevel : "maintainer" , // default value
167
- SubGroupCreationLevel : "owner" , // default value
168
- TwoFactorGracePeriod : 48 , // default value
167
+ Name : fmt .Sprintf ("nfoo-name-%d" , rInt ),
168
+ Path : fmt .Sprintf ("nfoo-path-%d" , rInt ),
169
+ Description : "Terraform acceptance tests - updated" ,
170
+ LFSEnabled : true ,
171
+ Visibility : "public" , // default value
172
+ ProjectCreationLevel : "maintainer" , // default value
173
+ SubGroupCreationLevel : "owner" , // default value
174
+ TwoFactorGracePeriod : 48 , // default value
175
+ DefaultBranchProtection : 2 , // default value
169
176
}),
170
177
),
171
178
},
@@ -185,6 +192,7 @@ func TestAccGitlabGroup_nested(t *testing.T) {
185
192
// ProjectCreationLevel: "maintainer", // default value
186
193
// SubGroupCreationLevel: "owner", // default value
187
194
// TwoFactorGracePeriod: 48, // default value
195
+ // DefaultBranchProtection: 2, // default value
188
196
// Parent: &group,
189
197
// }),
190
198
// ),
@@ -263,21 +271,22 @@ func testAccCheckGitlabGroupExists(n string, group *gitlab.Group) resource.TestC
263
271
}
264
272
265
273
type testAccGitlabGroupExpectedAttributes struct {
266
- Name string
267
- Path string
268
- Description string
269
- Parent * gitlab.Group
270
- LFSEnabled bool
271
- RequestAccessEnabled bool
272
- Visibility gitlab.VisibilityValue
273
- ShareWithGroupLock bool
274
- AutoDevopsEnabled bool
275
- EmailsDisabled bool
276
- MentionsDisabled bool
277
- ProjectCreationLevel gitlab.ProjectCreationLevelValue
278
- SubGroupCreationLevel gitlab.SubGroupCreationLevelValue
279
- RequireTwoFactorAuth bool
280
- TwoFactorGracePeriod int
274
+ Name string
275
+ Path string
276
+ Description string
277
+ Parent * gitlab.Group
278
+ LFSEnabled bool
279
+ RequestAccessEnabled bool
280
+ Visibility gitlab.VisibilityValue
281
+ ShareWithGroupLock bool
282
+ AutoDevopsEnabled bool
283
+ EmailsDisabled bool
284
+ MentionsDisabled bool
285
+ ProjectCreationLevel gitlab.ProjectCreationLevelValue
286
+ SubGroupCreationLevel gitlab.SubGroupCreationLevelValue
287
+ RequireTwoFactorAuth bool
288
+ TwoFactorGracePeriod int
289
+ DefaultBranchProtection int
281
290
}
282
291
283
292
func testAccCheckGitlabGroupAttributes (group * gitlab.Group , want * testAccGitlabGroupExpectedAttributes ) resource.TestCheckFunc {
@@ -338,6 +347,10 @@ func testAccCheckGitlabGroupAttributes(group *gitlab.Group, want *testAccGitlabG
338
347
return fmt .Errorf ("got share_with_group_lock %t; want %t" , group .ShareWithGroupLock , want .ShareWithGroupLock )
339
348
}
340
349
350
+ if group .DefaultBranchProtection != want .DefaultBranchProtection {
351
+ return fmt .Errorf ("got default_branch_protection %d; want %d" , group .DefaultBranchProtection , want .DefaultBranchProtection )
352
+ }
353
+
341
354
if want .Parent != nil {
342
355
if group .ParentID != want .Parent .ID {
343
356
return fmt .Errorf ("got parent_id %d; want %d" , group .ParentID , want .Parent .ID )
@@ -406,6 +419,7 @@ resource "gitlab_group" "foo" {
406
419
emails_disabled = true
407
420
mentions_disabled = true
408
421
share_with_group_lock = true
422
+ default_branch_protection = 1
409
423
410
424
# So that acceptance tests can be run in a gitlab organization
411
425
# with no billing
0 commit comments