|
| 1 | +package github |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "strings" |
| 6 | + "testing" |
| 7 | + |
| 8 | + "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" |
| 9 | + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" |
| 10 | +) |
| 11 | + |
| 12 | +func TestAccGithubCodespacesOrganizationSecretsDataSource(t *testing.T) { |
| 13 | + |
| 14 | + t.Run("queries organization codespaces secrets from a repository", func(t *testing.T) { |
| 15 | + randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) |
| 16 | + |
| 17 | + config := fmt.Sprintf(` |
| 18 | + resource "github_codespaces_organization_secret" "test" { |
| 19 | + secret_name = "org_cs_secret_1_%s" |
| 20 | + plaintext_value = "foo" |
| 21 | + visibility = "private" |
| 22 | + } |
| 23 | + `, randomID) |
| 24 | + |
| 25 | + config2 := config + ` |
| 26 | + data "github_codespaces_organization_secrets" "test" { |
| 27 | + } |
| 28 | + ` |
| 29 | + |
| 30 | + check := resource.ComposeTestCheckFunc( |
| 31 | + resource.TestCheckResourceAttr("data.github_codespaces_organization_secrets.test", "secrets.#", "1"), |
| 32 | + resource.TestCheckResourceAttr("data.github_codespaces_organization_secrets.test", "secrets.0.name", strings.ToUpper(fmt.Sprintf("ORG_CS_SECRET_1_%s", randomID))), |
| 33 | + resource.TestCheckResourceAttr("data.github_codespaces_organization_secrets.test", "secrets.0.visibility", "private"), |
| 34 | + resource.TestCheckResourceAttrSet("data.github_codespaces_organization_secrets.test", "secrets.0.created_at"), |
| 35 | + resource.TestCheckResourceAttrSet("data.github_codespaces_organization_secrets.test", "secrets.0.updated_at"), |
| 36 | + ) |
| 37 | + |
| 38 | + testCase := func(t *testing.T, mode string) { |
| 39 | + resource.Test(t, resource.TestCase{ |
| 40 | + PreCheck: func() { skipUnlessMode(t, mode) }, |
| 41 | + Providers: testAccProviders, |
| 42 | + Steps: []resource.TestStep{ |
| 43 | + { |
| 44 | + Config: config, |
| 45 | + Check: resource.ComposeTestCheckFunc(), |
| 46 | + }, |
| 47 | + { |
| 48 | + Config: config2, |
| 49 | + Check: check, |
| 50 | + }, |
| 51 | + }, |
| 52 | + }) |
| 53 | + } |
| 54 | + |
| 55 | + t.Run("with an organization account", func(t *testing.T) { |
| 56 | + testCase(t, organization) |
| 57 | + }) |
| 58 | + }) |
| 59 | +} |
0 commit comments