From 222fc668bf61d0f003586e863a9a287294764f31 Mon Sep 17 00:00:00 2001 From: Jeremy Udit Date: Thu, 15 Apr 2021 18:24:30 -0400 Subject: [PATCH] add test for repository visibility when created by a template --- github/resource_github_repository.go | 6 --- github/resource_github_repository_test.go | 50 +++++++++++++++++++++++ 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/github/resource_github_repository.go b/github/resource_github_repository.go index d755b6d060..ca56fd0b1c 100644 --- a/github/resource_github_repository.go +++ b/github/resource_github_repository.go @@ -240,21 +240,17 @@ func resourceGithubRepository() *schema.Resource { func calculateVisibility(d *schema.ResourceData) string { if value, ok := d.GetOk("visibility"); ok { - log.Printf("[DEBUG] <<<<<<<< calculating visibility as %v", value.(string)) return value.(string) } if value, ok := d.GetOk("private"); ok { if value.(bool) { - log.Printf("[DEBUG] <<<<<<<< calculating private as %v", "private") return "private" } else { - log.Printf("[DEBUG] <<<<<<<< calculating private as %v", "public") return "public" } } - log.Printf("[DEBUG] <<<<<<<< calculating private as %v", "public") return "public" } @@ -319,8 +315,6 @@ func resourceGithubRepositoryCreate(d *schema.ResourceData, meta interface{}) er } } - log.Printf("<<<<<<< Setting visibility to %v", isPrivate) - templateRepoReq := github.TemplateRepoRequest{ Name: &repoName, Owner: &owner, diff --git a/github/resource_github_repository_test.go b/github/resource_github_repository_test.go index 60caa774a0..b46f672f97 100644 --- a/github/resource_github_repository_test.go +++ b/github/resource_github_repository_test.go @@ -957,6 +957,56 @@ func TestAccGithubRepositoryVisibility(t *testing.T) { }) }) + t.Run("sets private visibility for repositories created by a template", func(t *testing.T) { + + config := fmt.Sprintf(` + resource "github_repository" "private" { + name = "tf-acc-test-visibility-private-%s" + visibility = "private" + template { + owner = "%s" + repository = "%s" + } + } + `, randomID, testOrganization, "terraform-template-module") + + check := resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr( + "github_repository.private", "visibility", + "private", + ), + resource.TestCheckResourceAttr( + "github_repository.private", "private", + "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) { + testCase(t, individual) + }) + + t.Run("with an organization account", func(t *testing.T) { + testCase(t, organization) + }) + }) + } func testSweepRepositories(region string) error {