|
| 1 | +package github |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/hashicorp/terraform-plugin-testing/helper/resource" |
| 7 | +) |
| 8 | + |
| 9 | +func TestAccGithubClientConfigDataSource(t *testing.T) { |
| 10 | + t.Run("reads provider configuration without error", func(t *testing.T) { |
| 11 | + config := `data "github_client_config" "test" {}` |
| 12 | + |
| 13 | + check := resource.ComposeTestCheckFunc( |
| 14 | + resource.TestCheckResourceAttr("data.github_client_config.test", "owner", testAccConf.owner), |
| 15 | + resource.TestCheckResourceAttr("data.github_client_config.test", "username", testAccConf.username), |
| 16 | + resource.TestCheckResourceAttr("data.github_client_config.test", "base_url", testAccConf.baseURL.String()), |
| 17 | + resource.TestCheckResourceAttrSet("data.github_client_config.test", "is_organization"), |
| 18 | + resource.TestCheckResourceAttrSet("data.github_client_config.test", "id"), |
| 19 | + ) |
| 20 | + |
| 21 | + resource.Test(t, resource.TestCase{ |
| 22 | + PreCheck: func() { skipUnauthenticated(t) }, |
| 23 | + ProviderFactories: providerFactories, |
| 24 | + Steps: []resource.TestStep{ |
| 25 | + { |
| 26 | + Config: config, |
| 27 | + Check: check, |
| 28 | + }, |
| 29 | + }, |
| 30 | + }) |
| 31 | + }) |
| 32 | + |
| 33 | + t.Run("reads provider configuration in anonymous mode", func(t *testing.T) { |
| 34 | + if testAccConf.authMode != anonymous { |
| 35 | + t.Skip("Skipping as test mode is not anonymous") |
| 36 | + } |
| 37 | + |
| 38 | + config := `data "github_client_config" "test" {}` |
| 39 | + |
| 40 | + check := resource.ComposeTestCheckFunc( |
| 41 | + resource.TestCheckResourceAttr("data.github_client_config.test", "owner", ""), |
| 42 | + resource.TestCheckResourceAttr("data.github_client_config.test", "username", ""), |
| 43 | + resource.TestCheckResourceAttr("data.github_client_config.test", "is_organization", "false"), |
| 44 | + resource.TestCheckResourceAttrSet("data.github_client_config.test", "base_url"), |
| 45 | + resource.TestCheckResourceAttrSet("data.github_client_config.test", "id"), |
| 46 | + ) |
| 47 | + |
| 48 | + resource.Test(t, resource.TestCase{ |
| 49 | + ProviderFactories: providerFactories, |
| 50 | + Steps: []resource.TestStep{ |
| 51 | + { |
| 52 | + Config: config, |
| 53 | + Check: check, |
| 54 | + }, |
| 55 | + }, |
| 56 | + }) |
| 57 | + }) |
| 58 | +} |
0 commit comments