-
Notifications
You must be signed in to change notification settings - Fork 288
/
Copy pathresource_check_common_test.go
209 lines (186 loc) · 8.2 KB
/
resource_check_common_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
//go:build (all || resource_check_branch_control) && !exclude_approvalsandchecks
// +build all resource_check_branch_control
// +build !exclude_approvalsandchecks
package acceptancetests
import (
"fmt"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/acceptancetests/testutils"
)
func TestAccCheckEndpoint(t *testing.T) {
projectName := testutils.GenerateResourceName()
checkName := testutils.GenerateResourceName()
branches := "refs/heads/main"
resourceType := "azuredevops_check_branch_control"
tfCheckNode := resourceType + ".test"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testutils.PreCheck(t, nil) },
Providers: testutils.GetProviders(),
CheckDestroy: testutils.CheckPipelineCheckDestroyed(resourceType),
Steps: []resource.TestStep{
{
Config: hclBranchControlCheckResourceBasicEndpoint(projectName, checkName, branches),
Check: resource.ComposeTestCheckFunc(
testutils.CheckPipelineCheckExistsWithName(tfCheckNode, checkName),
resource.TestCheckResourceAttrSet(tfCheckNode, "project_id"),
resource.TestCheckResourceAttr(tfCheckNode, "allowed_branches", branches),
resource.TestCheckResourceAttr(tfCheckNode, "display_name", checkName),
),
},
},
})
}
func hclBranchControlCheckResourceBasicEndpoint(projectName string, checkName string, branches string) string {
serviceEndpointResource := fmt.Sprintf(`
resource "azuredevops_check_branch_control" "test" {
project_id = azuredevops_project.project.id
display_name = "%s"
target_resource_id = azuredevops_serviceendpoint_generic.test.id
allowed_branches = "%s"
target_resource_type = "endpoint"
}`, checkName, branches)
genericServiceEndpointResource := testutils.HclServiceEndpointGenericResource(projectName, "serviceendpoint", "https://test/", "test", "test")
return fmt.Sprintf("%s\n%s", genericServiceEndpointResource, serviceEndpointResource)
}
func TestAccCheckEnvironment(t *testing.T) {
projectName := testutils.GenerateResourceName()
checkName := testutils.GenerateResourceName()
branches := "refs/heads/main"
resourceType := "azuredevops_check_branch_control"
tfCheckNode := resourceType + ".test"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testutils.PreCheck(t, nil) },
Providers: testutils.GetProviders(),
CheckDestroy: testutils.CheckPipelineCheckDestroyed(resourceType),
Steps: []resource.TestStep{
{
Config: hclBranchControlCheckResourceBasicEnvironment(projectName, checkName, branches),
Check: resource.ComposeTestCheckFunc(
testutils.CheckPipelineCheckExistsWithName(tfCheckNode, checkName),
resource.TestCheckResourceAttrSet(tfCheckNode, "project_id"),
resource.TestCheckResourceAttr(tfCheckNode, "allowed_branches", branches),
resource.TestCheckResourceAttr(tfCheckNode, "display_name", checkName),
),
},
},
})
}
func hclBranchControlCheckResourceBasicEnvironment(projectName string, checkName string, branches string) string {
checkResource := fmt.Sprintf(`
resource "azuredevops_check_branch_control" "test" {
project_id = azuredevops_project.project.id
display_name = "%s"
target_resource_id = azuredevops_environment.environment.id
target_resource_type = "environment"
allowed_branches = "%s"
}`, checkName, branches)
environmentResource := testutils.HclEnvironmentResource(projectName, "environment_test")
return fmt.Sprintf("%s\n%s", environmentResource, checkResource)
}
func TestAccCheckQueue(t *testing.T) {
projectName := testutils.GenerateResourceName()
checkName := testutils.GenerateResourceName()
branches := "refs/heads/main"
resourceType := "azuredevops_check_branch_control"
tfCheckNode := resourceType + ".test"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testutils.PreCheck(t, nil) },
Providers: testutils.GetProviders(),
CheckDestroy: testutils.CheckPipelineCheckDestroyed(resourceType),
Steps: []resource.TestStep{
{
Config: hclBranchControlCheckResourceBasicQueue(projectName, checkName, branches),
Check: resource.ComposeTestCheckFunc(
testutils.CheckPipelineCheckExistsWithName(tfCheckNode, checkName),
resource.TestCheckResourceAttrSet(tfCheckNode, "project_id"),
resource.TestCheckResourceAttr(tfCheckNode, "allowed_branches", branches),
resource.TestCheckResourceAttr(tfCheckNode, "display_name", checkName),
),
},
},
})
}
func hclBranchControlCheckResourceBasicQueue(projectName string, checkName string, branches string) string {
checkResource := fmt.Sprintf(`
resource "azuredevops_check_branch_control" "test" {
project_id = azuredevops_project.p.id
display_name = "%s"
target_resource_id = azuredevops_agent_queue.q.id
target_resource_type = "queue"
allowed_branches = "%s"
}`, checkName, branches)
queueResource := testutils.HclAgentQueueResource(projectName, "test_queue")
return fmt.Sprintf("%s\n%s", queueResource, checkResource)
}
func TestAccCheckRepo(t *testing.T) {
projectName := testutils.GenerateResourceName()
checkName := testutils.GenerateResourceName()
branches := "refs/heads/main"
resourceType := "azuredevops_check_branch_control"
tfCheckNode := resourceType + ".test"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testutils.PreCheck(t, nil) },
Providers: testutils.GetProviders(),
CheckDestroy: testutils.CheckPipelineCheckDestroyed(resourceType),
Steps: []resource.TestStep{
{
Config: hclBranchControlCheckResourceBasicRepo(projectName, checkName, branches),
Check: resource.ComposeTestCheckFunc(
testutils.CheckPipelineCheckExistsWithName(tfCheckNode, checkName),
resource.TestCheckResourceAttrSet(tfCheckNode, "project_id"),
resource.TestCheckResourceAttr(tfCheckNode, "allowed_branches", branches),
resource.TestCheckResourceAttr(tfCheckNode, "display_name", checkName),
),
},
},
})
}
func hclBranchControlCheckResourceBasicRepo(projectName string, checkName string, branches string) string {
checkResource := fmt.Sprintf(`
resource "azuredevops_check_branch_control" "test" {
project_id = azuredevops_project.project.id
display_name = "%s"
target_resource_id = "${azuredevops_project.project.id}.${azuredevops_git_repository.repository.id}"
target_resource_type = "repository"
allowed_branches = "%s"
}`, checkName, branches)
projectAndRepoResource := testutils.HclGitRepoResource(projectName, testutils.GenerateResourceName(), "Clean")
return fmt.Sprintf("%s\n%s", projectAndRepoResource, checkResource)
}
func TestAccCheckVariableGroup(t *testing.T) {
projectName := testutils.GenerateResourceName()
checkName := testutils.GenerateResourceName()
branches := "refs/heads/main"
resourceType := "azuredevops_check_branch_control"
tfCheckNode := resourceType + ".test"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testutils.PreCheck(t, nil) },
Providers: testutils.GetProviders(),
CheckDestroy: testutils.CheckPipelineCheckDestroyed(resourceType),
Steps: []resource.TestStep{
{
Config: hclBranchControlCheckResourceBasicVariableGroup(projectName, checkName, branches),
Check: resource.ComposeTestCheckFunc(
testutils.CheckPipelineCheckExistsWithName(tfCheckNode, checkName),
resource.TestCheckResourceAttrSet(tfCheckNode, "project_id"),
resource.TestCheckResourceAttr(tfCheckNode, "allowed_branches", branches),
resource.TestCheckResourceAttr(tfCheckNode, "display_name", checkName),
),
},
},
})
}
func hclBranchControlCheckResourceBasicVariableGroup(projectName string, checkName string, branches string) string {
checkResource := fmt.Sprintf(`
resource "azuredevops_check_branch_control" "test" {
project_id = azuredevops_project.project.id
display_name = "%s"
target_resource_id = azuredevops_variable_group.vg.id
target_resource_type = "variablegroup"
allowed_branches = "%s"
}`, checkName, branches)
variableGroupResource := testutils.HclVariableGroupResource(testutils.GenerateResourceName(), true)
projectResource := testutils.HclProjectResource(projectName)
return fmt.Sprintf("%s\n%s\n%s", variableGroupResource, projectResource, checkResource)
}