forked from integrations/terraform-provider-github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_source_github_repository_custom_properties_test.go
More file actions
233 lines (200 loc) · 7.19 KB
/
data_source_github_repository_custom_properties_test.go
File metadata and controls
233 lines (200 loc) · 7.19 KB
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
package github
import (
"fmt"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)
func TestAccGithubRepositoryCustomPropertiesDataSource(t *testing.T) {
t.Skip("You need an org with custom properties already setup as described in the variables below") // TODO: at the time of writing org_custom_properties are not supported by this terraform provider, so cant be setup in the test itself for now
singleSelectPropertyName := "single-select" // Needs to be a of type single_select, and have "option1" as an option
multiSelectPropertyName := "multi-select" // Needs to be a of type multi_select, and have "option1" and "option2" as an options
trueFlasePropertyName := "true-false" // Needs to be a of type true_false, and have "option1" as an option
stringPropertyName := "string" // Needs to be a of type string, and have "option1" as an option
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
t.Run("creates custom property of type single_select without error", func(t *testing.T) {
config := fmt.Sprintf(`
resource "github_repository" "test" {
name = "tf-acc-test-%s"
auto_init = true
}
resource "github_repository_custom_property" "test" {
repository = github_repository.test.name
property_name = "%s"
property_type = "single_select"
property_value = ["option1"]
}
data "github_repository_custom_properties" "test" {
repository = github_repository_custom_property.test.repository
}
`, randomID, singleSelectPropertyName)
check := resource.ComposeTestCheckFunc(
resource.TestCheckTypeSetElemNestedAttrs("data.github_repository_custom_properties.test",
"property.*", map[string]string{
"property_name": singleSelectPropertyName,
"property_value.#": "1",
"property_value.0": "option1",
}),
)
testCase := func(t *testing.T, mode string) {
resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessMode(t, mode) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: config,
Check: check,
},
},
})
}
t.Run("with an anonymous account", func(t *testing.T) {
t.Skip("anonymous account not supported for this operation")
})
t.Run("with an individual account", func(t *testing.T) {
t.Skip("individual account not supported for this operation")
})
t.Run("with an organization account", func(t *testing.T) {
testCase(t, organization)
})
})
t.Run("creates custom property of type multi_select without error", func(t *testing.T) {
config := fmt.Sprintf(`
resource "github_repository" "test" {
name = "tf-acc-test-%s"
auto_init = true
}
resource "github_repository_custom_property" "test" {
repository = github_repository.test.name
property_name = "%s"
property_type = "multi_select"
property_value = ["option1", "option2"]
}
data "github_repository_custom_properties" "test" {
repository = github_repository_custom_property.test.repository
}
`, randomID, multiSelectPropertyName)
check := resource.ComposeTestCheckFunc(
resource.TestCheckTypeSetElemNestedAttrs("data.github_repository_custom_properties.test",
"property.*", map[string]string{
"property_name": multiSelectPropertyName,
"property_value.#": "2",
"property_value.0": "option1",
"property_value.1": "option2",
}),
)
testCase := func(t *testing.T, mode string) {
resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessMode(t, mode) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: config,
Check: check,
},
},
})
}
t.Run("with an anonymous account", func(t *testing.T) {
t.Skip("anonymous account not supported for this operation")
})
t.Run("with an individual account", func(t *testing.T) {
t.Skip("individual account not supported for this operation")
})
t.Run("with an organization account", func(t *testing.T) {
testCase(t, organization)
})
})
t.Run("creates custom property of type true_false without error", func(t *testing.T) {
config := fmt.Sprintf(`
resource "github_repository" "test" {
name = "tf-acc-test-%s"
auto_init = true
}
resource "github_repository_custom_property" "test" {
repository = github_repository.test.name
property_name = "%s"
property_type = "true_false"
property_value = ["true"]
}
data "github_repository_custom_properties" "test" {
repository = github_repository_custom_property.test.repository
}
`, randomID, trueFlasePropertyName)
check := resource.ComposeTestCheckFunc(
resource.TestCheckTypeSetElemNestedAttrs("data.github_repository_custom_properties.test",
"property.*", map[string]string{
"property_name": trueFlasePropertyName,
"property_value.#": "1",
"property_value.0": "true",
}),
)
testCase := func(t *testing.T, mode string) {
resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessMode(t, mode) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: config,
Check: check,
},
},
})
}
t.Run("with an anonymous account", func(t *testing.T) {
t.Skip("anonymous account not supported for this operation")
})
t.Run("with an individual account", func(t *testing.T) {
t.Skip("individual account not supported for this operation")
})
t.Run("with an organization account", func(t *testing.T) {
testCase(t, organization)
})
})
t.Run("creates custom property of type string without error", func(t *testing.T) {
config := fmt.Sprintf(`
resource "github_repository" "test" {
name = "tf-acc-test-%s"
auto_init = true
}
resource "github_repository_custom_property" "test" {
repository = github_repository.test.name
property_name = "%s"
property_type = "string"
property_value = ["text"]
}
data "github_repository_custom_properties" "test" {
repository = github_repository_custom_property.test.repository
}
`, randomID, stringPropertyName)
check := resource.ComposeTestCheckFunc(
resource.TestCheckTypeSetElemNestedAttrs("data.github_repository_custom_properties.test",
"property.*", map[string]string{
"property_name": stringPropertyName,
"property_value.#": "1",
"property_value.0": "text",
}),
)
testCase := func(t *testing.T, mode string) {
resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessMode(t, mode) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: config,
Check: check,
},
},
})
}
t.Run("with an anonymous account", func(t *testing.T) {
t.Skip("anonymous account not supported for this operation")
})
t.Run("with an individual account", func(t *testing.T) {
t.Skip("individual account not supported for this operation")
})
t.Run("with an organization account", func(t *testing.T) {
testCase(t, organization)
})
})
}