-
Notifications
You must be signed in to change notification settings - Fork 288
/
Copy pathresource_branchpolicy_min_reviewer_test.go
253 lines (232 loc) · 9.45 KB
/
resource_branchpolicy_min_reviewer_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
//go:build (all || resource_branchpolicy_min_reviewer_acceptance_test || policy) && (!exclude_resource_branchpolicy_min_reviewer_acceptance_test || !exclude_policy)
// +build all resource_branchpolicy_min_reviewer_acceptance_test policy
// +build !exclude_resource_branchpolicy_min_reviewer_acceptance_test !exclude_policy
package acceptancetests
import (
"fmt"
"regexp"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/acceptancetests/testutils"
)
func TestAccBranchPolicyMinReviewers_basic(t *testing.T) {
name := testutils.GenerateResourceName()
node := "azuredevops_branch_policy_min_reviewers.test"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testutils.PreCheck(t, nil) },
Providers: testutils.GetProviders(),
Steps: []resource.TestStep{
{
Config: hclPolicyMinReviewersBasic(1, name),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(node, "id"),
resource.TestCheckResourceAttr(node, "blocking", "true"),
resource.TestCheckResourceAttr(node, "enabled", "true"),
resource.TestCheckResourceAttr(node, "settings.0.submitter_can_vote", "false"),
resource.TestCheckResourceAttr(node, "settings.0.allow_completion_with_rejects_or_waits", "false"),
resource.TestCheckResourceAttr(node, "settings.0.last_pusher_cannot_approve", "false"),
resource.TestCheckResourceAttr(node, "settings.0.on_last_iteration_require_vote", "false"),
resource.TestCheckResourceAttr(node, "settings.0.on_push_reset_approved_votes", "true"),
),
}, {
ResourceName: node,
ImportStateIdFunc: testutils.ComputeProjectQualifiedResourceImportID(node),
ImportState: true,
ImportStateVerify: true,
},
},
})
}
func TestAccBranchPolicyMinReviewers_update(t *testing.T) {
name := testutils.GenerateResourceName()
node := "azuredevops_branch_policy_min_reviewers.test"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testutils.PreCheck(t, nil) },
Providers: testutils.GetProviders(),
Steps: []resource.TestStep{
{
Config: hclPolicyMinReviewersBasic(1, name),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(node, "id"),
resource.TestCheckResourceAttr(node, "blocking", "true"),
resource.TestCheckResourceAttr(node, "enabled", "true"),
resource.TestCheckResourceAttr(node, "settings.0.submitter_can_vote", "false"),
resource.TestCheckResourceAttr(node, "settings.0.allow_completion_with_rejects_or_waits", "false"),
resource.TestCheckResourceAttr(node, "settings.0.last_pusher_cannot_approve", "false"),
resource.TestCheckResourceAttr(node, "settings.0.on_last_iteration_require_vote", "false"),
resource.TestCheckResourceAttr(node, "settings.0.on_push_reset_approved_votes", "true"),
),
}, {
Config: hclPolicyMinReviewersUpdate(2, name),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(node, "id"),
resource.TestCheckResourceAttr(node, "blocking", "false"),
resource.TestCheckResourceAttr(node, "enabled", "false"),
resource.TestCheckResourceAttr(node, "settings.0.submitter_can_vote", "true"),
resource.TestCheckResourceAttr(node, "settings.0.allow_completion_with_rejects_or_waits", "true"),
resource.TestCheckResourceAttr(node, "settings.0.last_pusher_cannot_approve", "true"),
resource.TestCheckResourceAttr(node, "settings.0.on_last_iteration_require_vote", "true"),
resource.TestCheckResourceAttr(node, "settings.0.on_push_reset_all_votes", "false"),
),
}, {
ResourceName: node,
ImportStateIdFunc: testutils.ComputeProjectQualifiedResourceImportID(node),
ImportState: true,
ImportStateVerify: true,
},
},
})
}
func TestAccBranchPolicyMinReviewers_resetAllVote(t *testing.T) {
name := testutils.GenerateResourceName()
node := "azuredevops_branch_policy_min_reviewers.test"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testutils.PreCheck(t, nil) },
Providers: testutils.GetProviders(),
Steps: []resource.TestStep{
{
Config: hclPolicyMinReviewersResetAllVote(name),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(node, "id"),
resource.TestCheckResourceAttr(node, "blocking", "true"),
resource.TestCheckResourceAttr(node, "enabled", "true"),
resource.TestCheckResourceAttr(node, "settings.0.submitter_can_vote", "false"),
resource.TestCheckResourceAttr(node, "settings.0.on_push_reset_all_votes", "true"),
resource.TestCheckResourceAttr(node, "settings.0.on_push_reset_approved_votes", "true"),
),
}, {
ResourceName: node,
ImportStateIdFunc: testutils.ComputeProjectQualifiedResourceImportID(node),
ImportState: true,
ImportStateVerify: true,
},
},
})
}
func TestAccBranchPolicyMinReviewers_requiresImportError(t *testing.T) {
name := testutils.GenerateResourceName()
node := "azuredevops_branch_policy_min_reviewers.test"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testutils.PreCheck(t, nil) },
Providers: testutils.GetProviders(),
Steps: []resource.TestStep{
{
Config: hclPolicyMinReviewersResetAllVote(name),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(node, "id"),
resource.TestCheckResourceAttr(node, "blocking", "true"),
resource.TestCheckResourceAttr(node, "enabled", "true"),
resource.TestCheckResourceAttr(node, "settings.0.submitter_can_vote", "false"),
resource.TestCheckResourceAttr(node, "settings.0.on_push_reset_all_votes", "true"),
resource.TestCheckResourceAttr(node, "settings.0.on_push_reset_approved_votes", "true"),
),
}, {
Config: hclPolicyMinReviewersResetRequireImportError(name),
ExpectError: regexp.MustCompile(` creating policy in Azure DevOps: The update is rejected by policy`),
},
},
})
}
func hclPolicyMinReviewersTemplate(name string) string {
return fmt.Sprintf(`
resource "azuredevops_project" "test" {
name = "%[1]s"
visibility = "private"
version_control = "Git"
work_item_template = "Agile"
}
data "azuredevops_git_repository" "test" {
project_id = azuredevops_project.test.id
name = "%[1]s"
}
`, name)
}
func hclPolicyMinReviewersBasic(reviewers int, name string) string {
template := hclPolicyMinReviewersTemplate(name)
return fmt.Sprintf(`
%s
resource "azuredevops_branch_policy_min_reviewers" "test" {
project_id = azuredevops_project.test.id
enabled = true
blocking = true
settings {
reviewer_count = %[2]d
submitter_can_vote = false
allow_completion_with_rejects_or_waits = false
on_push_reset_approved_votes = true
scope {
repository_id = data.azuredevops_git_repository.test.id
repository_ref = "refs/heads/release"
match_type = "Exact"
}
}
}
`, template, reviewers)
}
func hclPolicyMinReviewersUpdate(reviewers int, name string) string {
template := hclPolicyMinReviewersTemplate(name)
return fmt.Sprintf(`
%s
resource "azuredevops_branch_policy_min_reviewers" "test" {
project_id = azuredevops_project.test.id
enabled = false
blocking = false
settings {
reviewer_count = %[2]d
submitter_can_vote = true
allow_completion_with_rejects_or_waits = true
last_pusher_cannot_approve = true
on_last_iteration_require_vote = true
scope {
repository_id = data.azuredevops_git_repository.test.id
repository_ref = "refs/heads/release"
match_type = "Exact"
}
}
}
`, template, reviewers)
}
func hclPolicyMinReviewersResetAllVote(name string) string {
template := hclPolicyMinReviewersTemplate(name)
return fmt.Sprintf(`
%s
resource "azuredevops_branch_policy_min_reviewers" "test" {
project_id = azuredevops_project.test.id
enabled = true
blocking = true
settings {
reviewer_count = 2
submitter_can_vote = false
on_push_reset_all_votes = true
on_push_reset_approved_votes = true
scope {
repository_id = data.azuredevops_git_repository.test.id
repository_ref = "refs/heads/release"
match_type = "Exact"
}
}
}
`, template)
}
func hclPolicyMinReviewersResetRequireImportError(name string) string {
template := hclPolicyMinReviewersResetAllVote(name)
return fmt.Sprintf(`
%s
resource "azuredevops_branch_policy_min_reviewers" "import" {
project_id = azuredevops_branch_policy_min_reviewers.test.project_id
enabled = azuredevops_branch_policy_min_reviewers.test.enabled
blocking = azuredevops_branch_policy_min_reviewers.test.blocking
settings {
reviewer_count = azuredevops_branch_policy_min_reviewers.test.settings.0.reviewer_count
submitter_can_vote = azuredevops_branch_policy_min_reviewers.test.settings.0.submitter_can_vote
on_push_reset_all_votes = azuredevops_branch_policy_min_reviewers.test.settings.0.on_push_reset_all_votes
on_push_reset_approved_votes = azuredevops_branch_policy_min_reviewers.test.settings.0.on_push_reset_approved_votes
scope {
repository_id = azuredevops_branch_policy_min_reviewers.test.settings.0.scope.0.repository_id
repository_ref = azuredevops_branch_policy_min_reviewers.test.settings.0.scope.0.repository_ref
match_type = azuredevops_branch_policy_min_reviewers.test.settings.0.scope.0.match_type
}
}
}
`, template)
}