Skip to content

Commit 3ffbe0d

Browse files
committed
Enable running repository_ruleset tests on enterprise testmode
Signed-off-by: Timo Sand <[email protected]>
1 parent 3326ec6 commit 3ffbe0d

1 file changed

Lines changed: 38 additions & 26 deletions

File tree

github/resource_github_repository_ruleset_test.go

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ resource "github_repository_ruleset" "test" {
155155
name = "%s"
156156
auto_init = false
157157
vulnerability_alerts = true
158+
visibility = "%s"
158159
}
159160
160161
resource "github_repository_environment" "example" {
@@ -184,7 +185,7 @@ resource "github_repository_ruleset" "test" {
184185
}
185186
}
186187
}
187-
`, repoName)
188+
`, repoName, baseVisibility)
188189

189190
resource.Test(t, resource.TestCase{
190191
PreCheck: func() { skipUnlessMode(t, enterprise) },
@@ -236,7 +237,7 @@ resource "github_repository_ruleset" "test" {
236237
}
237238
238239
max_file_size {
239-
max_file_size = 1048576
240+
max_file_size = 99
240241
}
241242
242243
file_extension_restriction {
@@ -257,14 +258,14 @@ resource "github_repository_ruleset" "test" {
257258
resource.TestCheckResourceAttr("github_repository_ruleset.test", "name", "test-push"),
258259
resource.TestCheckResourceAttr("github_repository_ruleset.test", "target", "push"),
259260
resource.TestCheckResourceAttr("github_repository_ruleset.test", "enforcement", "active"),
260-
resource.TestCheckResourceAttr("github_organization_ruleset.test", "bypass_actors.#", "2"),
261-
resource.TestCheckResourceAttr("github_organization_ruleset.test", "bypass_actors.0.actor_type", "DeployKey"),
262-
resource.TestCheckResourceAttr("github_organization_ruleset.test", "bypass_actors.0.bypass_mode", "always"),
263-
resource.TestCheckResourceAttr("github_organization_ruleset.test", "bypass_actors.1.actor_id", "5"),
264-
resource.TestCheckResourceAttr("github_organization_ruleset.test", "bypass_actors.1.actor_type", "RepositoryRole"),
265-
resource.TestCheckResourceAttr("github_organization_ruleset.test", "bypass_actors.1.bypass_mode", "always"),
261+
resource.TestCheckResourceAttr("github_repository_ruleset.test", "bypass_actors.#", "2"),
262+
resource.TestCheckResourceAttr("github_repository_ruleset.test", "bypass_actors.0.actor_type", "DeployKey"),
263+
resource.TestCheckResourceAttr("github_repository_ruleset.test", "bypass_actors.0.bypass_mode", "always"),
264+
resource.TestCheckResourceAttr("github_repository_ruleset.test", "bypass_actors.1.actor_id", "5"),
265+
resource.TestCheckResourceAttr("github_repository_ruleset.test", "bypass_actors.1.actor_type", "RepositoryRole"),
266+
resource.TestCheckResourceAttr("github_repository_ruleset.test", "bypass_actors.1.bypass_mode", "always"),
266267
resource.TestCheckResourceAttr("github_repository_ruleset.test", "rules.0.file_path_restriction.0.restricted_file_paths.0", "test.txt"),
267-
resource.TestCheckResourceAttr("github_repository_ruleset.test", "rules.0.max_file_size.0.max_file_size", "1048576"),
268+
resource.TestCheckResourceAttr("github_repository_ruleset.test", "rules.0.max_file_size.0.max_file_size", "99"),
268269
resource.TestCheckResourceAttr("github_repository_ruleset.test", "rules.0.file_extension_restriction.0.restricted_file_extensions.0", "*.zip"),
269270
),
270271
},
@@ -280,13 +281,14 @@ resource "github_repository_ruleset" "test" {
280281

281282
config := `
282283
resource "github_repository" "test" {
283-
name = "%[1]s"
284-
description = "Terraform acceptance tests %[2]s"
284+
name = "%s"
285+
description = "Terraform acceptance tests %s"
285286
vulnerability_alerts = true
287+
visibility = "%s"
286288
}
287289
288290
resource "github_repository_ruleset" "test" {
289-
name = "%[3]s"
291+
name = "%s"
290292
repository = github_repository.test.id
291293
target = "branch"
292294
enforcement = "active"
@@ -302,13 +304,13 @@ resource "github_repository_ruleset" "test" {
302304
ProviderFactories: providerFactories,
303305
Steps: []resource.TestStep{
304306
{
305-
Config: fmt.Sprintf(config, repoName, randomID, name),
307+
Config: fmt.Sprintf(config, repoName, randomID, baseVisibility, name),
306308
Check: resource.ComposeTestCheckFunc(
307309
resource.TestCheckResourceAttr("github_repository_ruleset.test", "name", name),
308310
),
309311
},
310312
{
311-
Config: fmt.Sprintf(config, repoName, randomID, nameUpdated),
313+
Config: fmt.Sprintf(config, repoName, randomID, baseVisibility, nameUpdated),
312314
Check: resource.ComposeTestCheckFunc(
313315
resource.TestCheckResourceAttr("github_repository_ruleset.test", "name", nameUpdated),
314316
),
@@ -326,6 +328,7 @@ resource "github_repository" "test" {
326328
name = "%s"
327329
description = "Terraform acceptance tests %[1]s"
328330
auto_init = true
331+
visibility = "%s"
329332
}
330333
331334
resource "github_repository_ruleset" "test" {
@@ -356,13 +359,14 @@ resource "github_repository_ruleset" "test" {
356359
creation = true
357360
}
358361
}
359-
`, repoName)
362+
`, repoName, baseVisibility)
360363

361364
configUpdated := fmt.Sprintf(`
362365
resource "github_repository" "test" {
363366
name = "%s"
364367
description = "Terraform acceptance tests %[1]s"
365368
auto_init = true
369+
visibility = "%s"
366370
}
367371
368372
resource "github_repository_ruleset" "test" {
@@ -382,7 +386,7 @@ resource "github_repository_ruleset" "test" {
382386
creation = true
383387
}
384388
}
385-
`, repoName)
389+
`, repoName, baseVisibility)
386390

387391
resource.Test(t, resource.TestCase{
388392
PreCheck: func() { skipUnauthenticated(t) },
@@ -411,11 +415,12 @@ resource "github_repository_ruleset" "test" {
411415
bypassMode := "always"
412416
bypassModeUpdated := "exempt"
413417

414-
config := fmt.Sprintf(`
418+
config := `
415419
resource "github_repository" "test" {
416420
name = "%s"
417421
description = "Terraform acceptance tests %s"
418422
auto_init = true
423+
visibility = "%s"
419424
}
420425
421426
resource "github_repository_ruleset" "test" {
@@ -441,20 +446,20 @@ resource "github_repository_ruleset" "test" {
441446
creation = true
442447
}
443448
}
444-
`, repoName, randomID, bypassMode)
449+
`
445450

446451
resource.Test(t, resource.TestCase{
447452
PreCheck: func() { skipUnauthenticated(t) },
448453
Providers: testAccProviders,
449454
Steps: []resource.TestStep{
450455
{
451-
Config: fmt.Sprintf(config, randomID, bypassMode),
456+
Config: fmt.Sprintf(config, repoName, randomID, baseVisibility, bypassMode),
452457
Check: resource.ComposeTestCheckFunc(
453458
resource.TestCheckResourceAttr("github_repository_ruleset.test", "bypass_actors.0.bypass_mode", bypassMode),
454459
),
455460
},
456461
{
457-
Config: fmt.Sprintf(config, randomID, bypassModeUpdated),
462+
Config: fmt.Sprintf(config, repoName, randomID, baseVisibility, bypassModeUpdated),
458463
Check: resource.ComposeTestCheckFunc(
459464
resource.TestCheckResourceAttr("github_repository_ruleset.test", "bypass_actors.0.bypass_mode", bypassModeUpdated),
460465
),
@@ -473,7 +478,8 @@ resource "github_repository_ruleset" "test" {
473478
description = "Terraform acceptance tests %s"
474479
auto_init = true
475480
default_branch = "main"
476-
vulnerability_alerts = true
481+
vulnerability_alerts = true
482+
visibility = "%s"
477483
}
478484
479485
resource "github_repository_environment" "example" {
@@ -498,7 +504,7 @@ resource "github_repository_ruleset" "test" {
498504
creation = true
499505
}
500506
}
501-
`, repoName, randomID)
507+
`, repoName, randomID, baseVisibility)
502508

503509
resource.Test(t, resource.TestCase{
504510
PreCheck: func() { skipUnauthenticated(t) },
@@ -520,6 +526,10 @@ resource "github_repository_ruleset" "test" {
520526
}
521527

522528
func TestAccGithubRepositoryRulesetArchived(t *testing.T) {
529+
baseVisibility := "public"
530+
if testAccConf.authMode == enterprise {
531+
baseVisibility = "private" // Enable tests to run on GHEC EMU
532+
}
523533
t.Run("skips update and delete on archived repository", func(t *testing.T) {
524534
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
525535
repoName := fmt.Sprintf("%srepo-ruleset-arch-%s", testResourcePrefix, randomID)
@@ -528,6 +538,7 @@ func TestAccGithubRepositoryRulesetArchived(t *testing.T) {
528538
name = "%s"
529539
auto_init = true
530540
archived = false
541+
visibility = "%s"
531542
}
532543
533544
resource "github_repository_ruleset" "test" {
@@ -537,10 +548,10 @@ func TestAccGithubRepositoryRulesetArchived(t *testing.T) {
537548
enforcement = "active"
538549
rules { creation = true }
539550
}
540-
`, repoName)
551+
`, repoName, baseVisibility)
541552

542553
resource.Test(t, resource.TestCase{
543-
PreCheck: func() { skipUnlessMode(t, individual) },
554+
PreCheck: func() { skipUnauthenticated(t) },
544555
Providers: testAccProviders,
545556
Steps: []resource.TestStep{
546557
{Config: config},
@@ -558,6 +569,7 @@ func TestAccGithubRepositoryRulesetArchived(t *testing.T) {
558569
name = "%s"
559570
auto_init = true
560571
archived = true
572+
visibility = "%s"
561573
}
562574
resource "github_repository_ruleset" "test" {
563575
name = "test"
@@ -566,10 +578,10 @@ func TestAccGithubRepositoryRulesetArchived(t *testing.T) {
566578
enforcement = "active"
567579
rules { creation = true }
568580
}
569-
`, repoName)
581+
`, repoName, baseVisibility)
570582

571583
resource.Test(t, resource.TestCase{
572-
PreCheck: func() { skipUnlessMode(t, individual) },
584+
PreCheck: func() { skipUnauthenticated(t) },
573585
Providers: testAccProviders,
574586
Steps: []resource.TestStep{
575587
{Config: config, ExpectError: regexp.MustCompile("cannot create ruleset on archived repository")},

0 commit comments

Comments
 (0)