@@ -24,14 +24,51 @@ func TestAccGitlabDeployKeyEnable_basic(t *testing.T) {
24
24
Providers : testAccProviders ,
25
25
CheckDestroy : testAccCheckGitlabDeployKeyEnableDestroy ,
26
26
Steps : []resource.TestStep {
27
- // Create a project and deployKey with default options
27
+ // Enable a deployKey on project with default options
28
28
{
29
29
Config : testAccGitlabDeployKeyEnableConfig (rInt , keyTitle , key ),
30
30
Check : resource .ComposeTestCheckFunc (
31
31
testAccCheckGitlabDeployKeyEnableExists ("gitlab_deploy_key_enable.foo" , & deployKey ),
32
32
testAccCheckGitlabDeployKeyEnableAttributes (& deployKey , & testAccGitlabDeployKeyEnableExpectedAttributes {
33
- Title : keyTitle ,
34
- Key : key ,
33
+ Title : keyTitle ,
34
+ Key : key ,
35
+ CanPush : false ,
36
+ }),
37
+ ),
38
+ },
39
+ // Define canPush to true
40
+ {
41
+ Config : testAccGitlabDeployKeyEnableConfigCanPush (rInt , keyTitle , key , true ),
42
+ Check : resource .ComposeTestCheckFunc (
43
+ testAccCheckGitlabDeployKeyEnableExists ("gitlab_deploy_key_enable.foo" , & deployKey ),
44
+ testAccCheckGitlabDeployKeyEnableAttributes (& deployKey , & testAccGitlabDeployKeyEnableExpectedAttributes {
45
+ Title : keyTitle ,
46
+ Key : key ,
47
+ CanPush : true ,
48
+ }),
49
+ ),
50
+ },
51
+ // Define canPush to false
52
+ {
53
+ Config : testAccGitlabDeployKeyEnableConfigCanPush (rInt , keyTitle , key , false ),
54
+ Check : resource .ComposeTestCheckFunc (
55
+ testAccCheckGitlabDeployKeyEnableExists ("gitlab_deploy_key_enable.foo" , & deployKey ),
56
+ testAccCheckGitlabDeployKeyEnableAttributes (& deployKey , & testAccGitlabDeployKeyEnableExpectedAttributes {
57
+ Title : keyTitle ,
58
+ Key : key ,
59
+ CanPush : false ,
60
+ }),
61
+ ),
62
+ },
63
+ // Get back to default options
64
+ {
65
+ Config : testAccGitlabDeployKeyEnableConfig (rInt , keyTitle , key ),
66
+ Check : resource .ComposeTestCheckFunc (
67
+ testAccCheckGitlabDeployKeyEnableExists ("gitlab_deploy_key_enable.foo" , & deployKey ),
68
+ testAccCheckGitlabDeployKeyEnableAttributes (& deployKey , & testAccGitlabDeployKeyEnableExpectedAttributes {
69
+ Title : keyTitle ,
70
+ Key : key ,
71
+ CanPush : false ,
35
72
}),
36
73
),
37
74
},
@@ -137,8 +174,8 @@ resource "gitlab_project" "foo" {
137
174
138
175
resource "gitlab_deploy_key" "parent" {
139
176
project = "${gitlab_project.parent.id}"
140
- title = "%s"
141
- key = "%s"
177
+ title = "%s"
178
+ key = "%s"
142
179
}
143
180
144
181
resource "gitlab_deploy_key_enable" "foo" {
@@ -147,3 +184,37 @@ resource "gitlab_deploy_key_enable" "foo" {
147
184
}
148
185
` , rInt , rInt , keyTitle , key )
149
186
}
187
+
188
+ func testAccGitlabDeployKeyEnableConfigCanPush (rInt int , keyTitle string , key string , canPush bool ) string {
189
+ return fmt .Sprintf (`
190
+ resource "gitlab_project" "parent" {
191
+ name = "parent-%d"
192
+ description = "Terraform acceptance tests - Parent project"
193
+
194
+ # So that acceptance tests can be run in a gitlab organization
195
+ # with no billing
196
+ visibility_level = "public"
197
+ }
198
+
199
+ resource "gitlab_project" "foo" {
200
+ name = "foo-%d"
201
+ description = "Terraform acceptance tests - Test Project"
202
+
203
+ # So that acceptance tests can be run in a gitlab organization
204
+ # with no billing
205
+ visibility_level = "public"
206
+ }
207
+
208
+ resource "gitlab_deploy_key" "parent" {
209
+ project = "${gitlab_project.parent.id}"
210
+ title = "%s"
211
+ key = "%s"
212
+ }
213
+
214
+ resource "gitlab_deploy_key_enable" "foo" {
215
+ project = "${gitlab_project.foo.id}"
216
+ key_id = "${gitlab_deploy_key.parent.id}"
217
+ can_push = %t
218
+ }
219
+ ` , rInt , rInt , keyTitle , key , canPush )
220
+ }
0 commit comments