@@ -82,6 +82,80 @@ func TestAccGitlabGroup_import(t *testing.T) {
82
82
})
83
83
}
84
84
85
+ func TestAccGitlabGroup_nested (t * testing.T ) {
86
+ var group gitlab.Group
87
+ var group2 gitlab.Group
88
+ var nestedGroup gitlab.Group
89
+ rInt := acctest .RandInt ()
90
+
91
+ resource .Test (t , resource.TestCase {
92
+ PreCheck : func () { testAccPreCheck (t ) },
93
+ Providers : testAccProviders ,
94
+ CheckDestroy : testAccCheckGitlabGroupDestroy ,
95
+ Steps : []resource.TestStep {
96
+ {
97
+ Config : testAccGitlabNestedGroupConfig (rInt ),
98
+ Check : resource .ComposeTestCheckFunc (
99
+ testAccCheckGitlabGroupExists ("gitlab_group.foo" , & group ),
100
+ testAccCheckGitlabGroupExists ("gitlab_group.foo2" , & group2 ),
101
+ testAccCheckGitlabGroupExists ("gitlab_group.nested_foo" , & nestedGroup ),
102
+ testAccCheckGitlabGroupAttributes (& nestedGroup , & testAccGitlabGroupExpectedAttributes {
103
+ Name : fmt .Sprintf ("nfoo-name-%d" , rInt ),
104
+ Path : fmt .Sprintf ("nfoo-path-%d" , rInt ),
105
+ Description : "Terraform acceptance tests" ,
106
+ LFSEnabled : true ,
107
+ Parent : & group ,
108
+ }),
109
+ ),
110
+ },
111
+ {
112
+ Config : testAccGitlabNestedGroupChangeParentConfig (rInt ),
113
+ Check : resource .ComposeTestCheckFunc (
114
+ testAccCheckGitlabGroupExists ("gitlab_group.foo" , & group ),
115
+ testAccCheckGitlabGroupExists ("gitlab_group.foo2" , & group2 ),
116
+ testAccCheckGitlabGroupExists ("gitlab_group.nested_foo" , & nestedGroup ),
117
+ testAccCheckGitlabGroupAttributes (& nestedGroup , & testAccGitlabGroupExpectedAttributes {
118
+ Name : fmt .Sprintf ("nfoo-name-%d" , rInt ),
119
+ Path : fmt .Sprintf ("nfoo-path-%d" , rInt ),
120
+ Description : "Terraform acceptance tests - new parent" ,
121
+ LFSEnabled : true ,
122
+ Parent : & group2 ,
123
+ }),
124
+ ),
125
+ },
126
+ {
127
+ Config : testAccGitlabNestedGroupRemoveParentConfig (rInt ),
128
+ Check : resource .ComposeTestCheckFunc (
129
+ testAccCheckGitlabGroupExists ("gitlab_group.foo" , & group ),
130
+ testAccCheckGitlabGroupExists ("gitlab_group.foo2" , & group2 ),
131
+ testAccCheckGitlabGroupExists ("gitlab_group.nested_foo" , & nestedGroup ),
132
+ testAccCheckGitlabGroupAttributes (& nestedGroup , & testAccGitlabGroupExpectedAttributes {
133
+ Name : fmt .Sprintf ("nfoo-name-%d" , rInt ),
134
+ Path : fmt .Sprintf ("nfoo-path-%d" , rInt ),
135
+ Description : "Terraform acceptance tests - updated" ,
136
+ LFSEnabled : true ,
137
+ }),
138
+ ),
139
+ },
140
+ {
141
+ Config : testAccGitlabNestedGroupConfig (rInt ),
142
+ Check : resource .ComposeTestCheckFunc (
143
+ testAccCheckGitlabGroupExists ("gitlab_group.foo" , & group ),
144
+ testAccCheckGitlabGroupExists ("gitlab_group.foo2" , & group2 ),
145
+ testAccCheckGitlabGroupExists ("gitlab_group.nested_foo" , & nestedGroup ),
146
+ testAccCheckGitlabGroupAttributes (& nestedGroup , & testAccGitlabGroupExpectedAttributes {
147
+ Name : fmt .Sprintf ("nfoo-name-%d" , rInt ),
148
+ Path : fmt .Sprintf ("nfoo-path-%d" , rInt ),
149
+ Description : "Terraform acceptance tests" ,
150
+ LFSEnabled : true ,
151
+ Parent : & group ,
152
+ }),
153
+ ),
154
+ },
155
+ },
156
+ })
157
+ }
158
+
85
159
func testAccCheckGitlabGroupExists (n string , group * gitlab.Group ) resource.TestCheckFunc {
86
160
return func (s * terraform.State ) error {
87
161
rs , ok := s .RootModule ().Resources [n ]
@@ -108,6 +182,7 @@ type testAccGitlabGroupExpectedAttributes struct {
108
182
Name string
109
183
Path string
110
184
Description string
185
+ Parent * gitlab.Group
111
186
LFSEnabled bool
112
187
RequestAccessEnabled bool
113
188
}
@@ -134,6 +209,16 @@ func testAccCheckGitlabGroupAttributes(group *gitlab.Group, want *testAccGitlabG
134
209
return fmt .Errorf ("got request_access_enabled %t; want %t" , group .RequestAccessEnabled , want .RequestAccessEnabled )
135
210
}
136
211
212
+ if want .Parent != nil {
213
+ if group .ParentID != want .Parent .ID {
214
+ return fmt .Errorf ("got parent_id %d; want %d" , group .ParentID , want .Parent .ID )
215
+ }
216
+ } else {
217
+ if group .ParentID != 0 {
218
+ return fmt .Errorf ("got parent_id %d; want %d" , group .ParentID , 0 )
219
+ }
220
+ }
221
+
137
222
return nil
138
223
}
139
224
}
@@ -189,3 +274,101 @@ resource "gitlab_group" "foo" {
189
274
}
190
275
` , rInt , rInt )
191
276
}
277
+
278
+ func testAccGitlabNestedGroupConfig (rInt int ) string {
279
+ return fmt .Sprintf (`
280
+ resource "gitlab_group" "foo" {
281
+ name = "foo-name-%d"
282
+ path = "foo-path-%d"
283
+ description = "Terraform acceptance tests"
284
+
285
+ # So that acceptance tests can be run in a gitlab organization
286
+ # with no billing
287
+ visibility_level = "public"
288
+ }
289
+ resource "gitlab_group" "foo2" {
290
+ name = "foo2-name-%d"
291
+ path = "foo2-path-%d"
292
+ description = "Terraform acceptance tests - parent2"
293
+
294
+ # So that acceptance tests can be run in a gitlab organization
295
+ # with no billing
296
+ visibility_level = "public"
297
+ }
298
+ resource "gitlab_group" "nested_foo" {
299
+ name = "nfoo-name-%d"
300
+ path = "nfoo-path-%d"
301
+ parent_id = "${gitlab_group.foo.id}"
302
+ description = "Terraform acceptance tests"
303
+
304
+ # So that acceptance tests can be run in a gitlab organization
305
+ # with no billing
306
+ visibility_level = "public"
307
+ }
308
+ ` , rInt , rInt , rInt , rInt , rInt , rInt )
309
+ }
310
+
311
+ func testAccGitlabNestedGroupRemoveParentConfig (rInt int ) string {
312
+ return fmt .Sprintf (`
313
+ resource "gitlab_group" "foo" {
314
+ name = "foo-name-%d"
315
+ path = "foo-path-%d"
316
+ description = "Terraform acceptance tests"
317
+
318
+ # So that acceptance tests can be run in a gitlab organization
319
+ # with no billing
320
+ visibility_level = "public"
321
+ }
322
+ resource "gitlab_group" "foo2" {
323
+ name = "foo2-name-%d"
324
+ path = "foo2-path-%d"
325
+ description = "Terraform acceptance tests - parent2"
326
+
327
+ # So that acceptance tests can be run in a gitlab organization
328
+ # with no billing
329
+ visibility_level = "public"
330
+ }
331
+ resource "gitlab_group" "nested_foo" {
332
+ name = "nfoo-name-%d"
333
+ path = "nfoo-path-%d"
334
+ description = "Terraform acceptance tests - updated"
335
+
336
+ # So that acceptance tests can be run in a gitlab organization
337
+ # with no billing
338
+ visibility_level = "public"
339
+ }
340
+ ` , rInt , rInt , rInt , rInt , rInt , rInt )
341
+ }
342
+
343
+ func testAccGitlabNestedGroupChangeParentConfig (rInt int ) string {
344
+ return fmt .Sprintf (`
345
+ resource "gitlab_group" "foo" {
346
+ name = "foo-name-%d"
347
+ path = "foo-path-%d"
348
+ description = "Terraform acceptance tests"
349
+
350
+ # So that acceptance tests can be run in a gitlab organization
351
+ # with no billing
352
+ visibility_level = "public"
353
+ }
354
+ resource "gitlab_group" "foo2" {
355
+ name = "foo2-name-%d"
356
+ path = "foo2-path-%d"
357
+ description = "Terraform acceptance tests - parent2"
358
+
359
+ # So that acceptance tests can be run in a gitlab organization
360
+ # with no billing
361
+ visibility_level = "public"
362
+ }
363
+ resource "gitlab_group" "nested_foo" {
364
+ name = "nfoo-name-%d"
365
+ path = "nfoo-path-%d"
366
+ description = "Terraform acceptance tests - new parent"
367
+ parent_id = "${gitlab_group.foo2.id}"
368
+
369
+ # So that acceptance tests can be run in a gitlab organization
370
+ # with no billing
371
+ visibility_level = "public"
372
+ }
373
+ ` , rInt , rInt , rInt , rInt , rInt , rInt )
374
+ }
0 commit comments