|
| 1 | +package github |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" |
| 8 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
| 9 | +) |
| 10 | + |
| 11 | +func TestAccGithubRepositoryCustomPropertiesDataSource(t *testing.T) { |
| 12 | + |
| 13 | + 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 |
| 14 | + singleSelectPropertyName := "single-select" // Needs to be a of type single_select, and have "option1" as an option |
| 15 | + multiSelectPropertyName := "multi-select" // Needs to be a of type multi_select, and have "option1" and "option2" as an options |
| 16 | + trueFlasePropertyName := "true-false" // Needs to be a of type true_false, and have "option1" as an option |
| 17 | + stringPropertyName := "string" // Needs to be a of type string, and have "option1" as an option |
| 18 | + |
| 19 | + randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) |
| 20 | + |
| 21 | + t.Run("creates custom property of type single_select without error", func(t *testing.T) { |
| 22 | + |
| 23 | + config := fmt.Sprintf(` |
| 24 | + resource "github_repository" "test" { |
| 25 | + name = "tf-acc-test-%s" |
| 26 | + auto_init = true |
| 27 | + } |
| 28 | + resource "github_repository_custom_property" "test" { |
| 29 | + repository = github_repository.test.name |
| 30 | + property_name = "%s" |
| 31 | + property_type = "single_select" |
| 32 | + property_value = ["option1"] |
| 33 | + } |
| 34 | + data "github_repository_custom_properties" "test" { |
| 35 | + repository = github_repository_custom_property.test.repository |
| 36 | + } |
| 37 | + `, randomID, singleSelectPropertyName) |
| 38 | + |
| 39 | + check := resource.ComposeTestCheckFunc( |
| 40 | + resource.TestCheckTypeSetElemNestedAttrs("data.github_repository_custom_properties.test", |
| 41 | + "property.*", map[string]string{ |
| 42 | + "property_name": singleSelectPropertyName, |
| 43 | + "property_value.#": "1", |
| 44 | + "property_value.0": "option1", |
| 45 | + }), |
| 46 | + ) |
| 47 | + |
| 48 | + testCase := func(t *testing.T, mode string) { |
| 49 | + resource.Test(t, resource.TestCase{ |
| 50 | + PreCheck: func() { skipUnlessMode(t, mode) }, |
| 51 | + Providers: testAccProviders, |
| 52 | + Steps: []resource.TestStep{ |
| 53 | + { |
| 54 | + Config: config, |
| 55 | + Check: check, |
| 56 | + }, |
| 57 | + }, |
| 58 | + }) |
| 59 | + } |
| 60 | + |
| 61 | + t.Run("with an anonymous account", func(t *testing.T) { |
| 62 | + t.Skip("anonymous account not supported for this operation") |
| 63 | + }) |
| 64 | + |
| 65 | + t.Run("with an individual account", func(t *testing.T) { |
| 66 | + t.Skip("individual account not supported for this operation") |
| 67 | + }) |
| 68 | + |
| 69 | + t.Run("with an organization account", func(t *testing.T) { |
| 70 | + testCase(t, organization) |
| 71 | + }) |
| 72 | + }) |
| 73 | + |
| 74 | + t.Run("creates custom property of type multi_select without error", func(t *testing.T) { |
| 75 | + |
| 76 | + config := fmt.Sprintf(` |
| 77 | + resource "github_repository" "test" { |
| 78 | + name = "tf-acc-test-%s" |
| 79 | + auto_init = true |
| 80 | + } |
| 81 | + resource "github_repository_custom_property" "test" { |
| 82 | + repository = github_repository.test.name |
| 83 | + property_name = "%s" |
| 84 | + property_type = "multi_select" |
| 85 | + property_value = ["option1", "option2"] |
| 86 | + } |
| 87 | + data "github_repository_custom_properties" "test" { |
| 88 | + repository = github_repository_custom_property.test.repository |
| 89 | + } |
| 90 | + `, randomID, multiSelectPropertyName) |
| 91 | + |
| 92 | + check := resource.ComposeTestCheckFunc( |
| 93 | + resource.TestCheckTypeSetElemNestedAttrs("data.github_repository_custom_properties.test", |
| 94 | + "property.*", map[string]string{ |
| 95 | + "property_name": multiSelectPropertyName, |
| 96 | + "property_value.#": "2", |
| 97 | + "property_value.0": "option1", |
| 98 | + "property_value.1": "option2", |
| 99 | + }), |
| 100 | + ) |
| 101 | + |
| 102 | + testCase := func(t *testing.T, mode string) { |
| 103 | + resource.Test(t, resource.TestCase{ |
| 104 | + PreCheck: func() { skipUnlessMode(t, mode) }, |
| 105 | + Providers: testAccProviders, |
| 106 | + Steps: []resource.TestStep{ |
| 107 | + { |
| 108 | + Config: config, |
| 109 | + Check: check, |
| 110 | + }, |
| 111 | + }, |
| 112 | + }) |
| 113 | + } |
| 114 | + |
| 115 | + t.Run("with an anonymous account", func(t *testing.T) { |
| 116 | + t.Skip("anonymous account not supported for this operation") |
| 117 | + }) |
| 118 | + |
| 119 | + t.Run("with an individual account", func(t *testing.T) { |
| 120 | + t.Skip("individual account not supported for this operation") |
| 121 | + }) |
| 122 | + |
| 123 | + t.Run("with an organization account", func(t *testing.T) { |
| 124 | + testCase(t, organization) |
| 125 | + }) |
| 126 | + }) |
| 127 | + |
| 128 | + t.Run("creates custom property of type true_false without error", func(t *testing.T) { |
| 129 | + |
| 130 | + config := fmt.Sprintf(` |
| 131 | + resource "github_repository" "test" { |
| 132 | + name = "tf-acc-test-%s" |
| 133 | + auto_init = true |
| 134 | + } |
| 135 | + resource "github_repository_custom_property" "test" { |
| 136 | + repository = github_repository.test.name |
| 137 | + property_name = "%s" |
| 138 | + property_type = "true_false" |
| 139 | + property_value = ["true"] |
| 140 | + } |
| 141 | + data "github_repository_custom_properties" "test" { |
| 142 | + repository = github_repository_custom_property.test.repository |
| 143 | + } |
| 144 | + `, randomID, trueFlasePropertyName) |
| 145 | + |
| 146 | + check := resource.ComposeTestCheckFunc( |
| 147 | + resource.TestCheckTypeSetElemNestedAttrs("data.github_repository_custom_properties.test", |
| 148 | + "property.*", map[string]string{ |
| 149 | + "property_name": trueFlasePropertyName, |
| 150 | + "property_value.#": "1", |
| 151 | + "property_value.0": "true", |
| 152 | + }), |
| 153 | + ) |
| 154 | + |
| 155 | + testCase := func(t *testing.T, mode string) { |
| 156 | + resource.Test(t, resource.TestCase{ |
| 157 | + PreCheck: func() { skipUnlessMode(t, mode) }, |
| 158 | + Providers: testAccProviders, |
| 159 | + Steps: []resource.TestStep{ |
| 160 | + { |
| 161 | + Config: config, |
| 162 | + Check: check, |
| 163 | + }, |
| 164 | + }, |
| 165 | + }) |
| 166 | + } |
| 167 | + |
| 168 | + t.Run("with an anonymous account", func(t *testing.T) { |
| 169 | + t.Skip("anonymous account not supported for this operation") |
| 170 | + }) |
| 171 | + |
| 172 | + t.Run("with an individual account", func(t *testing.T) { |
| 173 | + t.Skip("individual account not supported for this operation") |
| 174 | + }) |
| 175 | + |
| 176 | + t.Run("with an organization account", func(t *testing.T) { |
| 177 | + testCase(t, organization) |
| 178 | + }) |
| 179 | + }) |
| 180 | + |
| 181 | + t.Run("creates custom property of type string without error", func(t *testing.T) { |
| 182 | + |
| 183 | + config := fmt.Sprintf(` |
| 184 | + resource "github_repository" "test" { |
| 185 | + name = "tf-acc-test-%s" |
| 186 | + auto_init = true |
| 187 | + } |
| 188 | + resource "github_repository_custom_property" "test" { |
| 189 | + repository = github_repository.test.name |
| 190 | + property_name = "%s" |
| 191 | + property_type = "string" |
| 192 | + property_value = ["text"] |
| 193 | + } |
| 194 | + data "github_repository_custom_properties" "test" { |
| 195 | + repository = github_repository_custom_property.test.repository |
| 196 | + } |
| 197 | + `, randomID, stringPropertyName) |
| 198 | + |
| 199 | + check := resource.ComposeTestCheckFunc( |
| 200 | + resource.TestCheckTypeSetElemNestedAttrs("data.github_repository_custom_properties.test", |
| 201 | + "property.*", map[string]string{ |
| 202 | + "property_name": stringPropertyName, |
| 203 | + "property_value.#": "1", |
| 204 | + "property_value.0": "text", |
| 205 | + }), |
| 206 | + ) |
| 207 | + |
| 208 | + testCase := func(t *testing.T, mode string) { |
| 209 | + resource.Test(t, resource.TestCase{ |
| 210 | + PreCheck: func() { skipUnlessMode(t, mode) }, |
| 211 | + Providers: testAccProviders, |
| 212 | + Steps: []resource.TestStep{ |
| 213 | + { |
| 214 | + Config: config, |
| 215 | + Check: check, |
| 216 | + }, |
| 217 | + }, |
| 218 | + }) |
| 219 | + } |
| 220 | + |
| 221 | + t.Run("with an anonymous account", func(t *testing.T) { |
| 222 | + t.Skip("anonymous account not supported for this operation") |
| 223 | + }) |
| 224 | + |
| 225 | + t.Run("with an individual account", func(t *testing.T) { |
| 226 | + t.Skip("individual account not supported for this operation") |
| 227 | + }) |
| 228 | + |
| 229 | + t.Run("with an organization account", func(t *testing.T) { |
| 230 | + testCase(t, organization) |
| 231 | + }) |
| 232 | + }) |
| 233 | +} |
0 commit comments