Skip to content

Commit 9602a9e

Browse files
committed
Add test config for EMU enterprise and helper functions to skip tests
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
1 parent acd8678 commit 9602a9e

4 files changed

Lines changed: 39 additions & 16 deletions

File tree

CONTRIBUTING.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ This section describes a typical sequence performed when developing locally. Ful
3333
Once you have the repository cloned, there's a couple of additional steps you'll need to take. Since most of the testing is acceptance or integration testing, we need to manipulate real GitHub resources in order to run it. Useful setup steps are listed below:
3434

3535
- If you haven't already, [create a GitHub organization you can use for testing](#github-organization).
36-
- Optional: you may find it beneficial to create a test user as well in order to avoid potential rate-limiting issues on your main account.
37-
- Your organization _must_ have a repository called `terraform-template-module`. The [terraformtesting/terraform-template-module](https://github.com/terraformtesting/terraform-template-module) repo is a good, re-usable example.
38-
- You _must_ make sure that the "Template Repository" item in Settings is checked for this repo.
36+
- Optional: you may find it beneficial to create a test user as well in order to avoid potential rate-limiting issues on your main account.
37+
- Your organization _must_ have a repository called `terraform-template-module`. The [terraformtesting/terraform-template-module](https://github.com/terraformtesting/terraform-template-module) repo is a good, re-usable example.
38+
- You _must_ make sure that the "Template Repository" item in Settings is checked for this repo.
3939
- If you haven't already, generate a Personal Access Token (PAT) for authenticating your test runs.
4040
- Export the necessary configuration for authenticating your provider with GitHub
4141

@@ -52,7 +52,7 @@ Once you have the repository cloned, there's a couple of additional steps you'll
5252
### Local Development Iteration
5353

5454
1. Write a test describing what you will fix. See [`github_label`](./github/resource_github_issue_label_test.go) for an example format.
55-
1. Run your test and observe it fail. Enabling debug output allows for observing the underlying requests and responses made as well as viewing state (search `STATE:`) generated during the acceptance test run.
55+
2. Run your test and observe it fail. Enabling debug output allows for observing the underlying requests and responses made as well as viewing state (search `STATE:`) generated during the acceptance test run.
5656

5757
```sh
5858
TF_LOG=DEBUG TF_ACC=1 go test -v ./... -run ^TestAccGithubIssueLabel
@@ -182,6 +182,9 @@ export GH_TEST_ENTERPRISE_EMU_GROUP_ID=
182182

183183
# Configure test options
184184
export GH_TEST_ADVANCED_SECURITY=
185+
186+
# Configure if the enterprise is an EMU enterprise
187+
export GH_TEST_ENTERPRISE_IS_EMU=
185188
```
186189

187190
There are also a small amount of unit tests in the provider. Due to the nature of the provider, such tests are currently only recommended for exercising functionality completely internal to the provider. These may be executed by running `make test`.

github/acc_test.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ type testAccConfig struct {
4343
token string
4444

4545
// Enterprise configuration
46-
enterpriseSlug string
46+
enterpriseSlug string
47+
enterpriseIsEMU bool
4748

4849
// Global test configuration
4950
testPublicRepository string
@@ -130,6 +131,7 @@ func TestMain(m *testing.M) {
130131
testExternalUserToken: os.Getenv("GH_TEST_EXTERNAL_USER_TOKEN"),
131132
testExternalUser2: os.Getenv("GH_TEST_EXTERNAL_USER2"),
132133
testAdvancedSecurity: os.Getenv("GH_TEST_ADVANCED_SECURITY") == "true",
134+
enterpriseIsEMU: authMode == enterprise && os.Getenv("GH_TEST_ENTERPRISE_IS_EMU") == "true",
133135
}
134136

135137
if config.authMode != anonymous {
@@ -300,6 +302,18 @@ func skipUnlessEnterprise(t *testing.T) {
300302
}
301303
}
302304

305+
func skipUnlessEMUEnterprise(t *testing.T) {
306+
if !testAccConf.enterpriseIsEMU {
307+
t.Skip("Skipping as test mode is not EMU enterprise")
308+
}
309+
}
310+
311+
func skipIfEMUEnterprise(t *testing.T) {
312+
if testAccConf.enterpriseIsEMU {
313+
t.Skip("Skipping as this test is not supported for EMU enterprise")
314+
}
315+
}
316+
303317
func skipUnlessMode(t *testing.T, testModes ...testMode) {
304318
if !slices.Contains(testModes, testAccConf.authMode) {
305319
t.Skip("Skipping as not supported test mode")

github/resource_github_emu_group_mapping_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func TestAccGithubEMUGroupMapping(t *testing.T) {
2121
teamName := fmt.Sprintf("%steam-emu-%s", testResourcePrefix, randomID)
2222

2323
resource.Test(t, resource.TestCase{
24-
PreCheck: func() { skipUnlessMode(t, enterprise) },
24+
PreCheck: func() { skipUnlessEMUEnterprise(t) },
2525
ProviderFactories: providerFactories,
2626
CheckDestroy: testAccCheckGithubEMUGroupMappingDestroy,
2727
Steps: []resource.TestStep{
@@ -43,7 +43,7 @@ func TestAccGithubEMUGroupMapping(t *testing.T) {
4343
rn := "github_emu_group_mapping.test"
4444

4545
resource.Test(t, resource.TestCase{
46-
PreCheck: func() { skipUnlessMode(t, enterprise) },
46+
PreCheck: func() { skipUnlessEMUEnterprise(t) },
4747
ProviderFactories: providerFactories,
4848
CheckDestroy: testAccCheckGithubEMUGroupMappingDestroy,
4949
Steps: []resource.TestStep{
@@ -84,7 +84,7 @@ func TestAccGithubEMUGroupMapping(t *testing.T) {
8484
`, teamName, teamName2, groupID)
8585

8686
resource.Test(t, resource.TestCase{
87-
PreCheck: func() { skipUnlessMode(t, enterprise) },
87+
PreCheck: func() { skipUnlessEMUEnterprise(t) },
8888
ProviderFactories: providerFactories,
8989
CheckDestroy: testAccCheckGithubEMUGroupMappingDestroy,
9090
Steps: []resource.TestStep{
@@ -107,7 +107,7 @@ func TestAccGithubEMUGroupMapping(t *testing.T) {
107107
teamName2 := fmt.Sprintf("%s-upd", teamName1)
108108

109109
resource.Test(t, resource.TestCase{
110-
PreCheck: func() { skipUnlessMode(t, enterprise) },
110+
PreCheck: func() { skipUnlessEMUEnterprise(t) },
111111
ProviderFactories: providerFactories,
112112
CheckDestroy: testAccCheckGithubEMUGroupMappingDestroy,
113113
Steps: []resource.TestStep{
@@ -149,7 +149,7 @@ resource "github_emu_group_mapping" "test" {
149149
`
150150

151151
resource.Test(t, resource.TestCase{
152-
PreCheck: func() { skipUnlessEnterprise(t) },
152+
PreCheck: func() { skipUnlessEMUEnterprise(t) },
153153
ProviderFactories: providerFactories,
154154
CheckDestroy: testAccCheckGithubEMUGroupMappingDestroy,
155155
Steps: []resource.TestStep{

github/resource_github_repository_test.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ resource "github_repository" "test" {
419419
`, testRepoName, testAccConf.testPublicTemplateRepositoryOwner, testAccConf.testPublicTemplateRepository)
420420

421421
resource.Test(t, resource.TestCase{
422-
PreCheck: func() { skipUnauthenticated(t) },
422+
PreCheck: func() { skipUnauthenticated(t); skipIfEMUEnterprise(t) },
423423
ProviderFactories: providerFactories,
424424
Steps: []resource.TestStep{
425425
{
@@ -604,7 +604,10 @@ resource "github_repository" "test" {
604604
`, testRepoName)
605605

606606
resource.Test(t, resource.TestCase{
607-
PreCheck: func() { skipUnauthenticated(t) },
607+
PreCheck: func() {
608+
skipUnauthenticated(t)
609+
skipIfEMUEnterprise(t)
610+
},
608611
ProviderFactories: providerFactories,
609612
Steps: []resource.TestStep{
610613
{
@@ -1057,7 +1060,10 @@ resource "github_repository" "test" {
10571060
),
10581061
)
10591062
resource.Test(t, resource.TestCase{
1060-
PreCheck: func() { skipUnauthenticated(t) },
1063+
PreCheck: func() {
1064+
skipUnauthenticated(t)
1065+
skipIfEMUEnterprise(t)
1066+
},
10611067
ProviderFactories: providerFactories,
10621068
Steps: []resource.TestStep{
10631069
{
@@ -1143,7 +1149,7 @@ resource "github_repository" "test" {
11431149
}
11441150

11451151
resource.Test(t, resource.TestCase{
1146-
PreCheck: func() { skipUnauthenticated(t) },
1152+
PreCheck: func() { skipUnauthenticated(t); skipIfEMUEnterprise(t) },
11471153
ProviderFactories: providerFactories,
11481154
Steps: []resource.TestStep{
11491155
{
@@ -1278,7 +1284,7 @@ resource "github_repository" "test" {
12781284
)
12791285

12801286
resource.Test(t, resource.TestCase{
1281-
PreCheck: func() { skipUnauthenticated(t) },
1287+
PreCheck: func() { skipUnauthenticated(t); skipIfEMUEnterprise(t) },
12821288
ProviderFactories: providerFactories,
12831289
Steps: []resource.TestStep{
12841290
{
@@ -1304,7 +1310,7 @@ resource "github_repository" "test" {
13041310
`, testRepoName, testAccConf.testPublicTemplateRepositoryOwner, testAccConf.testPublicTemplateRepository)
13051311

13061312
resource.Test(t, resource.TestCase{
1307-
PreCheck: func() { skipUnlessMode(t, enterprise) },
1313+
PreCheck: func() { skipUnlessMode(t, enterprise); skipIfEMUEnterprise(t) },
13081314
ProviderFactories: providerFactories,
13091315
Steps: []resource.TestStep{
13101316
{

0 commit comments

Comments
 (0)