Skip to content

Commit 9c58122

Browse files
committed
Refactor GITHUB_IN_ORG_USER tests to enable them
Signed-off-by: Timo Sand <[email protected]>
1 parent d8d09c0 commit 9c58122

3 files changed

Lines changed: 9 additions & 24 deletions

github/data_source_github_organization_role_users_test.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,13 @@ package github
22

33
import (
44
"fmt"
5-
"os"
65
"testing"
76

87
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
98
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
109
)
1110

1211
func TestAccDataSourceGithubOrganizationRoleUsers(t *testing.T) {
13-
login := os.Getenv("GITHUB_IN_ORG_USER")
14-
if len(login) == 0 {
15-
t.Skip("set inOrgUser to unskip this test run")
16-
}
17-
1812
t.Run("get the organization role users without error", func(t *testing.T) {
1913
roleId := 8134
2014
config := fmt.Sprintf(`
@@ -30,7 +24,7 @@ func TestAccDataSourceGithubOrganizationRoleUsers(t *testing.T) {
3024
github_organization_role_user.test
3125
]
3226
}
33-
`, roleId, login)
27+
`, roleId, testAccConf.testOrgUser)
3428

3529
resource.Test(t, resource.TestCase{
3630
PreCheck: func() { skipUnlessHasOrgs(t) },
@@ -42,7 +36,7 @@ func TestAccDataSourceGithubOrganizationRoleUsers(t *testing.T) {
4236
resource.TestCheckResourceAttrSet("data.github_organization_role_users.test", "users.#"),
4337
resource.TestCheckResourceAttr("data.github_organization_role_users.test", "users.#", "1"),
4438
resource.TestCheckResourceAttrSet("data.github_organization_role_users.test", "users.0.user_id"),
45-
resource.TestCheckResourceAttr("data.github_organization_role_users.test", "users.0.login", login),
39+
resource.TestCheckResourceAttr("data.github_organization_role_users.test", "users.0.login", testAccConf.testOrgUser),
4640
),
4741
},
4842
},
@@ -76,7 +70,7 @@ func TestAccDataSourceGithubOrganizationRoleUsers(t *testing.T) {
7670
github_organization_role_team.test
7771
]
7872
}
79-
`, teamName, login, roleId)
73+
`, teamName, testAccConf.testOrgUser, roleId)
8074

8175
resource.Test(t, resource.TestCase{
8276
PreCheck: func() { skipUnlessHasOrgs(t) },
@@ -88,7 +82,7 @@ func TestAccDataSourceGithubOrganizationRoleUsers(t *testing.T) {
8882
resource.TestCheckResourceAttrSet("data.github_organization_role_users.test", "users.#"),
8983
resource.TestCheckResourceAttr("data.github_organization_role_users.test", "users.#", "1"),
9084
resource.TestCheckResourceAttrSet("data.github_organization_role_users.test", "users.0.user_id"),
91-
resource.TestCheckResourceAttr("data.github_organization_role_users.test", "users.0.login", login),
85+
resource.TestCheckResourceAttr("data.github_organization_role_users.test", "users.0.login", testAccConf.testOrgUser),
9286
),
9387
},
9488
},

github/resource_github_actions_organization_secret_repositories_test.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,20 @@ package github
22

33
import (
44
"fmt"
5-
"os"
65
"testing"
76

87
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
98
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
109
)
1110

1211
func TestAccGithubActionsOrganizationSecretRepositories(t *testing.T) {
13-
const ORG_SECRET_NAME = "ORG_SECRET_NAME"
1412
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
15-
secret_name, exists := os.LookupEnv(ORG_SECRET_NAME)
1613
repoName1 := fmt.Sprintf("%srepo-act-org-secret-%s-1", testResourcePrefix, randomID)
1714
repoName2 := fmt.Sprintf("%srepo-act-org-secret-%s-2", testResourcePrefix, randomID)
1815

1916
t.Run("set repository allowlist for a organization secret", func(t *testing.T) {
20-
if !exists {
21-
t.Skipf("%s environment variable is missing", ORG_SECRET_NAME)
17+
if len(testAccConf.testOrgSecretName) == 0 {
18+
t.Skipf("'GH_TEST_ORG_SECRET_NAME' environment variable is missing")
2219
}
2320

2421
config := fmt.Sprintf(`
@@ -41,7 +38,7 @@ func TestAccGithubActionsOrganizationSecretRepositories(t *testing.T) {
4138
github_repository.test_repo_2.repo_id
4239
]
4340
}
44-
`, repoName1, repoName2, secret_name)
41+
`, repoName1, repoName2, testAccConf.testOrgSecretName)
4542

4643
check := resource.ComposeTestCheckFunc(
4744
resource.TestCheckResourceAttrSet(

github/resource_github_organization_role_user_test.go

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

33
import (
44
"fmt"
5-
"os"
65
"strconv"
76
"testing"
87

@@ -11,18 +10,13 @@ import (
1110

1211
func TestAccGithubOrganizationRoleUser(t *testing.T) {
1312
t.Run("adds user to an organization org role", func(t *testing.T) {
14-
login := os.Getenv("GITHUB_IN_ORG_USER")
15-
if len(login) == 0 {
16-
t.Skip("set inOrgUser to unskip this test run")
17-
}
18-
1913
roleId := 8134
2014
config := fmt.Sprintf(`
2115
resource "github_organization_role_user" "test" {
2216
role_id = %d
2317
login = "%s"
2418
}
25-
`, roleId, login)
19+
`, roleId, testAccConf.testOrgUser)
2620

2721
resource.Test(t, resource.TestCase{
2822
PreCheck: func() { skipUnlessHasOrgs(t) },
@@ -32,7 +26,7 @@ func TestAccGithubOrganizationRoleUser(t *testing.T) {
3226
Config: config,
3327
Check: resource.ComposeTestCheckFunc(
3428
resource.TestCheckResourceAttr("github_organization_role_user.test", "role_id", strconv.Itoa(roleId)),
35-
resource.TestCheckResourceAttr("github_organization_role_user.test", "login", login),
29+
resource.TestCheckResourceAttr("github_organization_role_user.test", "login", testAccConf.testOrgUser),
3630
),
3731
},
3832
},

0 commit comments

Comments
 (0)