Skip to content

Commit e487d8f

Browse files
committed
Remove unnecessary abstraction with reconfigureVisibility
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
1 parent eb71436 commit e487d8f

1 file changed

Lines changed: 11 additions & 32 deletions

File tree

github/resource_github_repository_test.go

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package github
22

33
import (
44
"fmt"
5-
"regexp"
65
"strings"
76
"testing"
87

@@ -1119,40 +1118,29 @@ resource "github_repository" "test" {
11191118
t.Run("updates repos to private visibility", func(t *testing.T) {
11201119
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
11211120
testRepoName := fmt.Sprintf("%svisibility-public-%s", testResourcePrefix, randomID)
1122-
config := fmt.Sprintf(`
1121+
config := `
11231122
resource "github_repository" "public" {
11241123
name = "%s"
1125-
visibility = "public"
1124+
visibility = "%s"
11261125
vulnerability_alerts = false
11271126
}
1128-
`, testRepoName)
1129-
1130-
checks := map[string]resource.TestCheckFunc{
1131-
"before": resource.ComposeTestCheckFunc(
1132-
resource.TestCheckResourceAttr(
1133-
"github_repository.public", "visibility",
1134-
"public",
1135-
),
1136-
),
1137-
"after": resource.ComposeTestCheckFunc(
1138-
resource.TestCheckResourceAttr(
1139-
"github_repository.public", "visibility",
1140-
"private",
1141-
),
1142-
),
1143-
}
1127+
`
11441128

11451129
resource.Test(t, resource.TestCase{
11461130
PreCheck: func() { skipUnauthenticated(t) },
11471131
ProviderFactories: providerFactories,
11481132
Steps: []resource.TestStep{
11491133
{
1150-
Config: config,
1151-
Check: checks["before"],
1134+
Config: fmt.Sprintf(config, testRepoName, "public"),
1135+
Check: resource.ComposeTestCheckFunc(
1136+
resource.TestCheckResourceAttr("github_repository.public", "visibility", "public"),
1137+
),
11521138
},
11531139
{
1154-
Config: reconfigureVisibility(config, "private"),
1155-
Check: checks["after"],
1140+
Config: fmt.Sprintf(config, testRepoName, "private"),
1141+
Check: resource.ComposeTestCheckFunc(
1142+
resource.TestCheckResourceAttr("github_repository.public", "visibility", "private"),
1143+
),
11561144
},
11571145
},
11581146
})
@@ -1563,15 +1551,6 @@ func TestGithubRepositoryTopicFailsValidationWhenOverMaxCharacters(t *testing.T)
15631551
}
15641552
}
15651553

1566-
func reconfigureVisibility(config, visibility string) string {
1567-
re := regexp.MustCompile(`visibility = "(.*)"`)
1568-
newConfig := re.ReplaceAllString(
1569-
config,
1570-
fmt.Sprintf(`visibility = "%s"`, visibility),
1571-
)
1572-
return newConfig
1573-
}
1574-
15751554
type resourceDataLike map[string]any
15761555

15771556
func (d resourceDataLike) GetOk(key string) (any, bool) {

0 commit comments

Comments
 (0)