@@ -4,23 +4,24 @@ import (
4
4
"fmt"
5
5
"testing"
6
6
7
- "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
8
7
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
9
8
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
10
9
gitlab "github.com/xanzy/go-gitlab"
11
10
)
12
11
13
- func TestAccGitlabRepositoryFile_create (t * testing.T ) {
12
+ func TestAccGitlabRepositoryFile_basic (t * testing.T ) {
13
+ testAccCheck (t )
14
+
14
15
var file gitlab.File
15
- rInt := acctest . RandInt ( )
16
+ testProject := testAccCreateProject ( t )
16
17
17
18
resource .Test (t , resource.TestCase {
18
19
PreCheck : func () { testAccPreCheck (t ) },
19
20
ProviderFactories : providerFactories ,
20
21
CheckDestroy : testAccCheckGitlabRepositoryFileDestroy ,
21
22
Steps : []resource.TestStep {
22
23
{
23
- Config : testAccGitlabRepositoryFileConfig (rInt ),
24
+ Config : testAccGitlabRepositoryFileConfig (testProject . ID ),
24
25
Check : resource .ComposeTestCheckFunc (
25
26
testAccCheckGitlabRepositoryFileExists ("gitlab_repository_file.this" , & file ),
26
27
testAccCheckGitlabRepositoryFileAttributes (& file , & testAccGitlabRepositoryFileAttributes {
@@ -29,22 +30,47 @@ func TestAccGitlabRepositoryFile_create(t *testing.T) {
29
30
}),
30
31
),
31
32
},
33
+ {
34
+ ResourceName : "gitlab_repository_file.this" ,
35
+ ImportState : true ,
36
+ ImportStateVerify : true ,
37
+ ImportStateVerifyIgnore : []string {"author_email" , "author_name" , "commit_message" },
38
+ },
39
+ {
40
+ Config : testAccGitlabRepositoryFileUpdateConfig (testProject .ID ),
41
+ Check : resource .ComposeTestCheckFunc (
42
+ testAccCheckGitlabRepositoryFileExists ("gitlab_repository_file.this" , & file ),
43
+ testAccCheckGitlabRepositoryFileAttributes (& file , & testAccGitlabRepositoryFileAttributes {
44
+ FilePath : "meow.txt" ,
45
+ Content : "bWVvdyBtZW93IG1lb3cgbWVvdyBtZW93Cg==" ,
46
+ }),
47
+ ),
48
+ },
49
+ {
50
+ ResourceName : "gitlab_repository_file.this" ,
51
+ ImportState : true ,
52
+ ImportStateVerify : true ,
53
+ ImportStateVerifyIgnore : []string {"author_email" , "author_name" , "commit_message" },
54
+ },
32
55
},
33
56
})
34
57
}
35
58
36
59
func TestAccGitlabRepositoryFile_createSameFileDifferentRepository (t * testing.T ) {
60
+ testAccCheck (t )
61
+
37
62
var fooFile gitlab.File
38
63
var barFile gitlab.File
39
- rInt := acctest .RandInt ()
64
+ firstTestProject := testAccCreateProject (t )
65
+ secondTestProject := testAccCreateProject (t )
40
66
41
67
resource .Test (t , resource.TestCase {
42
68
PreCheck : func () { testAccPreCheck (t ) },
43
69
ProviderFactories : providerFactories ,
44
70
CheckDestroy : testAccCheckGitlabRepositoryFileDestroy ,
45
71
Steps : []resource.TestStep {
46
72
{
47
- Config : testAccGitlabRepositoryFileSameFileDifferentRepositoryConfig (rInt ),
73
+ Config : testAccGitlabRepositoryFileSameFileDifferentRepositoryConfig (firstTestProject . ID , secondTestProject . ID ),
48
74
Check : resource .ComposeTestCheckFunc (
49
75
testAccCheckGitlabRepositoryFileExists ("gitlab_repository_file.foo_file" , & fooFile ),
50
76
testAccCheckGitlabRepositoryFileAttributes (& fooFile , & testAccGitlabRepositoryFileAttributes {
@@ -112,39 +138,18 @@ func TestAccGitlabRepositoryFile_validationOfBase64Content(t *testing.T) {
112
138
}
113
139
114
140
func TestAccGitlabRepositoryFile_createOnNewBranch (t * testing.T ) {
115
- var file gitlab.File
116
- rInt := acctest .RandInt ()
117
-
118
- resource .Test (t , resource.TestCase {
119
- PreCheck : func () { testAccPreCheck (t ) },
120
- ProviderFactories : providerFactories ,
121
- CheckDestroy : testAccCheckGitlabRepositoryFileDestroy ,
122
- Steps : []resource.TestStep {
123
- {
124
- Config : testAccGitlabRepositoryFileStartBranchConfig (rInt ),
125
- Check : resource .ComposeTestCheckFunc (
126
- testAccCheckGitlabRepositoryFileExists ("gitlab_repository_file.this" , & file ),
127
- testAccCheckGitlabRepositoryFileAttributes (& file , & testAccGitlabRepositoryFileAttributes {
128
- FilePath : "meow.txt" ,
129
- Content : "bWVvdyBtZW93IG1lb3c=" ,
130
- }),
131
- ),
132
- },
133
- },
134
- })
135
- }
141
+ testAccCheck (t )
136
142
137
- func TestAccGitlabRepositoryFile_update (t * testing.T ) {
138
143
var file gitlab.File
139
- rInt := acctest . RandInt ( )
144
+ testProject := testAccCreateProject ( t )
140
145
141
146
resource .Test (t , resource.TestCase {
142
147
PreCheck : func () { testAccPreCheck (t ) },
143
148
ProviderFactories : providerFactories ,
144
149
CheckDestroy : testAccCheckGitlabRepositoryFileDestroy ,
145
150
Steps : []resource.TestStep {
146
151
{
147
- Config : testAccGitlabRepositoryFileConfig ( rInt ),
152
+ Config : testAccGitlabRepositoryFileStartBranchConfig ( testProject . ID ),
148
153
Check : resource .ComposeTestCheckFunc (
149
154
testAccCheckGitlabRepositoryFileExists ("gitlab_repository_file.this" , & file ),
150
155
testAccCheckGitlabRepositoryFileAttributes (& file , & testAccGitlabRepositoryFileAttributes {
@@ -153,39 +158,6 @@ func TestAccGitlabRepositoryFile_update(t *testing.T) {
153
158
}),
154
159
),
155
160
},
156
- {
157
- Config : testAccGitlabRepositoryFileUpdateConfig (rInt ),
158
- Check : resource .ComposeTestCheckFunc (
159
- testAccCheckGitlabRepositoryFileExists ("gitlab_repository_file.this" , & file ),
160
- testAccCheckGitlabRepositoryFileAttributes (& file , & testAccGitlabRepositoryFileAttributes {
161
- FilePath : "meow.txt" ,
162
- Content : "bWVvdyBtZW93IG1lb3cgbWVvdyBtZW93Cg==" ,
163
- }),
164
- ),
165
- },
166
- },
167
- })
168
- }
169
-
170
- // lintignore: AT002 // TODO: Resolve this tfproviderlint issue
171
- func TestAccGitlabRepositoryFile_import (t * testing.T ) {
172
- rInt := acctest .RandInt ()
173
- resourceName := "gitlab_repository_file.this"
174
-
175
- resource .Test (t , resource.TestCase {
176
- PreCheck : func () { testAccPreCheck (t ) },
177
- ProviderFactories : providerFactories ,
178
- CheckDestroy : testAccCheckGitlabPipelineTriggerDestroy ,
179
- Steps : []resource.TestStep {
180
- {
181
- Config : testAccGitlabRepositoryFileConfig (rInt ),
182
- },
183
- {
184
- ResourceName : resourceName ,
185
- ImportState : true ,
186
- ImportStateVerify : true ,
187
- ImportStateVerifyIgnore : []string {"author_email" , "author_name" , "commit_message" },
188
- },
189
161
},
190
162
})
191
163
}
@@ -266,48 +238,24 @@ func testAccCheckGitlabRepositoryFileDestroy(s *terraform.State) error {
266
238
return nil
267
239
}
268
240
269
- func testAccGitlabRepositoryFileConfig (rInt int ) string {
241
+ func testAccGitlabRepositoryFileConfig (projectID int ) string {
270
242
return fmt .Sprintf (`
271
- resource "gitlab_project" "foo" {
272
- name = "foo-%d"
273
- description = "Terraform acceptance tests"
274
-
275
- default_branch = "main"
276
-
277
- # So that acceptance tests can be run in a gitlab organization
278
- # with no billing
279
- visibility_level = "public"
280
- initialize_with_readme = true
281
- }
282
-
283
243
resource "gitlab_repository_file" "this" {
284
- project = "${gitlab_project.foo.id}"
244
+ project = %d
285
245
file_path = "meow.txt"
286
246
branch = "main"
287
247
content = "bWVvdyBtZW93IG1lb3c="
288
248
author_email = "[email protected] "
289
249
author_name = "Meow Meowington"
290
250
commit_message = "feature: add launch codes"
291
251
}
292
- ` , rInt )
252
+ ` , projectID )
293
253
}
294
254
295
- func testAccGitlabRepositoryFileStartBranchConfig (rInt int ) string {
255
+ func testAccGitlabRepositoryFileStartBranchConfig (projectID int ) string {
296
256
return fmt .Sprintf (`
297
- resource "gitlab_project" "foo" {
298
- name = "foo-%d"
299
- description = "Terraform acceptance tests"
300
-
301
- default_branch = "main"
302
-
303
- # So that acceptance tests can be run in a gitlab organization
304
- # with no billing
305
- visibility_level = "public"
306
- initialize_with_readme = true
307
- }
308
-
309
257
resource "gitlab_repository_file" "this" {
310
- project = "${gitlab_project.foo.id}"
258
+ project = %d
311
259
file_path = "meow.txt"
312
260
branch = "meow-branch"
313
261
start_branch = "main"
@@ -316,63 +264,27 @@ resource "gitlab_repository_file" "this" {
316
264
author_name = "Meow Meowington"
317
265
commit_message = "feature: add launch codes"
318
266
}
319
- ` , rInt )
267
+ ` , projectID )
320
268
}
321
269
322
- func testAccGitlabRepositoryFileUpdateConfig (rInt int ) string {
270
+ func testAccGitlabRepositoryFileUpdateConfig (projectID int ) string {
323
271
return fmt .Sprintf (`
324
- resource "gitlab_project" "foo" {
325
- name = "foo-%d"
326
- description = "Terraform acceptance tests"
327
-
328
- default_branch = "main"
329
-
330
- # So that acceptance tests can be run in a gitlab organization
331
- # with no billing
332
- visibility_level = "public"
333
- initialize_with_readme = true
334
- }
335
-
336
272
resource "gitlab_repository_file" "this" {
337
- project = "${gitlab_project.foo.id}"
273
+ project = %d
338
274
file_path = "meow.txt"
339
275
branch = "main"
340
276
content = "bWVvdyBtZW93IG1lb3cgbWVvdyBtZW93Cg=="
341
277
author_email = "[email protected] "
342
278
author_name = "Meow Meowington"
343
279
commit_message = "feature: change launch codes"
344
280
}
345
- ` , rInt )
281
+ ` , projectID )
346
282
}
347
283
348
- func testAccGitlabRepositoryFileSameFileDifferentRepositoryConfig (rInt int ) string {
284
+ func testAccGitlabRepositoryFileSameFileDifferentRepositoryConfig (firstProjectID , secondProjectID int ) string {
349
285
return fmt .Sprintf (`
350
- resource "gitlab_project" "foo" {
351
- name = "foo-%d"
352
- description = "Terraform acceptance tests"
353
-
354
- default_branch = "main"
355
-
356
- # So that acceptance tests can be run in a gitlab organization
357
- # with no billing
358
- visibility_level = "public"
359
- initialize_with_readme = true
360
- }
361
-
362
- resource "gitlab_project" "bar" {
363
- name = "bar-%d"
364
- description = "Terraform acceptance tests"
365
-
366
- default_branch = "main"
367
-
368
- # So that acceptance tests can be run in a gitlab organization
369
- # with no billing
370
- visibility_level = "public"
371
- initialize_with_readme = true
372
- }
373
-
374
286
resource "gitlab_repository_file" "foo_file" {
375
- project = "${gitlab_project.foo.id}"
287
+ project = %d
376
288
file_path = "meow.txt"
377
289
branch = "main"
378
290
content = "bWVvdyBtZW93IG1lb3c="
@@ -382,15 +294,15 @@ resource "gitlab_repository_file" "foo_file" {
382
294
}
383
295
384
296
resource "gitlab_repository_file" "bar_file" {
385
- project = "${gitlab_project.bar.id}"
297
+ project = %d
386
298
file_path = "meow.txt"
387
299
branch = "main"
388
300
content = "bWVvdyBtZW93IG1lb3c="
389
301
author_email = "[email protected] "
390
302
author_name = "Meow Meowington"
391
303
commit_message = "feature: add launch codes"
392
304
}
393
- ` , rInt , rInt )
305
+ ` , firstProjectID , secondProjectID )
394
306
}
395
307
396
308
func testAccGitlabRepositoryFileConcurrentResourcesConfig (projectID int ) string {
0 commit comments