|
| 1 | +package github |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/hashicorp/terraform-plugin-testing/compare" |
| 8 | + "github.com/hashicorp/terraform-plugin-testing/helper/acctest" |
| 9 | + "github.com/hashicorp/terraform-plugin-testing/helper/resource" |
| 10 | + "github.com/hashicorp/terraform-plugin-testing/knownvalue" |
| 11 | + "github.com/hashicorp/terraform-plugin-testing/statecheck" |
| 12 | + "github.com/hashicorp/terraform-plugin-testing/tfjsonpath" |
| 13 | +) |
| 14 | + |
| 15 | +func TestAccGithubRepositoryPagesDataSource(t *testing.T) { |
| 16 | + t.Run("reads_pages_configuration", func(t *testing.T) { |
| 17 | + randomID := acctest.RandString(5) |
| 18 | + repoName := fmt.Sprintf("%spages-ds-%s", testResourcePrefix, randomID) |
| 19 | + |
| 20 | + config := fmt.Sprintf(` |
| 21 | + resource "github_repository" "test" { |
| 22 | + name = "%s" |
| 23 | + visibility = "%s" |
| 24 | + auto_init = true |
| 25 | + } |
| 26 | +
|
| 27 | + resource "github_repository_pages" "test" { |
| 28 | + repository = github_repository.test.name |
| 29 | + build_type = "legacy" |
| 30 | + source { |
| 31 | + branch = "main" |
| 32 | + path = "/" |
| 33 | + } |
| 34 | + } |
| 35 | +
|
| 36 | + data "github_repository_pages" "test" { |
| 37 | + repository = github_repository.test.name |
| 38 | +
|
| 39 | + depends_on = [github_repository_pages.test] |
| 40 | + } |
| 41 | + `, repoName, testAccConf.testRepositoryVisibility) |
| 42 | + |
| 43 | + resource.Test(t, resource.TestCase{ |
| 44 | + PreCheck: func() { |
| 45 | + skipUnauthenticated(t) |
| 46 | + }, |
| 47 | + ProviderFactories: providerFactories, |
| 48 | + Steps: []resource.TestStep{ |
| 49 | + { |
| 50 | + Config: config, |
| 51 | + ConfigStateChecks: []statecheck.StateCheck{ |
| 52 | + statecheck.CompareValuePairs("data.github_repository_pages.test", tfjsonpath.New("build_type"), "github_repository_pages.test", tfjsonpath.New("build_type"), compare.ValuesSame()), |
| 53 | + statecheck.CompareValuePairs("data.github_repository_pages.test", tfjsonpath.New("source").AtSliceIndex(0).AtMapKey("branch"), "github_repository_pages.test", tfjsonpath.New("source").AtSliceIndex(0).AtMapKey("branch"), compare.ValuesSame()), |
| 54 | + statecheck.CompareValuePairs("data.github_repository_pages.test", tfjsonpath.New("source").AtSliceIndex(0).AtMapKey("path"), "github_repository_pages.test", tfjsonpath.New("source").AtSliceIndex(0).AtMapKey("path"), compare.ValuesSame()), |
| 55 | + statecheck.CompareValuePairs("data.github_repository_pages.test", tfjsonpath.New("cname"), "github_repository_pages.test", tfjsonpath.New("cname"), compare.ValuesSame()), |
| 56 | + statecheck.CompareValuePairs("data.github_repository_pages.test", tfjsonpath.New("custom_404"), "github_repository_pages.test", tfjsonpath.New("custom_404"), compare.ValuesSame()), |
| 57 | + statecheck.CompareValuePairs("data.github_repository_pages.test", tfjsonpath.New("html_url"), "github_repository_pages.test", tfjsonpath.New("html_url"), compare.ValuesSame()), |
| 58 | + statecheck.ExpectKnownValue("data.github_repository_pages.test", tfjsonpath.New("build_status"), knownvalue.NotNull()), |
| 59 | + statecheck.CompareValuePairs("data.github_repository_pages.test", tfjsonpath.New("api_url"), "github_repository_pages.test", tfjsonpath.New("api_url"), compare.ValuesSame()), |
| 60 | + statecheck.ExpectKnownValue("data.github_repository_pages.test", tfjsonpath.New("public"), knownvalue.Bool(testAccConf.authMode != enterprise)), |
| 61 | + statecheck.CompareValuePairs("data.github_repository_pages.test", tfjsonpath.New("https_enforced"), "github_repository_pages.test", tfjsonpath.New("https_enforced"), compare.ValuesSame()), |
| 62 | + }, |
| 63 | + }, |
| 64 | + }, |
| 65 | + }) |
| 66 | + }) |
| 67 | + t.Run("reads_pages_enterprise_configuration", func(t *testing.T) { |
| 68 | + randomID := acctest.RandString(5) |
| 69 | + repoName := fmt.Sprintf("%spages-ds-%s", testResourcePrefix, randomID) |
| 70 | + |
| 71 | + config := fmt.Sprintf(` |
| 72 | + resource "github_repository" "test" { |
| 73 | + name = "%s" |
| 74 | + visibility = "%s" |
| 75 | + auto_init = true |
| 76 | + } |
| 77 | +
|
| 78 | + resource "github_repository_pages" "test" { |
| 79 | + repository = github_repository.test.name |
| 80 | + build_type = "legacy" |
| 81 | + source { |
| 82 | + branch = "main" |
| 83 | + path = "/" |
| 84 | + } |
| 85 | + public = false |
| 86 | + } |
| 87 | +
|
| 88 | + data "github_repository_pages" "test" { |
| 89 | + repository = github_repository.test.name |
| 90 | +
|
| 91 | + depends_on = [github_repository_pages.test] |
| 92 | + } |
| 93 | + `, repoName, testAccConf.testRepositoryVisibility) |
| 94 | + |
| 95 | + resource.Test(t, resource.TestCase{ |
| 96 | + PreCheck: func() { skipUnlessEnterprise(t) }, |
| 97 | + ProviderFactories: providerFactories, |
| 98 | + Steps: []resource.TestStep{ |
| 99 | + { |
| 100 | + Config: config, |
| 101 | + ConfigStateChecks: []statecheck.StateCheck{ |
| 102 | + statecheck.CompareValuePairs("data.github_repository_pages.test", tfjsonpath.New("build_type"), "github_repository_pages.test", tfjsonpath.New("build_type"), compare.ValuesSame()), |
| 103 | + statecheck.CompareValuePairs("data.github_repository_pages.test", tfjsonpath.New("source").AtSliceIndex(0).AtMapKey("branch"), "github_repository_pages.test", tfjsonpath.New("source").AtSliceIndex(0).AtMapKey("branch"), compare.ValuesSame()), |
| 104 | + statecheck.CompareValuePairs("data.github_repository_pages.test", tfjsonpath.New("source").AtSliceIndex(0).AtMapKey("path"), "github_repository_pages.test", tfjsonpath.New("source").AtSliceIndex(0).AtMapKey("path"), compare.ValuesSame()), |
| 105 | + statecheck.CompareValuePairs("data.github_repository_pages.test", tfjsonpath.New("cname"), "github_repository_pages.test", tfjsonpath.New("cname"), compare.ValuesSame()), |
| 106 | + statecheck.CompareValuePairs("data.github_repository_pages.test", tfjsonpath.New("custom_404"), "github_repository_pages.test", tfjsonpath.New("custom_404"), compare.ValuesSame()), |
| 107 | + statecheck.CompareValuePairs("data.github_repository_pages.test", tfjsonpath.New("html_url"), "github_repository_pages.test", tfjsonpath.New("html_url"), compare.ValuesSame()), |
| 108 | + statecheck.ExpectKnownValue("data.github_repository_pages.test", tfjsonpath.New("build_status"), knownvalue.NotNull()), |
| 109 | + statecheck.CompareValuePairs("data.github_repository_pages.test", tfjsonpath.New("api_url"), "github_repository_pages.test", tfjsonpath.New("api_url"), compare.ValuesSame()), |
| 110 | + statecheck.CompareValuePairs("data.github_repository_pages.test", tfjsonpath.New("public"), "github_repository_pages.test", tfjsonpath.New("public"), compare.ValuesSame()), |
| 111 | + statecheck.CompareValuePairs("data.github_repository_pages.test", tfjsonpath.New("https_enforced"), "github_repository_pages.test", tfjsonpath.New("https_enforced"), compare.ValuesSame()), |
| 112 | + }, |
| 113 | + }, |
| 114 | + }, |
| 115 | + }) |
| 116 | + }) |
| 117 | +} |
0 commit comments