From 087842934ee3aa78e30f7f77e3a4ce02803b536c Mon Sep 17 00:00:00 2001 From: Jeremy Udit Date: Tue, 15 Sep 2020 11:44:47 -0400 Subject: [PATCH] archives repositories on destroy --- .github/workflows/dotcom-acceptance-tests.yml | 1 + github/resource_github_repository_test.go | 59 +++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/.github/workflows/dotcom-acceptance-tests.yml b/.github/workflows/dotcom-acceptance-tests.yml index 5bf4015412..cea917665c 100644 --- a/.github/workflows/dotcom-acceptance-tests.yml +++ b/.github/workflows/dotcom-acceptance-tests.yml @@ -1,6 +1,7 @@ name: Dotcom Acceptance Tests on: + push: pull_request: types: [opened, synchronize, reopened] diff --git a/github/resource_github_repository_test.go b/github/resource_github_repository_test.go index 3031c07c26..75e5fbcc18 100644 --- a/github/resource_github_repository_test.go +++ b/github/resource_github_repository_test.go @@ -432,6 +432,65 @@ func TestAccGithubRepositories(t *testing.T) { }) + t.Run("archives repositories on destroy", func(t *testing.T) { + + config := fmt.Sprintf(` + resource "github_repository" "test" { + name = "tf-acc-test-%[1]s" + auto_init = true + archive_on_destroy = true + archived = false + } + `, randomID) + + checks := map[string]resource.TestCheckFunc{ + "before": resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr( + "github_repository.test", "archived", + "false", + ), + ), + "after": resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr( + "github_repository.test", "archived", + "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: checks["before"], + }, + { + Config: strings.Replace(config, + `archived = false`, + `archived = true`, 1), + Check: checks["after"], + }, + }, + }) + } + + 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 {