Skip to content

Commit 53fac2d

Browse files
committed
Ensure that Org setting modifying tests don't run in parallel
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
1 parent 526c4de commit 53fac2d

2 files changed

Lines changed: 32 additions & 5 deletions

File tree

github/acc_helpers_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,3 +659,31 @@ func mustDisableForkingForOrganization(t *testing.T, orgName string) {
659659
}
660660
})
661661
}
662+
663+
func mustRequireWebCommitSignoffForOrganization(t *testing.T, orgName string) {
664+
t.Helper()
665+
666+
currentSettings, _, err := testAccConf.meta.v3client.Organizations.Get(t.Context(), orgName)
667+
if err != nil {
668+
t.Fatalf("failed to get current organization settings for %s: %v", orgName, err)
669+
}
670+
671+
if currentSettings.GetWebCommitSignoffRequired() == true {
672+
return
673+
}
674+
675+
orgSettingsReq := &github.Organization{
676+
WebCommitSignoffRequired: new(true),
677+
}
678+
679+
_, _, err = testAccConf.meta.v3client.Organizations.Edit(t.Context(), orgName, orgSettingsReq)
680+
if err != nil {
681+
t.Fatalf("failed to update organization settings for %s: %v", orgName, err)
682+
}
683+
684+
t.Cleanup(func() {
685+
if _, _, err := testAccConf.meta.v3client.Organizations.Edit(context.WithoutCancel(t.Context()), orgName, &github.Organization{WebCommitSignoffRequired: new(false)}); err != nil {
686+
t.Logf("failed to reset organization setting for %s: %v", orgName, err)
687+
}
688+
})
689+
}

github/resource_github_repository_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,9 +1341,8 @@ resource "github_repository" "test" {
13411341
})
13421342

13431343
t.Run("check_web_commit_signoff_required_organization_enabled_but_not_set", func(t *testing.T) {
1344-
t.Parallel()
1345-
1346-
t.Skip("This test should be run manually after confirming that the test organization has 'Require contributors to sign off on web-based commits' enabled under Organizations -> Settings -> Repository -> Repository defaults.")
1344+
// This test can't be run in parallel because it modifies the organization settings, which could affect other tests.
1345+
mustRequireWebCommitSignoffForOrganization(t, testAccConf.owner)
13471346

13481347
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
13491348
testRepoName := fmt.Sprintf("%scommit-signoff-%s", testResourcePrefix, randomID)
@@ -1374,8 +1373,7 @@ resource "github_repository" "test" {
13741373
})
13751374

13761375
t.Run("check_allow_forking_not_set", func(t *testing.T) {
1377-
t.Parallel()
1378-
1376+
// This test can't be run in parallel because it modifies the organization settings, which could affect other tests.
13791377
mustDisableForkingForOrganization(t, testAccConf.owner)
13801378

13811379
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
@@ -1403,6 +1401,7 @@ resource "github_repository" "private" {
14031401
})
14041402
})
14051403

1404+
// TODO: Delete test when removing deprecated vulnerability_alerts attribute.
14061405
t.Run("check_vulnerability_alerts_not_set", func(t *testing.T) {
14071406
t.Parallel()
14081407

0 commit comments

Comments
 (0)