Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ func TestAccGithubActionsEnvironmentPublicKeyDataSource(t *testing.T) {
)

resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnauthenticated(t) },
Providers: testAccProviders,
PreCheck: func() { skipUnauthenticated(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ func TestAccGithubOrganizationRepositoryRoleDataSource(t *testing.T) {
`, roleName)

resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessMode(t, enterprise) },
Providers: testAccProviders,
PreCheck: func() { skipUnlessMode(t, enterprise) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ func TestAccDataSourceGithubOrganizationRepositoryRoles(t *testing.T) {
`

resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessHasPaidOrgs(t) },
Providers: testAccProviders,
PreCheck: func() { skipUnlessHasPaidOrgs(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: config,
Expand Down Expand Up @@ -45,8 +45,8 @@ func TestAccDataSourceGithubOrganizationRepositoryRoles(t *testing.T) {
`

resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessMode(t, enterprise) },
Providers: testAccProviders,
PreCheck: func() { skipUnlessMode(t, enterprise) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: config,
Expand Down
8 changes: 4 additions & 4 deletions github/data_source_github_organization_role_teams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ func TestAccDataSourceGithubOrganizationRoleTeams(t *testing.T) {
`, teamName, roleId)

resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessHasOrgs(t) },
Providers: testAccProviders,
PreCheck: func() { skipUnlessHasOrgs(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: config,
Expand Down Expand Up @@ -82,8 +82,8 @@ func TestAccDataSourceGithubOrganizationRoleTeams(t *testing.T) {
`, teamName1, teamName2, roleId)

resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessHasOrgs(t) },
Providers: testAccProviders,
PreCheck: func() { skipUnlessHasOrgs(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: config,
Expand Down
4 changes: 2 additions & 2 deletions github/data_source_github_organization_role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ func TestAccDataSourceGithubOrganizationRole(t *testing.T) {
`, roleId)

resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessHasOrgs(t) },
Providers: testAccProviders,
PreCheck: func() { skipUnlessHasOrgs(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: config,
Expand Down
8 changes: 4 additions & 4 deletions github/data_source_github_organization_role_users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func TestAccDataSourceGithubOrganizationRoleUsers(t *testing.T) {
`, roleId, testAccConf.testOrgUser)

resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessHasOrgs(t) },
Providers: testAccProviders,
PreCheck: func() { skipUnlessHasOrgs(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: config,
Expand Down Expand Up @@ -81,8 +81,8 @@ func TestAccDataSourceGithubOrganizationRoleUsers(t *testing.T) {
`, teamName, testAccConf.testOrgUser, roleId)

resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessHasOrgs(t) },
Providers: testAccProviders,
PreCheck: func() { skipUnlessHasOrgs(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: config,
Expand Down
4 changes: 2 additions & 2 deletions github/data_source_github_organization_roles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ func TestAccDataSourceGithubOrganizationRoles(t *testing.T) {
`

resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessHasOrgs(t) },
Providers: testAccProviders,
PreCheck: func() { skipUnlessHasOrgs(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ func TestAccDataSourceGithubOrganizationSecurityManagers(t *testing.T) {
`, teamName)

resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessHasOrgs(t) },
Providers: testAccProviders,
PreCheck: func() { skipUnlessHasOrgs(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: config,
Expand Down
16 changes: 8 additions & 8 deletions github/data_source_github_repository_custom_properties_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ func TestAccGithubRepositoryCustomPropertiesDataSource(t *testing.T) {
)

resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessHasOrgs(t) },
Providers: testAccProviders,
PreCheck: func() { skipUnlessHasOrgs(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: config,
Expand Down Expand Up @@ -93,8 +93,8 @@ func TestAccGithubRepositoryCustomPropertiesDataSource(t *testing.T) {
)

resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessHasOrgs(t) },
Providers: testAccProviders,
PreCheck: func() { skipUnlessHasOrgs(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: config,
Expand Down Expand Up @@ -139,8 +139,8 @@ func TestAccGithubRepositoryCustomPropertiesDataSource(t *testing.T) {
)

resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessHasOrgs(t) },
Providers: testAccProviders,
PreCheck: func() { skipUnlessHasOrgs(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: config,
Expand Down Expand Up @@ -185,8 +185,8 @@ func TestAccGithubRepositoryCustomPropertiesDataSource(t *testing.T) {
)

resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessHasOrgs(t) },
Providers: testAccProviders,
PreCheck: func() { skipUnlessHasOrgs(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicies(t *testing.T) {
`, repoName)

resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnauthenticated(t) },
Providers: testAccProviders,
PreCheck: func() { skipUnauthenticated(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: config,
Expand Down
24 changes: 0 additions & 24 deletions github/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,9 @@ import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

var (
testAccProviders map[string]*schema.Provider
testAccProviderFactories func(providers *[]*schema.Provider) map[string]func() (*schema.Provider, error)
testAccProvider *schema.Provider
)

func init() {
testAccProvider = Provider()
testAccProviders = map[string]*schema.Provider{
"github": testAccProvider,
}
testAccProviderFactories = func(providers *[]*schema.Provider) map[string]func() (*schema.Provider, error) {
return map[string]func() (*schema.Provider, error){
//nolint:unparam
"github": func() (*schema.Provider, error) {
p := Provider()
*providers = append(*providers, p)
return p, nil
},
}
}
}

func TestProvider(t *testing.T) {
t.Run("runs internal validation without error", func(t *testing.T) {
if err := Provider().InternalValidate(); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions github/resource_github_actions_environment_secret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ func TestAccGithubActionsEnvironmentSecretIgnoreChanges(t *testing.T) {
}

resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnauthenticated(t) },
Providers: testAccProviders,
PreCheck: func() { skipUnauthenticated(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(configFmtStr, repoName, secretValue, secretValue),
Expand Down
14 changes: 9 additions & 5 deletions github/resource_github_actions_environment_variable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ func TestAccGithubActionsEnvironmentVariable_alreadyExists(t *testing.T) {
`, repoName, envName, varName, value)

resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnauthenticated(t) },
Providers: testAccProviders,
PreCheck: func() { skipUnauthenticated(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
// First, create the repository and environment.
Expand All @@ -204,15 +204,19 @@ func TestAccGithubActionsEnvironmentVariable_alreadyExists(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
func(s *terraform.State) error {
// Now that the repo and env are created, create the variable using the API.
client := testAccProvider.Meta().(*Owner).v3client
owner := testAccProvider.Meta().(*Owner).name
meta, err := getTestMeta()
if err != nil {
return err
}
client := meta.v3client
owner := meta.name
ctx := context.Background()

variable := &github.ActionsVariable{
Name: varName,
Value: value,
}
_, err := client.Actions.CreateEnvVariable(ctx, owner, repoName, url.PathEscape(envName), variable)
_, err = client.Actions.CreateEnvVariable(ctx, owner, repoName, url.PathEscape(envName), variable)
return err
},
),
Expand Down
24 changes: 12 additions & 12 deletions github/resource_github_actions_hosted_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ func TestAccGithubActionsHostedRunner(t *testing.T) {
)

resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessHasPaidOrgs(t) },
Providers: testAccProviders,
PreCheck: func() { skipUnlessHasPaidOrgs(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: config,
Expand Down Expand Up @@ -128,8 +128,8 @@ func TestAccGithubActionsHostedRunner(t *testing.T) {
)

resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessHasPaidOrgs(t) },
Providers: testAccProviders,
PreCheck: func() { skipUnlessHasPaidOrgs(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: config,
Expand Down Expand Up @@ -211,8 +211,8 @@ func TestAccGithubActionsHostedRunner(t *testing.T) {
)

resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessHasPaidOrgs(t) },
Providers: testAccProviders,
PreCheck: func() { skipUnlessHasPaidOrgs(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: configBefore,
Expand Down Expand Up @@ -288,8 +288,8 @@ func TestAccGithubActionsHostedRunner(t *testing.T) {
)

resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessHasPaidOrgs(t) },
Providers: testAccProviders,
PreCheck: func() { skipUnlessHasPaidOrgs(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: configBefore,
Expand Down Expand Up @@ -334,8 +334,8 @@ func TestAccGithubActionsHostedRunner(t *testing.T) {
)

resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessHasPaidOrgs(t) },
Providers: testAccProviders,
PreCheck: func() { skipUnlessHasPaidOrgs(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: config,
Expand Down Expand Up @@ -372,8 +372,8 @@ func TestAccGithubActionsHostedRunner(t *testing.T) {
`, randomID, randomID)

resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessHasPaidOrgs(t) },
Providers: testAccProviders,
PreCheck: func() { skipUnlessHasPaidOrgs(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ func TestAccGithubActionsOrganizationSecretRepository(t *testing.T) {
)

resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessHasOrgs(t) },
Providers: testAccProviders,
PreCheck: func() { skipUnlessHasOrgs(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: config,
Expand Down
14 changes: 9 additions & 5 deletions github/resource_github_actions_organization_secret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ func TestAccGithubActionsOrganizationSecret_DestroyOnDrift(t *testing.T) {
`, randomID, destroyOnDrift)

resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessHasOrgs(t) },
Providers: testAccProviders,
PreCheck: func() { skipUnlessHasOrgs(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: config,
Expand All @@ -183,11 +183,15 @@ func TestAccGithubActionsOrganizationSecret_DestroyOnDrift(t *testing.T) {
t.Errorf("not found: github_actions_organization_secret.test_secret")
}
// Now that the secret is created, update it to trigger a drift.
client := testAccProvider.Meta().(*Owner).v3client
owner := testAccProvider.Meta().(*Owner).name
meta, err := getTestMeta()
if err != nil {
return err
}
client := meta.v3client
owner := meta.name
ctx := t.Context()

keyId, publicKey, err := getOrganizationPublicKeyDetails(owner, testAccProvider.Meta().(*Owner))
keyId, publicKey, err := getOrganizationPublicKeyDetails(owner, meta)
if err != nil {
t.Errorf("Failed to get organization public key details: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions github/resource_github_actions_secret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ func TestAccGithubActionsSecret(t *testing.T) {
`, repoName)

resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnauthenticated(t) },
Providers: testAccProviders,
PreCheck: func() { skipUnauthenticated(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: config,
Expand Down
4 changes: 2 additions & 2 deletions github/resource_github_branch_default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ func TestAccGithubBranchDefault(t *testing.T) {
)

resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnauthenticated(t) },
Providers: testAccProviders,
PreCheck: func() { skipUnauthenticated(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: config,
Expand Down
Loading