-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathresource_project_test.go
365 lines (333 loc) · 10.1 KB
/
resource_project_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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
package main
import (
"fmt"
//"log"
//"regexp"
//"strings"
//"math/rand"
"reflect"
"testing"
//"time"
//"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
"github.com/umweltdk/teamcity/teamcity"
"github.com/umweltdk/teamcity/types"
)
var testAccProject = `
resource "teamcity_project" "bar" {
parent = "Single"
name = "bar"
parameter {
name = "env.MUH"
type = "password"
}
parameter {
name = "env.TEST"
type = "text"
validation_mode = "not_empty"
label = "Test framework"
description = "Name of the test framework to use"
}
parameter_values {
"env.MUH" = "Hush Hush"
"env.TEST" = "Hello"
}
}`
func TestAccProject_basic(t *testing.T) {
var v types.Project
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckProjectDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccProject,
Check: resource.ComposeTestCheckFunc(
testAccCheckProjectExists("teamcity_project.bar", &v),
testAccCheckProjectAttributes(&v),
testAccCheckProjectParameters(&v, &types.Parameters{
"env.TEST": types.Parameter{
Value: "Hello",
Spec: &types.ParameterSpec{
Label: "Test framework",
Description: "Name of the test framework to use",
Type: types.TextType{"not_empty"},
},
},
"env.MUH": types.Parameter{
Spec: &types.ParameterSpec{
Type: types.PasswordType{},
},
},
}),
resource.TestCheckResourceAttr(
"teamcity_project.bar", "parent", "Single"),
resource.TestCheckResourceAttr(
"teamcity_project.bar", "name", "bar"),
resource.TestCheckResourceAttr(
"teamcity_project.bar", "description", ""),
resource.TestCheckResourceAttr(
"teamcity_project.bar", "parameter_values.env.TEST", "Hello"),
testAccCheckParameter("teamcity_project.bar", "env.MUH", types.ParameterSpec{
Type: types.PasswordType{},
}),
testAccCheckParameter("teamcity_project.bar", "env.TEST", types.ParameterSpec{
Label: "Test framework",
Description: "Name of the test framework to use",
Type: types.TextType{"not_empty"},
}),
resource.TestCheckResourceAttr(
"teamcity_project.bar", "parameter.#", "2"),
),
},
},
})
}
var testAccProjectParentParameter = `
resource "teamcity_project" "parent" {
name = "Parent"
parameter {
name = "env.CLOVER"
type = "text"
validation_mode = "any"
}
parameter {
name = "env.GROVER"
type = "text"
validation_mode = "any"
}
parameter_values = {
"env.OVER" = "Parent"
}
}
resource "teamcity_project" "bar" {
parent = "${teamcity_project.parent.id}"
name = "Bar"
parameter {
name = "env.OVER"
type = "checkbox"
checked_value = "Hello"
}
parameter {
name = "env.PLOVER"
type = "checkbox"
checked_value = "Hello"
}
parameter_values {
"env.OVER" = "Owner"
}
}`
var testAccProjectParentParameterUpdate = `
resource "teamcity_project" "parent" {
name = "Parent"
parameter {
name = "env.CLOVER"
type = "text"
validation_mode = "any"
}
parameter {
name = "env.PLOVER"
type = "text"
validation_mode = "any"
}
parameter_values = {
"env.OVER" = "Parent"
"env.PLOVER" = "Parent"
}
}
resource "teamcity_project" "bar" {
parent = "${teamcity_project.parent.id}"
name = "Bar"
parameter {
name = "env.OVER"
type = "checkbox"
checked_value = "Hello"
}
parameter {
name = "env.MOVER"
type = "checkbox"
unchecked_value = "Hello"
}
parameter_values {
"env.OVER" = "Owner"
"env.PLOVER" = "Owner"
}
}`
func TestAccProject_parentParameters(t *testing.T) {
var v types.Project
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckProjectDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccProjectParentParameter,
Check: resource.ComposeTestCheckFunc(
testAccCheckProjectExists("teamcity_project.bar", &v),
testAccCheckProjectAttributes(&v),
testAccCheckProjectParameters(&v, &types.Parameters{
"env.OVER": types.Parameter{
Value: "Owner",
Spec: &types.ParameterSpec{
Type: types.CheckboxType{"Hello", ""},
},
},
"env.CLOVER": types.Parameter{
Value: "",
Spec: &types.ParameterSpec{
Type: types.TextType{"any"},
},
},
"env.GROVER": types.Parameter{
Value: "",
Spec: &types.ParameterSpec{
Type: types.TextType{"any"},
},
},
"env.PLOVER": types.Parameter{
Value: "",
Spec: &types.ParameterSpec{
Type: types.CheckboxType{"Hello", ""},
},
},
}),
resource.TestCheckResourceAttr(
"teamcity_project.bar", "parent", "Parent"),
resource.TestCheckResourceAttr(
"teamcity_project.bar", "name", "Bar"),
resource.TestCheckResourceAttr(
"teamcity_project.bar", "description", ""),
resource.TestCheckResourceAttr(
"teamcity_project.bar", "parameter_values.env.OVER", "Owner"),
testAccCheckParameter("teamcity_project.bar", "env.OVER", types.ParameterSpec{
Type: types.CheckboxType{Checked: "Hello",},
}),
testAccCheckParameter("teamcity_project.bar", "env.PLOVER", types.ParameterSpec{
Type: types.CheckboxType{Checked: "Hello",},
}),
resource.TestCheckResourceAttr(
"teamcity_project.bar", "parameter.#", "2"),
),
},
resource.TestStep{
Config: testAccProjectParentParameterUpdate,
Check: resource.ComposeTestCheckFunc(
testAccCheckProjectExists("teamcity_project.bar", &v),
testAccCheckProjectAttributes(&v),
testAccCheckProjectParameters(&v, &types.Parameters{
"env.OVER": types.Parameter{
Value: "Owner",
Spec: &types.ParameterSpec{
Type: types.CheckboxType{"Hello", ""},
},
},
"env.MOVER": types.Parameter{
Value: "",
Spec: &types.ParameterSpec{
Type: types.CheckboxType{"", "Hello"},
},
},
"env.CLOVER": types.Parameter{
Value: "",
Spec: &types.ParameterSpec{
Type: types.TextType{"any"},
},
},
"env.PLOVER": types.Parameter{
Value: "Owner",
Spec: &types.ParameterSpec{
Type: types.TextType{"any"},
},
},
}),
resource.TestCheckResourceAttr(
"teamcity_project.bar", "parent", "Parent"),
resource.TestCheckResourceAttr(
"teamcity_project.bar", "name", "Bar"),
resource.TestCheckResourceAttr(
"teamcity_project.bar", "description", ""),
resource.TestCheckResourceAttr(
"teamcity_project.bar", "parameter_values.env.OVER", "Owner"),
resource.TestCheckResourceAttr(
"teamcity_project.bar", "parameter_values.env.PLOVER", "Owner"),
//resource.TestCheckResourceAttr(
// "teamcity_project.bar", "parameter_values.#", "2"),
testAccCheckParameter("teamcity_project.bar", "env.OVER", types.ParameterSpec{
Type: types.CheckboxType{Checked: "Hello",},
}),
testAccCheckParameter("teamcity_project.bar", "env.MOVER", types.ParameterSpec{
Type: types.CheckboxType{Unchecked: "Hello",},
}),
resource.TestCheckResourceAttr(
"teamcity_project.bar", "parameter.#", "2"),
),
},
},
})
}
func testAccCheckProjectDestroy(s *terraform.State) error {
client := testAccProvider.Meta().(*teamcity.Client)
for _, rs := range s.RootModule().Resources {
if rs.Type != "teamcity_project" {
continue
}
// Try to find the Group
var err error
project, err := client.GetProject(rs.Primary.ID)
if err == nil && project == nil {
continue
}
if err == nil {
return fmt.Errorf("Project still exists")
}
return err
}
return nil
}
func testAccCheckProjectAttributes(v *types.Project) resource.TestCheckFunc {
return func(s *terraform.State) error {
/*
if *v.Engine != "mysql" {
return fmt.Errorf("bad engine: %#v", *v.Engine)
}
if *v.EngineVersion == "" {
return fmt.Errorf("bad engine_version: %#v", *v.EngineVersion)
}
if *v.BackupRetentionPeriod != 0 {
return fmt.Errorf("bad backup_retention_period: %#v", *v.BackupRetentionPeriod)
}
*/
return nil
}
}
func testAccCheckProjectParameters(v *types.Project, e *types.Parameters) resource.TestCheckFunc {
return func(s *terraform.State) error {
expected := *e
if !reflect.DeepEqual(v.Parameters, expected) {
return fmt.Errorf("bad parameters: %q %q", v.Parameters, expected)
}
return nil
}
}
func testAccCheckProjectExists(n string, v *types.Project) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}
if rs.Primary.ID == "" {
return fmt.Errorf("No Project ID is set")
}
client := testAccProvider.Meta().(*teamcity.Client)
project, err := client.GetProject(rs.Primary.ID)
if err != nil {
return err
}
if project == nil {
return fmt.Errorf("Project not found")
}
*v = *project
return nil
}
}