Skip to content

Commit 3926e7f

Browse files
committed
docs: Adds test to verify that unarchiving does work and update docs
Signed-off-by: Timo Sand <[email protected]>
1 parent d103f9b commit 3926e7f

3 files changed

Lines changed: 126 additions & 75 deletions

File tree

github/resource_github_repository.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ func resourceGithubRepository() *schema.Resource {
322322
Type: schema.TypeBool,
323323
Optional: true,
324324
Default: false,
325-
Description: "Specifies if the repository should be archived. Defaults to 'false'. NOTE Currently, the API does not support unarchiving.",
325+
Description: "Specifies if the repository should be archived. Defaults to 'false'. Unarchiving is supported by setting this back to 'false'.",
326326
},
327327
"archive_on_destroy": {
328328
Type: schema.TypeBool,
@@ -934,7 +934,7 @@ func resourceGithubRepositoryRead(ctx context.Context, d *schema.ResourceData, m
934934

935935
func resourceGithubRepositoryUpdate(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
936936
// Can only update a repository if it is not archived or the update is to
937-
// archive the repository (unarchiving is not supported by the GitHub API)
937+
// archive the repository
938938
if d.Get("archived").(bool) && !d.HasChange("archived") {
939939
log.Printf("[INFO] Skipping update of archived repository")
940940
return nil

github/resource_github_repository_test.go

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,55 @@ func TestAccGithubRepository(t *testing.T) {
209209
},
210210
})
211211
})
212+
t.Run("unarchives archived repositories without error", func(t *testing.T) {
213+
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
214+
testRepoName := fmt.Sprintf("%sunarchive-%s", testResourcePrefix, randomID)
215+
config := fmt.Sprintf(`
216+
resource "github_repository" "test" {
217+
name = "%s"
218+
description = "Terraform acceptance tests %[1]s"
219+
archived = false
220+
visibility = "%s"
221+
}
222+
`, testRepoName, baseVisibility)
223+
224+
resource.Test(t, resource.TestCase{
225+
PreCheck: func() { skipUnauthenticated(t) },
226+
ProviderFactories: providerFactories,
227+
Steps: []resource.TestStep{
228+
{
229+
Config: config,
230+
Check: resource.ComposeTestCheckFunc(
231+
resource.TestCheckResourceAttr(
232+
"github_repository.test", "archived",
233+
"false",
234+
),
235+
),
236+
},
237+
{
238+
Config: strings.Replace(config,
239+
`archived = false`,
240+
`archived = true`, 1),
241+
Check: resource.ComposeTestCheckFunc(
242+
resource.TestCheckResourceAttr(
243+
"github_repository.test", "archived",
244+
"true",
245+
),
246+
),
247+
},
248+
{
249+
Config: config,
250+
Check: resource.ComposeTestCheckFunc(
251+
resource.TestCheckResourceAttr(
252+
"github_repository.test", "archived",
253+
"false",
254+
),
255+
),
256+
},
257+
},
258+
})
259+
})
260+
212261
t.Run("creates_repositories_as_archived_without_error", func(t *testing.T) {
213262
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
214263
testRepoName := fmt.Sprintf("%screate-and-archive-%s", testResourcePrefix, randomID)
@@ -246,8 +295,9 @@ func TestAccGithubRepository(t *testing.T) {
246295
name = "%s"
247296
description = "Terraform acceptance tests %[1]s"
248297
has_projects = false
298+
visibility = "%s"
249299
}
250-
`, testRepoName)
300+
`, testRepoName, baseVisibility)
251301

252302
checks := map[string]resource.TestCheckFunc{
253303
"before": resource.ComposeTestCheckFunc(
@@ -524,8 +574,9 @@ func TestAccGithubRepository(t *testing.T) {
524574
auto_init = true
525575
archive_on_destroy = true
526576
archived = false
577+
visibility = "%s"
527578
}
528-
`, testRepoName)
579+
`, testRepoName, baseVisibility)
529580

530581
checks := map[string]resource.TestCheckFunc{
531582
"before": resource.ComposeTestCheckFunc(

0 commit comments

Comments
 (0)