Skip to content

Commit 21f44f9

Browse files
committed
Add helper for temporarily disabling forking
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
1 parent 8606799 commit 21f44f9

2 files changed

Lines changed: 30 additions & 5 deletions

File tree

github/acc_helpers_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,3 +631,31 @@ func mustUpdateRepositoryDependabotSecret(t *testing.T, repo *github.Repository,
631631
t.Fatalf("failed to update test repository dependabot secret: %v", err)
632632
}
633633
}
634+
635+
func mustDisableForkingForOrganization(t *testing.T, orgName string) {
636+
t.Helper()
637+
638+
currentSettings, _, err := testAccConf.meta.v3client.Organizations.Get(t.Context(), orgName)
639+
if err != nil {
640+
t.Fatalf("failed to get current organization settings for %s: %v", orgName, err)
641+
}
642+
643+
if currentSettings.GetMembersCanForkPrivateRepos() == false {
644+
return
645+
}
646+
647+
orgSettingsReq := &github.Organization{
648+
MembersCanForkPrivateRepos: new(false),
649+
}
650+
651+
_, _, err = testAccConf.meta.v3client.Organizations.Edit(t.Context(), orgName, orgSettingsReq)
652+
if err != nil {
653+
t.Fatalf("failed to update organization settings for %s: %v", orgName, err)
654+
}
655+
656+
t.Cleanup(func() {
657+
if _, _, err := testAccConf.meta.v3client.Organizations.Edit(context.WithoutCancel(t.Context()), orgName, &github.Organization{MembersCanForkPrivateRepos: new(true)}); err != nil {
658+
t.Logf("failed to reset organization setting for %s: %v", orgName, err)
659+
}
660+
})
661+
}

github/resource_github_repository_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,7 +1376,7 @@ resource "github_repository" "test" {
13761376
t.Run("check_allow_forking_not_set", func(t *testing.T) {
13771377
t.Parallel()
13781378

1379-
t.Skip("This test should be run manually after confirming that the test organization has been correctly configured to disable setting forking at the repo level.")
1379+
mustDisableForkingForOrganization(t, testAccConf.owner)
13801380

13811381
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
13821382
testRepoName := fmt.Sprintf("%s%s", testResourcePrefix, randomID)
@@ -1390,7 +1390,7 @@ resource "github_repository" "private" {
13901390
`
13911391

13921392
resource.Test(t, resource.TestCase{
1393-
PreCheck: func() { skipUnauthenticated(t) },
1393+
PreCheck: func() { skipUnlessHasOrgs(t) },
13941394
ProviderFactories: providerFactories,
13951395
Steps: []resource.TestStep{
13961396
{
@@ -1399,9 +1399,6 @@ resource "github_repository" "private" {
13991399
statecheck.ExpectKnownValue("github_repository.private", tfjsonpath.New("allow_forking"), knownvalue.Bool(false)),
14001400
},
14011401
},
1402-
{
1403-
Config: fmt.Sprintf(config, testRepoName, "bar"),
1404-
},
14051402
},
14061403
})
14071404
})

0 commit comments

Comments
 (0)