diff --git a/vercel/data_source_access_group_project_test.go b/vercel/data_source_access_group_project_test.go index 654479cb..5802fd4a 100644 --- a/vercel/data_source_access_group_project_test.go +++ b/vercel/data_source_access_group_project_test.go @@ -11,11 +11,10 @@ import ( func TestAcc_AccessGroupProjectDataSource(t *testing.T) { name := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { - Config: testAccAccessGroupProjectDataSource(name), + Config: testAccAccessGroupProjectDataSource(teamIDConfig(t), name), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.vercel_access_group_project.test", "role", "ADMIN"), ), @@ -24,7 +23,7 @@ func TestAcc_AccessGroupProjectDataSource(t *testing.T) { }) } -func testAccAccessGroupProjectDataSource(name string) string { +func testAccAccessGroupProjectDataSource(teamIDConfig string, name string) string { return fmt.Sprintf(` resource "vercel_project" "test" { %[1]s @@ -51,5 +50,5 @@ data "vercel_access_group_project" "test" { vercel_access_group_project.test ] } -`, teamIDConfig(), name) +`, teamIDConfig, name) } diff --git a/vercel/data_source_access_group_test.go b/vercel/data_source_access_group_test.go index 1787a344..0c04173a 100644 --- a/vercel/data_source_access_group_test.go +++ b/vercel/data_source_access_group_test.go @@ -11,11 +11,10 @@ import ( func TestAcc_AccessGroupDataSource(t *testing.T) { name := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { - Config: testAccAccessGroupDataSource(name), + Config: testAccAccessGroupDataSource(teamIDConfig(t), name), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.vercel_access_group.test", "name", "test-acc-"+name), ), @@ -24,7 +23,7 @@ func TestAcc_AccessGroupDataSource(t *testing.T) { }) } -func testAccAccessGroupDataSource(name string) string { +func testAccAccessGroupDataSource(teamIDConfig string, name string) string { return fmt.Sprintf(` resource "vercel_access_group" "test" { name = "test-acc-%[2]s" @@ -35,5 +34,5 @@ data "vercel_access_group" "test" { id = vercel_access_group.test.id %[1]s } -`, teamIDConfig(), name) +`, teamIDConfig, name) } diff --git a/vercel/data_source_alias_test.go b/vercel/data_source_alias_test.go index 8aad6750..7c81e04c 100644 --- a/vercel/data_source_alias_test.go +++ b/vercel/data_source_alias_test.go @@ -11,14 +11,13 @@ import ( func TestAcc_AliasDataSource(t *testing.T) { name := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { - Config: testAccAliasDataSourceConfig(name, teamIDConfig()), + Config: testAccAliasDataSourceConfig(name, teamIDConfig(t), testGithubRepo(t)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.vercel_alias.test", "alias", fmt.Sprintf("test-acc-%s.vercel.app", name)), - resource.TestCheckResourceAttr("data.vercel_alias.test", "team_id", testTeam()), + resource.TestCheckResourceAttr("data.vercel_alias.test", "team_id", testTeam(t)), resource.TestCheckResourceAttrSet("data.vercel_alias.test", "id"), resource.TestCheckResourceAttrSet("data.vercel_alias.test", "deployment_id"), ), @@ -27,7 +26,7 @@ func TestAcc_AliasDataSource(t *testing.T) { }) } -func testAccAliasDataSourceConfig(name, team string) string { +func testAccAliasDataSourceConfig(name, team string, testGithubRepo string) string { return fmt.Sprintf(` resource "vercel_project" "test" { name = "test-acc-%[1]s" @@ -54,5 +53,5 @@ data "vercel_alias" "test" { alias = vercel_alias.test.alias %[2]s } -`, name, team, testGithubRepo()) +`, name, team, testGithubRepo) } diff --git a/vercel/data_source_attack_challenge_mode_test.go b/vercel/data_source_attack_challenge_mode_test.go index e9e8061d..a5099323 100644 --- a/vercel/data_source_attack_challenge_mode_test.go +++ b/vercel/data_source_attack_challenge_mode_test.go @@ -11,11 +11,10 @@ import ( func TestAcc_AttackChallengeModeDataSource(t *testing.T) { name := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { - Config: testAccAttackChallengeModeConfig(name, teamIDConfig()), + Config: testAccAttackChallengeModeConfig(name, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.vercel_attack_challenge_mode.never_enabled", "enabled", "false"), resource.TestCheckResourceAttr("data.vercel_attack_challenge_mode.enabled", "enabled", "true"), diff --git a/vercel/data_source_custom_environment_test.go b/vercel/data_source_custom_environment_test.go index e51b0324..6f1c208f 100644 --- a/vercel/data_source_custom_environment_test.go +++ b/vercel/data_source_custom_environment_test.go @@ -11,12 +11,11 @@ import ( func TestAcc_CustomEnvironmentDataSource(t *testing.T) { projectSuffix := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, - CheckDestroy: testAccProjectDestroy("vercel_project.test", testTeam()), + CheckDestroy: testAccProjectDestroy(testClient(t), "vercel_project.test", testTeam(t)), Steps: []resource.TestStep{ { - Config: testAccCustomEnvironmentDataSource(projectSuffix), + Config: testAccCustomEnvironmentDataSource(projectSuffix, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("data.vercel_custom_environment.test", "id"), resource.TestCheckResourceAttrSet("data.vercel_custom_environment.test", "project_id"), @@ -30,7 +29,7 @@ func TestAcc_CustomEnvironmentDataSource(t *testing.T) { }) } -func testAccCustomEnvironmentDataSource(projectSuffix string) string { +func testAccCustomEnvironmentDataSource(projectSuffix, teamIDConfig string) string { return fmt.Sprintf(` resource "vercel_project" "test" { name = "test-acc-custom-env-data-source-%[1]s" @@ -53,5 +52,5 @@ data "vercel_custom_environment" "test" { %[2]s name = vercel_custom_environment.test.name } -`, projectSuffix, teamIDConfig()) +`, projectSuffix, teamIDConfig) } diff --git a/vercel/data_source_deployment_test.go b/vercel/data_source_deployment_test.go index d7bf1e16..2c6fa8c5 100644 --- a/vercel/data_source_deployment_test.go +++ b/vercel/data_source_deployment_test.go @@ -11,11 +11,10 @@ import ( func TestAcc_DeploymentDataSource(t *testing.T) { name := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { - Config: testAccDeploymentDataSourceConfig(name, teamIDConfig()), + Config: testAccDeploymentDataSourceConfig(name, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("data.vercel_deployment.by_id", "id"), resource.TestCheckResourceAttrSet("data.vercel_deployment.by_id", "project_id"), diff --git a/vercel/data_source_edge_config_item_test.go b/vercel/data_source_edge_config_item_test.go index fb28eb2a..b93f789e 100644 --- a/vercel/data_source_edge_config_item_test.go +++ b/vercel/data_source_edge_config_item_test.go @@ -12,11 +12,10 @@ import ( func TestAcc_EdgeConfigItemDataSource(t *testing.T) { name := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { - Config: testAccEdgeConfigItemDataSourceConfig(name, teamIDConfig()), + Config: testAccEdgeConfigItemDataSourceConfig(name, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("data.vercel_edge_config_item.test", "id"), resource.TestCheckResourceAttrSet("data.vercel_edge_config_item.test", "team_id"), @@ -25,7 +24,7 @@ func TestAcc_EdgeConfigItemDataSource(t *testing.T) { ), }, { - Config: testAccEdgeConfigItemDataSourceConfigNoItem(name, teamIDConfig()), + Config: testAccEdgeConfigItemDataSourceConfigNoItem(name, teamIDConfig(t)), ExpectError: regexp.MustCompile("not_found"), }, }, diff --git a/vercel/data_source_edge_config_schema_test.go b/vercel/data_source_edge_config_schema_test.go index 0f73c2a1..21c8b702 100644 --- a/vercel/data_source_edge_config_schema_test.go +++ b/vercel/data_source_edge_config_schema_test.go @@ -12,11 +12,10 @@ import ( func TestAcc_EdgeConfigSchemaDataSource(t *testing.T) { name := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { - Config: testAccEdgeConfigSchemaDataSourceConfig(name, teamIDConfig()), + Config: testAccEdgeConfigSchemaDataSourceConfig(name, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("data.vercel_edge_config_schema.test", "id"), resource.TestCheckResourceAttrSet("data.vercel_edge_config_schema.test", "team_id"), @@ -24,7 +23,7 @@ func TestAcc_EdgeConfigSchemaDataSource(t *testing.T) { ), }, { - Config: testAccEdgeConfigSchemaDataSourceConfigNoSchema(name, teamIDConfig()), + Config: testAccEdgeConfigSchemaDataSourceConfigNoSchema(name, teamIDConfig(t)), ExpectError: regexp.MustCompile("not_found"), }, }, diff --git a/vercel/data_source_edge_config_test.go b/vercel/data_source_edge_config_test.go index 2fbc0ea6..0f767ba7 100644 --- a/vercel/data_source_edge_config_test.go +++ b/vercel/data_source_edge_config_test.go @@ -11,11 +11,10 @@ import ( func TestAcc_EdgeConfigDataSource(t *testing.T) { name := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { - Config: testAccEdgeConfigDataSourceConfig(name, teamIDConfig()), + Config: testAccEdgeConfigDataSourceConfig(name, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.vercel_edge_config.test", "name", name), ), diff --git a/vercel/data_source_edge_config_token_test.go b/vercel/data_source_edge_config_token_test.go index 84bd5679..45b4e76f 100644 --- a/vercel/data_source_edge_config_token_test.go +++ b/vercel/data_source_edge_config_token_test.go @@ -11,11 +11,10 @@ import ( func TestAcc_EdgeConfigTokenDataSource(t *testing.T) { name := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { - Config: testAccEdgeConfigTokenDataSourceConfig(name, teamIDConfig()), + Config: testAccEdgeConfigTokenDataSourceConfig(name, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.vercel_edge_config_token.test", "label", "test-acc-token"), resource.TestCheckResourceAttrSet("data.vercel_edge_config_token.test", "edge_config_id"), diff --git a/vercel/data_source_endpoint_verification_test.go b/vercel/data_source_endpoint_verification_test.go index fcb6f11e..e39be3d5 100644 --- a/vercel/data_source_endpoint_verification_test.go +++ b/vercel/data_source_endpoint_verification_test.go @@ -9,11 +9,10 @@ import ( func TestAcc_EndpointVerificationDataSource(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { - Config: testAccEndpointVerificationDataSourceConfig(teamIDConfig()), + Config: testAccEndpointVerificationDataSourceConfig(teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("data.vercel_endpoint_verification.test", "verification_code"), ), diff --git a/vercel/data_source_file_test.go b/vercel/data_source_file_test.go index 29f302e1..42e871c4 100644 --- a/vercel/data_source_file_test.go +++ b/vercel/data_source_file_test.go @@ -40,7 +40,6 @@ func testChecksum(n, attribute string, checksums Checksums) resource.TestCheckFu func TestAcc_DataSourceFile(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/vercel/data_source_microfrontend_group_test.go b/vercel/data_source_microfrontend_group_test.go index 3c0f75d5..d18b229e 100644 --- a/vercel/data_source_microfrontend_group_test.go +++ b/vercel/data_source_microfrontend_group_test.go @@ -11,7 +11,6 @@ import ( func TestAcc_MicrofrontendGroupDataSource(t *testing.T) { name := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { @@ -45,7 +44,7 @@ func TestAcc_MicrofrontendGroupDataSource(t *testing.T) { project_id = vercel_project.test_project_2.id %[2]s } - `, name, teamIDConfig()), + `, name, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.vercel_microfrontend_group.test_group", "name", "test-acc-microfrontend-group-"+name), resource.TestCheckResourceAttrSet("data.vercel_microfrontend_group.test_group", "default_app.project_id"), diff --git a/vercel/data_source_prebuilt_project_test.go b/vercel/data_source_prebuilt_project_test.go index e98d1970..73b46448 100644 --- a/vercel/data_source_prebuilt_project_test.go +++ b/vercel/data_source_prebuilt_project_test.go @@ -11,7 +11,6 @@ import ( func TestAcc_DataSourcePrebuiltProject(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/vercel/data_source_project_deployment_retention_test.go b/vercel/data_source_project_deployment_retention_test.go index d75560c2..90e0b8b1 100644 --- a/vercel/data_source_project_deployment_retention_test.go +++ b/vercel/data_source_project_deployment_retention_test.go @@ -11,16 +11,15 @@ import ( func TestAcc_ProjectDeploymentRetentionDataSource(t *testing.T) { nameSuffix := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, CheckDestroy: resource.ComposeAggregateTestCheckFunc( - testAccProjectDestroy("vercel_project.example", testTeam()), + testAccProjectDestroy(testClient(t), "vercel_project.example", testTeam(t)), ), Steps: []resource.TestStep{ { - Config: testAccProjectDeploymentRetentionDataSourceConfig(nameSuffix), + Config: testAccProjectDeploymentRetentionDataSourceConfig(nameSuffix, testGithubRepo(t), teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( - testAccProjectDeploymentRetentionExists("vercel_project_deployment_retention.example", testTeam()), + testAccProjectDeploymentRetentionExists(testClient(t), "vercel_project_deployment_retention.example", testTeam(t)), resource.TestCheckResourceAttr("data.vercel_project_deployment_retention.example", "expiration_preview", "1m"), resource.TestCheckResourceAttr("data.vercel_project_deployment_retention.example", "expiration_production", "unlimited"), resource.TestCheckResourceAttr("data.vercel_project_deployment_retention.example", "expiration_canceled", "unlimited"), @@ -36,7 +35,7 @@ func TestAcc_ProjectDeploymentRetentionDataSource(t *testing.T) { }) } -func testAccProjectDeploymentRetentionDataSourceConfig(projectName string) string { +func testAccProjectDeploymentRetentionDataSourceConfig(projectName string, githubRepo string, teamIDConfig string) string { return fmt.Sprintf(` resource "vercel_project" "example" { name = "test-acc-example-project-%[1]s" @@ -73,5 +72,5 @@ data "vercel_project_deployment_retention" "example_2" { project_id = vercel_project.example_2.id %[3]s } -`, projectName, testGithubRepo(), teamIDConfig()) +`, projectName, githubRepo, teamIDConfig) } diff --git a/vercel/data_source_project_directory_test.go b/vercel/data_source_project_directory_test.go index 69fc3cab..2d120d4f 100644 --- a/vercel/data_source_project_directory_test.go +++ b/vercel/data_source_project_directory_test.go @@ -9,7 +9,6 @@ import ( func TestAcc_DataSourceProjectDirectory(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { diff --git a/vercel/data_source_project_members_test.go b/vercel/data_source_project_members_test.go index 64aae87a..13f78418 100644 --- a/vercel/data_source_project_members_test.go +++ b/vercel/data_source_project_members_test.go @@ -11,12 +11,11 @@ import ( func TestAcc_ProjectMembersDataSource(t *testing.T) { projectSuffix := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, - CheckDestroy: testAccProjectDestroy("vercel_project.test", testTeam()), + CheckDestroy: testAccProjectDestroy(testClient(t), "vercel_project.test", testTeam(t)), Steps: []resource.TestStep{ { - Config: testAccProjectMembersDataSourceConfig(projectSuffix), + Config: testAccProjectMembersDataSourceConfig(projectSuffix, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("data.vercel_project_members.test", "project_id"), resource.TestCheckResourceAttr("data.vercel_project_members.test", "members.#", "1"), @@ -26,7 +25,7 @@ func TestAcc_ProjectMembersDataSource(t *testing.T) { }) } -func testAccProjectMembersDataSourceConfig(projectSuffix string) string { +func testAccProjectMembersDataSourceConfig(projectSuffix string, teamIDConfig string) string { return fmt.Sprintf(` resource "vercel_project" "test" { name = "test-acc-project-members-%[1]s" @@ -47,5 +46,5 @@ data "vercel_project_members" "test" { project_id = vercel_project_members.test.project_id %[2]s } -`, projectSuffix, teamIDConfig()) +`, projectSuffix, teamIDConfig) } diff --git a/vercel/data_source_project_test.go b/vercel/data_source_project_test.go index 20a57bf7..0e7f2168 100644 --- a/vercel/data_source_project_test.go +++ b/vercel/data_source_project_test.go @@ -11,11 +11,10 @@ import ( func TestAcc_ProjectDataSource(t *testing.T) { name := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { - Config: testAccProjectDataSourceConfig(name, teamIDConfig()), + Config: testAccProjectDataSourceConfig(name, teamIDConfig(t), testGithubRepo(t)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.vercel_project.test", "name", "test-acc-"+name), resource.TestCheckResourceAttr("data.vercel_project.test", "build_command", "npm run build"), @@ -63,7 +62,7 @@ func TestAcc_ProjectDataSource(t *testing.T) { }) } -func testAccProjectDataSourceConfig(name, teamID string) string { +func testAccProjectDataSourceConfig(name, teamID, githubRepo string) string { return fmt.Sprintf(` resource "vercel_project" "test" { name = "test-acc-%s" @@ -144,5 +143,5 @@ data "vercel_project" "test" { name = vercel_project.test.name %[2]s } -`, name, teamID, testGithubRepo()) +`, name, teamID, githubRepo) } diff --git a/vercel/data_source_shared_environment_variable_test.go b/vercel/data_source_shared_environment_variable_test.go index 33f0cb2e..396b38a7 100644 --- a/vercel/data_source_shared_environment_variable_test.go +++ b/vercel/data_source_shared_environment_variable_test.go @@ -11,11 +11,10 @@ import ( func TestAcc_SharedEnvironmentVariableDataSource(t *testing.T) { name := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { - Config: testAccSharedEnvironmentVariableDataSource(name, teamIDConfig()), + Config: testAccSharedEnvironmentVariableDataSource(name, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.vercel_shared_environment_variable.test", "key", "test_acc_"+name), resource.TestCheckResourceAttr("data.vercel_shared_environment_variable.test", "value", "foobar"), diff --git a/vercel/data_source_team_config_test.go b/vercel/data_source_team_config_test.go index 1a687d35..3c937356 100644 --- a/vercel/data_source_team_config_test.go +++ b/vercel/data_source_team_config_test.go @@ -11,11 +11,10 @@ func TestAcc_TeamConfigDataSource(t *testing.T) { resourceName := "data.vercel_team_config.test" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { - Config: testAccVercelTeamConfigDataSource(testTeam()), + Config: testAccVercelTeamConfigDataSource(testTeam(t)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet(resourceName, "id"), resource.TestCheckResourceAttrSet(resourceName, "name"), diff --git a/vercel/data_source_team_member_test.go b/vercel/data_source_team_member_test.go index d55659cb..e80dcecf 100644 --- a/vercel/data_source_team_member_test.go +++ b/vercel/data_source_team_member_test.go @@ -9,11 +9,10 @@ import ( func TestAcc_TeamMemberDataSource(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { - Config: testAccTeamMemberDataSourceConfig(), + Config: testAccTeamMemberDataSourceConfig(teamIDConfig(t), testAdditionalUser(t)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("data.vercel_team_member.test", "team_id"), resource.TestCheckResourceAttrSet("data.vercel_team_member.test", "user_id"), @@ -24,7 +23,7 @@ func TestAcc_TeamMemberDataSource(t *testing.T) { }) } -func testAccTeamMemberDataSourceConfig() string { +func testAccTeamMemberDataSourceConfig(teamIDConfig string, user string) string { return fmt.Sprintf(` resource "vercel_team_member" "test" { %[1]s @@ -36,5 +35,5 @@ data "vercel_team_member" "test" { user_id = vercel_team_member.test.user_id team_id = vercel_team_member.test.team_id } -`, teamIDConfig(), testAdditionalUser()) +`, teamIDConfig, user) } diff --git a/vercel/provider_test.go b/vercel/provider_test.go index 40fe1f89..e58f1794 100644 --- a/vercel/provider_test.go +++ b/vercel/provider_test.go @@ -15,64 +15,72 @@ var testAccProtoV6ProviderFactories = map[string]func() (tfprotov6.ProviderServe "vercel": providerserver.NewProtocol6WithError(vercel.New()), } -func mustHaveEnv(t *testing.T, name string) { - if os.Getenv(name) == "" { - t.Fatalf("%s environment variable must be set for acceptance tests", name) - } -} - -func testAccPreCheck(t *testing.T) { - mustHaveEnv(t, "VERCEL_API_TOKEN") - mustHaveEnv(t, "VERCEL_TERRAFORM_TESTING_TEAM") - mustHaveEnv(t, "VERCEL_TERRAFORM_TESTING_GITHUB_REPO") - mustHaveEnv(t, "VERCEL_TERRAFORM_TESTING_GITLAB_REPO") - mustHaveEnv(t, "VERCEL_TERRAFORM_TESTING_BITBUCKET_REPO") - mustHaveEnv(t, "VERCEL_TERRAFORM_TESTING_DOMAIN") - mustHaveEnv(t, "VERCEL_TERRAFORM_TESTING_ADDITIONAL_USER") - mustHaveEnv(t, "VERCEL_TERRAFORM_TESTING_EXISTING_INTEGRATION") -} - var tc *client.Client -func testClient() *client.Client { +func testClient(t *testing.T) *client.Client { if tc == nil { - tc = client.New(apiToken()) + tc = client.New(apiToken(t)) } return tc } -func apiToken() string { - return os.Getenv("VERCEL_API_TOKEN") +func apiToken(t *testing.T) string { + value := os.Getenv("VERCEL_API_TOKEN") + if value == "" { + t.Fatalf("Missing required environment variable VERCEL_API_TOKEN") + } + return value } -func testGithubRepo() string { - return os.Getenv("VERCEL_TERRAFORM_TESTING_GITHUB_REPO") +func testGithubRepo(t *testing.T) string { + value := os.Getenv("VERCEL_TERRAFORM_TESTING_GITHUB_REPO") + if value == "" { + t.Fatalf("Missing required environment variable VERCEL_TERRAFORM_TESTING_GITHUB_REPO") + } + return value } -func testBitbucketRepo() string { - return os.Getenv("VERCEL_TERRAFORM_TESTING_BITBUCKET_REPO") +func testBitbucketRepo(t *testing.T) string { + value := os.Getenv("VERCEL_TERRAFORM_TESTING_BITBUCKET_REPO") + if value == "" { + t.Fatalf("Missing required environment variable VERCEL_TERRAFORM_TESTING_BITBUCKET_REPO") + } + return value } -func testTeam() string { - return os.Getenv("VERCEL_TERRAFORM_TESTING_TEAM") +func testTeam(t *testing.T) string { + value := os.Getenv("VERCEL_TERRAFORM_TESTING_TEAM") + if value == "" { + t.Fatalf("Missing required environment variable VERCEL_TERRAFORM_TESTING_TEAM") + } + return value } -func teamIDConfig() string { - if testTeam() == "" { - return "" - } - return fmt.Sprintf("team_id = \"%s\"", testTeam()) +func teamIDConfig(t *testing.T) string { + return fmt.Sprintf("team_id = \"%s\"", testTeam(t)) } -func testDomain() string { - return os.Getenv("VERCEL_TERRAFORM_TESTING_DOMAIN") +func testDomain(t *testing.T) string { + value := os.Getenv("VERCEL_TERRAFORM_TESTING_DOMAIN") + if value == "" { + t.Fatalf("Missing required environment variable VERCEL_TERRAFORM_TESTING_DOMAIN") + } + return value } -func testAdditionalUser() string { - return os.Getenv("VERCEL_TERRAFORM_TESTING_ADDITIONAL_USER") +func testAdditionalUser(t *testing.T) string { + value := os.Getenv("VERCEL_TERRAFORM_TESTING_ADDITIONAL_USER") + if value == "" { + t.Fatalf("Missing required environment variable VERCEL_TERRAFORM_TESTING_ADDITIONAL_USER") + } + return value } -func testExistingIntegration() string { - return os.Getenv("VERCEL_TERRAFORM_TESTING_EXISTING_INTEGRATION") +func testExistingIntegration(t *testing.T) string { + value := os.Getenv("VERCEL_TERRAFORM_TESTING_EXISTING_INTEGRATION") + if value == "" { + t.Fatalf("Missing required environment variable VERCEL_TERRAFORM_TESTING_EXISTING_INTEGRATION") + } + return value } diff --git a/vercel/resource_access_group_project_test.go b/vercel/resource_access_group_project_test.go index b50279bd..0726fbf8 100644 --- a/vercel/resource_access_group_project_test.go +++ b/vercel/resource_access_group_project_test.go @@ -15,14 +15,13 @@ func TestAcc_AccessGroupProjectResource(t *testing.T) { name := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, - CheckDestroy: testAccAccessGroupProjectDoesNotExist("vercel_access_group_project.test"), + CheckDestroy: testAccAccessGroupProjectDoesNotExist(testClient(t), testTeam(t), "vercel_access_group_project.test"), Steps: []resource.TestStep{ { - Config: testAccResourceAccessGroupProject(name), + Config: testAccResourceAccessGroupProject(teamIDConfig(t), name), Check: resource.ComposeAggregateTestCheckFunc( - testCheckAccessGroupProjectExists("vercel_access_group_project.test"), + testCheckAccessGroupProjectExists(testClient(t), testTeam(t), "vercel_access_group_project.test"), resource.TestCheckResourceAttrSet("vercel_access_group_project.test", "access_group_id"), resource.TestCheckResourceAttrSet("vercel_access_group_project.test", "project_id"), resource.TestCheckResourceAttr("vercel_access_group_project.test", "role", "ADMIN"), @@ -34,9 +33,9 @@ func TestAcc_AccessGroupProjectResource(t *testing.T) { ImportStateIdFunc: getAccessGroupProjectImportID("vercel_access_group_project.test"), }, { - Config: testAccResourceAccessGroupProjectUpdated(name), + Config: testAccResourceAccessGroupProjectUpdated(teamIDConfig(t), name), Check: resource.ComposeAggregateTestCheckFunc( - testCheckAccessGroupProjectExists("vercel_access_group_project.test"), + testCheckAccessGroupProjectExists(testClient(t), testTeam(t), "vercel_access_group_project.test"), resource.TestCheckResourceAttrSet("vercel_access_group_project.test", "project_id"), resource.TestCheckResourceAttrSet("vercel_access_group_project.test", "access_group_id"), resource.TestCheckResourceAttr("vercel_access_group_project.test", "role", "PROJECT_DEVELOPER"), @@ -62,15 +61,15 @@ func getAccessGroupProjectImportID(n string) resource.ImportStateIdFunc { } } -func testCheckAccessGroupProjectExists(n string) resource.TestCheckFunc { +func testCheckAccessGroupProjectExists(testClient *client.Client, teamID string, n string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { return fmt.Errorf("not found: %s", n) } - _, err := testClient().GetAccessGroupProject(context.TODO(), client.GetAccessGroupProjectRequest{ - TeamID: testTeam(), + _, err := testClient.GetAccessGroupProject(context.TODO(), client.GetAccessGroupProjectRequest{ + TeamID: teamID, AccessGroupID: rs.Primary.Attributes["access_group_id"], ProjectID: rs.Primary.Attributes["project_id"], }) @@ -78,15 +77,15 @@ func testCheckAccessGroupProjectExists(n string) resource.TestCheckFunc { } } -func testAccAccessGroupProjectDoesNotExist(n string) resource.TestCheckFunc { +func testAccAccessGroupProjectDoesNotExist(testClient *client.Client, teamID string, n string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { return fmt.Errorf("not found: %s", n) } - _, err := testClient().GetAccessGroupProject(context.TODO(), client.GetAccessGroupProjectRequest{ - TeamID: testTeam(), + _, err := testClient.GetAccessGroupProject(context.TODO(), client.GetAccessGroupProjectRequest{ + TeamID: teamID, AccessGroupID: rs.Primary.Attributes["access_group_id"], ProjectID: rs.Primary.Attributes["project_id"], }) @@ -101,7 +100,7 @@ func testAccAccessGroupProjectDoesNotExist(n string) resource.TestCheckFunc { } } -func testAccResourceAccessGroupProject(name string) string { +func testAccResourceAccessGroupProject(teamIDConfig string, name string) string { return fmt.Sprintf(` resource "vercel_project" "test" { %[1]s @@ -119,10 +118,10 @@ resource "vercel_access_group_project" "test" { access_group_id = vercel_access_group.test.id role = "ADMIN" } -`, teamIDConfig(), name) +`, teamIDConfig, name) } -func testAccResourceAccessGroupProjectUpdated(name string) string { +func testAccResourceAccessGroupProjectUpdated(teamIDConfig string, name string) string { return fmt.Sprintf(` resource "vercel_project" "test" { %[1]s @@ -140,5 +139,5 @@ resource "vercel_access_group_project" "test" { access_group_id = vercel_access_group.test.id role = "PROJECT_DEVELOPER" } -`, teamIDConfig(), name) +`, teamIDConfig, name) } diff --git a/vercel/resource_access_group_test.go b/vercel/resource_access_group_test.go index 7a6ede42..2c18fcdb 100644 --- a/vercel/resource_access_group_test.go +++ b/vercel/resource_access_group_test.go @@ -15,16 +15,15 @@ import ( func TestAcc_AccessGroupResource(t *testing.T) { name := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, CheckDestroy: resource.ComposeAggregateTestCheckFunc( - testCheckAccessGroupDoesNotExist("vercel_access_group.test"), + testCheckAccessGroupDoesNotExist(testClient(t), testTeam(t), "vercel_access_group.test"), ), Steps: []resource.TestStep{ { - Config: testAccResourceAccessGroup(name), + Config: testAccResourceAccessGroup(teamIDConfig(t), name), Check: resource.ComposeAggregateTestCheckFunc( - testCheckAccessGroupExists("vercel_access_group.test"), + testCheckAccessGroupExists(testClient(t), testTeam(t), "vercel_access_group.test"), resource.TestCheckResourceAttrSet("vercel_access_group.test", "id"), resource.TestCheckResourceAttr("vercel_access_group.test", "name", fmt.Sprintf("test-acc-%s", name)), ), @@ -35,9 +34,9 @@ func TestAcc_AccessGroupResource(t *testing.T) { ImportStateIdFunc: getAccessGroupImportID("vercel_access_group.test"), }, { - Config: testAccResourceAccessGroupUpdated(name), + Config: testAccResourceAccessGroupUpdated(teamIDConfig(t), name), Check: resource.ComposeAggregateTestCheckFunc( - testCheckAccessGroupExists("vercel_access_group.test"), + testCheckAccessGroupExists(testClient(t), testTeam(t), "vercel_access_group.test"), resource.TestCheckResourceAttrSet("vercel_access_group.test", "id"), resource.TestCheckResourceAttr("vercel_access_group.test", "name", fmt.Sprintf("test-acc-%s-updated", name)), ), @@ -65,7 +64,7 @@ func getAccessGroupImportID(n string) resource.ImportStateIdFunc { } } -func testCheckAccessGroupExists(n string) resource.TestCheckFunc { +func testCheckAccessGroupExists(testClient *client.Client, teamID string, n string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -76,15 +75,15 @@ func testCheckAccessGroupExists(n string) resource.TestCheckFunc { return fmt.Errorf("no ID is set") } - _, err := testClient().GetAccessGroup(context.TODO(), client.GetAccessGroupRequest{ - TeamID: testTeam(), + _, err := testClient.GetAccessGroup(context.TODO(), client.GetAccessGroupRequest{ + TeamID: teamID, AccessGroupID: rs.Primary.ID, }) return err } } -func testCheckAccessGroupDoesNotExist(n string) resource.TestCheckFunc { +func testCheckAccessGroupDoesNotExist(testClient *client.Client, teamID string, n string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -99,8 +98,8 @@ func testCheckAccessGroupDoesNotExist(n string) resource.TestCheckFunc { // small amount of time. time.Sleep(time.Second * 2) - _, err := testClient().GetAccessGroup(context.TODO(), client.GetAccessGroupRequest{ - TeamID: testTeam(), + _, err := testClient.GetAccessGroup(context.TODO(), client.GetAccessGroupRequest{ + TeamID: teamID, AccessGroupID: rs.Primary.ID, }) if err == nil { @@ -114,20 +113,20 @@ func testCheckAccessGroupDoesNotExist(n string) resource.TestCheckFunc { } } -func testAccResourceAccessGroup(name string) string { +func testAccResourceAccessGroup(teamIDConfig string, name string) string { return fmt.Sprintf(` resource "vercel_access_group" "test" { %[1]s name = "test-acc-%[2]s" } -`, teamIDConfig(), name) +`, teamIDConfig, name) } -func testAccResourceAccessGroupUpdated(name string) string { +func testAccResourceAccessGroupUpdated(teamIDConfig string, name string) string { return fmt.Sprintf(` resource "vercel_access_group" "test" { %[1]s name = "test-acc-%[2]s-updated" } -`, teamIDConfig(), name) +`, teamIDConfig, name) } diff --git a/vercel/resource_alias_test.go b/vercel/resource_alias_test.go index 332032ba..ed07e48e 100644 --- a/vercel/resource_alias_test.go +++ b/vercel/resource_alias_test.go @@ -11,14 +11,14 @@ import ( "github.com/vercel/terraform-provider-vercel/v2/client" ) -func testCheckAliasExists(teamID, alias string) resource.TestCheckFunc { +func testCheckAliasExists(testClient *client.Client, teamID, alias string) resource.TestCheckFunc { return func(*terraform.State) error { - _, err := testClient().GetAlias(context.TODO(), alias, teamID) + _, err := testClient.GetAlias(context.TODO(), alias, teamID) return err } } -func testCheckAliasDestroyed(n, teamID string) resource.TestCheckFunc { +func testCheckAliasDestroyed(testClient *client.Client, n, teamID string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -29,7 +29,7 @@ func testCheckAliasDestroyed(n, teamID string) resource.TestCheckFunc { return fmt.Errorf("no alias is set") } - _, err := testClient().GetAlias(context.TODO(), rs.Primary.ID, teamID) + _, err := testClient.GetAlias(context.TODO(), rs.Primary.ID, teamID) if err == nil { return fmt.Errorf("expected not_found error, but got no error") } @@ -44,23 +44,22 @@ func testCheckAliasDestroyed(n, teamID string) resource.TestCheckFunc { func TestAcc_AliasResource(t *testing.T) { name := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, - CheckDestroy: testCheckAliasDestroyed("vercel_alias.test", testTeam()), + CheckDestroy: testCheckAliasDestroyed(testClient(t), "vercel_alias.test", testTeam(t)), Steps: []resource.TestStep{ { - Config: testAccAliasResourceConfig(name, teamIDConfig()), + Config: testAccAliasResourceConfig(name, teamIDConfig(t), testGithubRepo(t)), Check: resource.ComposeAggregateTestCheckFunc( - testCheckAliasExists(testTeam(), fmt.Sprintf("test-acc-%s.vercel.app", name)), + testCheckAliasExists(testClient(t), testTeam(t), fmt.Sprintf("test-acc-%s.vercel.app", name)), resource.TestCheckResourceAttr("vercel_alias.test", "alias", fmt.Sprintf("test-acc-%s.vercel.app", name)), resource.TestCheckResourceAttrSet("vercel_alias.test", "id"), resource.TestCheckResourceAttrSet("vercel_alias.test", "deployment_id"), ), }, { - Config: testAccAliasResourceConfigUpdated(name, teamIDConfig()), + Config: testAccAliasResourceConfigUpdated(name, teamIDConfig(t), testGithubRepo(t)), Check: resource.ComposeAggregateTestCheckFunc( - testCheckAliasExists(testTeam(), fmt.Sprintf("test-acc-%s.vercel.app", name)), + testCheckAliasExists(testClient(t), testTeam(t), fmt.Sprintf("test-acc-%s.vercel.app", name)), resource.TestCheckResourceAttr("vercel_alias.test", "alias", fmt.Sprintf("test-acc-%s.vercel.app", name)), resource.TestCheckResourceAttrSet("vercel_alias.test", "id"), resource.TestCheckResourceAttrSet("vercel_alias.test", "deployment_id"), @@ -70,7 +69,7 @@ func TestAcc_AliasResource(t *testing.T) { }) } -func testAccAliasResourceConfig(name, team string) string { +func testAccAliasResourceConfig(name, team string, githubRepo string) string { return fmt.Sprintf(` resource "vercel_project" "test" { name = "test-acc-%[1]s" @@ -92,10 +91,10 @@ resource "vercel_alias" "test" { deployment_id = vercel_deployment.test.id %[2]s } -`, name, team, testGithubRepo()) +`, name, team, githubRepo) } -func testAccAliasResourceConfigUpdated(name, team string) string { +func testAccAliasResourceConfigUpdated(name, team string, githubRepo string) string { return fmt.Sprintf(` resource "vercel_project" "test" { name = "test-acc-%[1]s" @@ -117,5 +116,5 @@ resource "vercel_alias" "test" { deployment_id = vercel_deployment.test_two.id %[2]s } -`, name, team, testGithubRepo()) +`, name, team, githubRepo) } diff --git a/vercel/resource_attack_challenge_mode_test.go b/vercel/resource_attack_challenge_mode_test.go index 0dd80cb2..0bc9c4d1 100644 --- a/vercel/resource_attack_challenge_mode_test.go +++ b/vercel/resource_attack_challenge_mode_test.go @@ -12,11 +12,10 @@ import ( func TestAcc_AttackChallengeModeResource(t *testing.T) { name := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { - Config: testAccAttackChallengeModeConfigResource(name, teamIDConfig()), + Config: testAccAttackChallengeModeConfigResource(name, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("vercel_attack_challenge_mode.enabled", "enabled", "true"), resource.TestCheckResourceAttr("vercel_attack_challenge_mode.disabled", "enabled", "false"), @@ -45,7 +44,7 @@ func TestAcc_AttackChallengeModeResource(t *testing.T) { }, }, { - Config: testAccAttackChallengeModeConfigResourceUpdated(name, teamIDConfig()), + Config: testAccAttackChallengeModeConfigResourceUpdated(name, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("vercel_attack_challenge_mode.enabled", "enabled", "false"), ), diff --git a/vercel/resource_custom_environment_test.go b/vercel/resource_custom_environment_test.go index 09d7388a..06cf2008 100644 --- a/vercel/resource_custom_environment_test.go +++ b/vercel/resource_custom_environment_test.go @@ -11,7 +11,7 @@ import ( "github.com/vercel/terraform-provider-vercel/v2/client" ) -func testCheckCustomEnvironmentExists(n string) resource.TestCheckFunc { +func testCheckCustomEnvironmentExists(testClient *client.Client, teamID string, n string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -25,13 +25,13 @@ func testCheckCustomEnvironmentExists(n string) resource.TestCheckFunc { projectID := rs.Primary.Attributes["project_id"] name := rs.Primary.Attributes["name"] - _, err := testClient().GetCustomEnvironment(context.TODO(), client.GetCustomEnvironmentRequest{ - TeamID: testTeam(), + _, err := testClient.GetCustomEnvironment(context.TODO(), client.GetCustomEnvironmentRequest{ + TeamID: teamID, ProjectID: projectID, Slug: name, }) if client.NotFound(err) { - return fmt.Errorf("test failed because the custom environment %s %s %s - %s could not be found", testTeam(), projectID, name, rs.Primary.ID) + return fmt.Errorf("test failed because the custom environment %s %s %s - %s could not be found", teamID, projectID, name, rs.Primary.ID) } return err } @@ -40,21 +40,20 @@ func testCheckCustomEnvironmentExists(n string) resource.TestCheckFunc { func TestAcc_CustomEnvironmentResource(t *testing.T) { projectSuffix := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, - CheckDestroy: testAccProjectDestroy("vercel_project.test", testTeam()), + CheckDestroy: testAccProjectDestroy(testClient(t), "vercel_project.test", testTeam(t)), Steps: []resource.TestStep{ { - Config: testAccCustomEnvironment(projectSuffix), + Config: testAccCustomEnvironment(projectSuffix, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( - testCheckCustomEnvironmentExists("vercel_custom_environment.test"), + testCheckCustomEnvironmentExists(testClient(t), testTeam(t), "vercel_custom_environment.test"), resource.TestCheckResourceAttrSet("vercel_custom_environment.test", "id"), resource.TestCheckResourceAttrSet("vercel_custom_environment.test", "project_id"), resource.TestCheckResourceAttrSet("vercel_custom_environment.test", "name"), resource.TestCheckNoResourceAttr("vercel_custom_environment.test", "branch_tracking"), resource.TestCheckResourceAttr("vercel_custom_environment.test", "description", "without branch tracking"), - testCheckCustomEnvironmentExists("vercel_custom_environment.test_bt"), + testCheckCustomEnvironmentExists(testClient(t), testTeam(t), "vercel_custom_environment.test_bt"), resource.TestCheckResourceAttrSet("vercel_custom_environment.test_bt", "id"), resource.TestCheckResourceAttrSet("vercel_custom_environment.test_bt", "project_id"), resource.TestCheckResourceAttrSet("vercel_custom_environment.test_bt", "name"), @@ -70,9 +69,9 @@ func TestAcc_CustomEnvironmentResource(t *testing.T) { ), }, { - Config: testAccCustomEnvironmentUpdated(projectSuffix), + Config: testAccCustomEnvironmentUpdated(projectSuffix, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( - testCheckCustomEnvironmentExists("vercel_custom_environment.test"), + testCheckCustomEnvironmentExists(testClient(t), testTeam(t), "vercel_custom_environment.test"), resource.TestCheckResourceAttrSet("vercel_custom_environment.test", "id"), resource.TestCheckResourceAttrSet("vercel_custom_environment.test", "project_id"), resource.TestCheckResourceAttrSet("vercel_custom_environment.test", "name"), @@ -106,7 +105,7 @@ func getCustomEnvImportID(n string) resource.ImportStateIdFunc { } } -func testAccCustomEnvironment(projectSuffix string) string { +func testAccCustomEnvironment(projectSuffix string, teamIDConfig string) string { return fmt.Sprintf(` resource "vercel_project" "test" { name = "test-acc-custom-env-%[1]s" @@ -150,10 +149,10 @@ resource "vercel_custom_environment" "test_bt" { type = "startsWith" } } -`, projectSuffix, teamIDConfig()) +`, projectSuffix, teamIDConfig) } -func testAccCustomEnvironmentUpdated(projectSuffix string) string { +func testAccCustomEnvironmentUpdated(projectSuffix string, teamIDConfig string) string { return fmt.Sprintf(` resource "vercel_project" "test" { name = "test-acc-custom-env-%[1]s" @@ -170,5 +169,5 @@ resource "vercel_custom_environment" "test" { type = "endsWith" } } -`, projectSuffix, teamIDConfig()) +`, projectSuffix, teamIDConfig) } diff --git a/vercel/resource_deployment_test.go b/vercel/resource_deployment_test.go index 08ee565d..44faf7a0 100644 --- a/vercel/resource_deployment_test.go +++ b/vercel/resource_deployment_test.go @@ -14,7 +14,7 @@ import ( "github.com/vercel/terraform-provider-vercel/v2/client" ) -func testAccDeploymentExists(n, teamID string) resource.TestCheckFunc { +func testAccDeploymentExists(testClient *client.Client, n string, teamID string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -25,7 +25,7 @@ func testAccDeploymentExists(n, teamID string) resource.TestCheckFunc { return fmt.Errorf("no DeploymentID is set") } - _, err := testClient().GetDeployment(context.TODO(), rs.Primary.ID, teamID) + _, err := testClient.GetDeployment(context.TODO(), rs.Primary.ID, teamID) return err } } @@ -39,7 +39,7 @@ func contains(items []string, i string) bool { return false } -func testAccEnvironmentSet(n, teamID string, envs ...string) resource.TestCheckFunc { +func testAccEnvironmentSet(testClient *client.Client, n, teamID string, envs ...string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -49,7 +49,7 @@ func testAccEnvironmentSet(n, teamID string, envs ...string) resource.TestCheckF return fmt.Errorf("no DeploymentID is set") } - dpl, err := testClient().GetDeployment(context.TODO(), rs.Primary.ID, teamID) + dpl, err := testClient.GetDeployment(context.TODO(), rs.Primary.ID, teamID) if err != nil { return err } @@ -73,28 +73,27 @@ func TestAcc_Deployment(t *testing.T) { projectSuffix := acctest.RandString(16) testTeamID := resource.TestCheckNoResourceAttr("vercel_deployment.test", "team_id") - if testTeam() != "" { - testTeamID = resource.TestCheckResourceAttr("vercel_deployment.test", "team_id", testTeam()) + if testTeam(t) != "" { + testTeamID = resource.TestCheckResourceAttr("vercel_deployment.test", "team_id", testTeam(t)) } resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, CheckDestroy: noopDestroyCheck, Steps: []resource.TestStep{ { - Config: testAccDeploymentConfig(projectSuffix, teamIDConfig(), ""), + Config: testAccDeploymentConfig(projectSuffix, teamIDConfig(t), ""), Check: resource.ComposeAggregateTestCheckFunc( testTeamID, - testAccDeploymentExists("vercel_deployment.test", ""), + testAccDeploymentExists(testClient(t), "vercel_deployment.test", ""), resource.TestCheckResourceAttr("vercel_deployment.test", "production", "true"), ), }, { - Config: deploymentWithPrebuiltProject(projectSuffix, teamIDConfig()), + Config: deploymentWithPrebuiltProject(projectSuffix, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( testTeamID, - testAccDeploymentExists("vercel_deployment.test", ""), + testAccDeploymentExists(testClient(t), "vercel_deployment.test", ""), ), }, }, @@ -104,19 +103,18 @@ func TestAcc_Deployment(t *testing.T) { func TestAcc_DeploymentWithEnvironment(t *testing.T) { projectSuffix := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, CheckDestroy: noopDestroyCheck, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { - Config: testAccDeploymentConfig(projectSuffix, teamIDConfig(), `environment = { + Config: testAccDeploymentConfig(projectSuffix, teamIDConfig(t), `environment = { FOO = "baz", BAR = "qux", BAZ = null }`), Check: resource.ComposeAggregateTestCheckFunc( - testAccDeploymentExists("vercel_deployment.test", ""), - testAccEnvironmentSet("vercel_deployment.test", "", "FOO", "BAR"), + testAccDeploymentExists(testClient(t), "vercel_deployment.test", ""), + testAccEnvironmentSet(testClient(t), "vercel_deployment.test", "", "FOO", "BAR"), resource.TestCheckResourceAttr("vercel_deployment.test", "environment.FOO", "baz"), resource.TestCheckResourceAttr("vercel_deployment.test", "environment.BAR", "qux"), ), @@ -128,16 +126,16 @@ func TestAcc_DeploymentWithEnvironment(t *testing.T) { func TestAcc_DeploymentWithProjectSettings(t *testing.T) { projectSuffix := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + CheckDestroy: noopDestroyCheck, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { - Config: testAccDeploymentConfig(projectSuffix, teamIDConfig(), `project_settings = { + Config: testAccDeploymentConfig(projectSuffix, teamIDConfig(t), `project_settings = { output_directory = ".", }`), Check: resource.ComposeAggregateTestCheckFunc( - testAccDeploymentExists("vercel_deployment.test", ""), + testAccDeploymentExists(testClient(t), "vercel_deployment.test", ""), resource.TestCheckResourceAttr("vercel_deployment.test", "production", "true"), resource.TestCheckResourceAttr("vercel_deployment.test", "project_settings.output_directory", "."), // resource.TestCheckResourceAttr("vercel_deployment.test", "project_settings.build_command", "npm run build"), @@ -150,14 +148,13 @@ func TestAcc_DeploymentWithProjectSettings(t *testing.T) { func TestAcc_DeploymentWithRootDirectoryOverride(t *testing.T) { projectSuffix := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, CheckDestroy: noopDestroyCheck, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { - Config: testAccRootDirectoryOverride(projectSuffix, teamIDConfig()), + Config: testAccRootDirectoryOverride(projectSuffix, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( - testAccDeploymentExists("vercel_deployment.test", ""), + testAccDeploymentExists(testClient(t), "vercel_deployment.test", ""), resource.TestCheckResourceAttr("vercel_deployment.test", "production", "true"), ), }, @@ -168,14 +165,13 @@ func TestAcc_DeploymentWithRootDirectoryOverride(t *testing.T) { func TestAcc_DeploymentWithPathPrefix(t *testing.T) { projectSuffix := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, CheckDestroy: noopDestroyCheck, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { - Config: testAccRootDirectoryWithPathPrefix(projectSuffix, teamIDConfig()), + Config: testAccRootDirectoryWithPathPrefix(projectSuffix, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( - testAccDeploymentExists("vercel_deployment.test", ""), + testAccDeploymentExists(testClient(t), "vercel_deployment.test", ""), ), }, }, @@ -198,7 +194,7 @@ func TestAcc_DeploymentWithDeleteOnDestroy(t *testing.T) { } testDeploymentGone := func() resource.TestCheckFunc { return func(*terraform.State) error { - _, err := testClient().GetDeployment(context.TODO(), deploymentID, "") + _, err := testClient(t).GetDeployment(context.TODO(), deploymentID, "") if err == nil { return fmt.Errorf("expected not_found error, but got no error") } @@ -210,21 +206,20 @@ func TestAcc_DeploymentWithDeleteOnDestroy(t *testing.T) { } } resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, CheckDestroy: func(s *terraform.State) error { return nil }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { - Config: testAccDeploymentConfig(projectSuffix, teamIDConfig(), extraConfig), + Config: testAccDeploymentConfig(projectSuffix, teamIDConfig(t), extraConfig), Check: resource.ComposeAggregateTestCheckFunc( - testAccDeploymentExists("vercel_deployment.test", ""), + testAccDeploymentExists(testClient(t), "vercel_deployment.test", ""), storeDeploymentID("vercel_deployment.test", &deploymentID), ), }, { - Config: testAccDeploymentConfigWithNoDeployment(projectSuffix, teamIDConfig()), + Config: testAccDeploymentConfigWithNoDeployment(projectSuffix, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( testDeploymentGone(), ), @@ -236,15 +231,14 @@ func TestAcc_DeploymentWithDeleteOnDestroy(t *testing.T) { func TestAcc_DeploymentWithGitSource(t *testing.T) { projectSuffix := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, CheckDestroy: noopDestroyCheck, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { - Config: testAccDeployFromGitSource(projectSuffix, teamIDConfig()), + Config: testAccDeployFromGitSource(projectSuffix, teamIDConfig(t), testGithubRepo(t), testBitbucketRepo(t)), Check: resource.ComposeAggregateTestCheckFunc( - testAccDeploymentExists("vercel_deployment.bitbucket", testTeam()), - testAccDeploymentExists("vercel_deployment.github", testTeam()), + testAccDeploymentExists(testClient(t), "vercel_deployment.bitbucket", testTeam(t)), + testAccDeploymentExists(testClient(t), "vercel_deployment.github", testTeam(t)), ), }, }, @@ -279,15 +273,14 @@ func TestAcc_DeploymentWithMissingFilesPath(t *testing.T) { projectSuffix := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, CheckDestroy: noopDestroyCheck, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { PreConfig: func() { createRandomFilePreConfig(t) }, - Config: testAccWithDirectoryUpload(projectSuffix, teamIDConfig()), + Config: testAccWithDirectoryUpload(projectSuffix, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( - testAccDeploymentExists("vercel_deployment.test", ""), + testAccDeploymentExists(testClient(t), "vercel_deployment.test", ""), ), }, }, @@ -416,7 +409,7 @@ resource "vercel_deployment" "test" { }`, projectSuffix, teamID) } -func testAccDeployFromGitSource(projectSuffix, teamID string) string { +func testAccDeployFromGitSource(projectSuffix, teamID string, githubRepo string, bitbucketRepo string) string { return fmt.Sprintf(` resource "vercel_project" "github" { name = "test-acc-deployment-%[1]s-github" @@ -444,7 +437,7 @@ resource "vercel_deployment" "bitbucket" { ref = "main" %[4]s } -`, projectSuffix, testGithubRepo(), testBitbucketRepo(), teamID) +`, projectSuffix, githubRepo, bitbucketRepo, teamID) } func testAccWithDirectoryUpload(projectSuffix, teamID string) string { diff --git a/vercel/resource_dns_record_test.go b/vercel/resource_dns_record_test.go index a92fd177..b9d3b40b 100644 --- a/vercel/resource_dns_record_test.go +++ b/vercel/resource_dns_record_test.go @@ -11,7 +11,7 @@ import ( "github.com/vercel/terraform-provider-vercel/v2/client" ) -func testAccDNSRecordDestroy(n, teamID string) resource.TestCheckFunc { +func testAccDNSRecordDestroy(testClient *client.Client, n, teamID string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -22,7 +22,7 @@ func testAccDNSRecordDestroy(n, teamID string) resource.TestCheckFunc { return fmt.Errorf("no ID is set") } - _, err := testClient().GetDNSRecord(context.TODO(), rs.Primary.ID, teamID) + _, err := testClient.GetDNSRecord(context.TODO(), rs.Primary.ID, teamID) if err == nil { return fmt.Errorf("Found project but expected it to have been deleted") @@ -35,7 +35,7 @@ func testAccDNSRecordDestroy(n, teamID string) resource.TestCheckFunc { } } -func testAccDNSRecordExists(n, teamID string) resource.TestCheckFunc { +func testAccDNSRecordExists(testClient *client.Client, n, teamID string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -46,7 +46,7 @@ func testAccDNSRecordExists(n, teamID string) resource.TestCheckFunc { return fmt.Errorf("no ID is set") } - _, err := testClient().GetDNSRecord(context.TODO(), rs.Primary.ID, teamID) + _, err := testClient.GetDNSRecord(context.TODO(), rs.Primary.ID, teamID) return err } } @@ -55,68 +55,67 @@ func TestAcc_DNSRecord(t *testing.T) { t.Skip("Skipping until i have a domain in a suitable location to test with") nameSuffix := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, CheckDestroy: resource.ComposeAggregateTestCheckFunc( - testAccDNSRecordDestroy("vercel_dns_record.a_without_ttl", testTeam()), - testAccDNSRecordDestroy("vercel_dns_record.a", testTeam()), - testAccDNSRecordDestroy("vercel_dns_record.aaaa", testTeam()), - testAccDNSRecordDestroy("vercel_dns_record.alias", testTeam()), - testAccDNSRecordDestroy("vercel_dns_record.caa", testTeam()), - testAccDNSRecordDestroy("vercel_dns_record.cname", testTeam()), - testAccDNSRecordDestroy("vercel_dns_record.mx", testTeam()), - testAccDNSRecordDestroy("vercel_dns_record.srv", testTeam()), - testAccDNSRecordDestroy("vercel_dns_record.txt", testTeam()), + testAccDNSRecordDestroy(testClient(t), "vercel_dns_record.a_without_ttl", testTeam(t)), + testAccDNSRecordDestroy(testClient(t), "vercel_dns_record.a", testTeam(t)), + testAccDNSRecordDestroy(testClient(t), "vercel_dns_record.aaaa", testTeam(t)), + testAccDNSRecordDestroy(testClient(t), "vercel_dns_record.alias", testTeam(t)), + testAccDNSRecordDestroy(testClient(t), "vercel_dns_record.caa", testTeam(t)), + testAccDNSRecordDestroy(testClient(t), "vercel_dns_record.cname", testTeam(t)), + testAccDNSRecordDestroy(testClient(t), "vercel_dns_record.mx", testTeam(t)), + testAccDNSRecordDestroy(testClient(t), "vercel_dns_record.srv", testTeam(t)), + testAccDNSRecordDestroy(testClient(t), "vercel_dns_record.txt", testTeam(t)), ), Steps: []resource.TestStep{ { - Config: testAccDNSRecordConfig(testDomain(), nameSuffix, teamIDConfig()), + Config: testAccDNSRecordConfig(testDomain(t), nameSuffix, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( - testAccDNSRecordExists("vercel_dns_record.a_without_ttl", testTeam()), - resource.TestCheckResourceAttr("vercel_dns_record.a_without_ttl", "domain", testDomain()), + testAccDNSRecordExists(testClient(t), "vercel_dns_record.a_without_ttl", testTeam(t)), + resource.TestCheckResourceAttr("vercel_dns_record.a_without_ttl", "domain", testDomain(t)), resource.TestCheckResourceAttr("vercel_dns_record.a_without_ttl", "type", "A"), resource.TestCheckResourceAttr("vercel_dns_record.a_without_ttl", "ttl", "60"), resource.TestCheckResourceAttr("vercel_dns_record.a_without_ttl", "value", "127.0.0.1"), resource.TestCheckResourceAttr("vercel_dns_record.a_without_ttl", "comment", "a without ttl"), - testAccDNSRecordExists("vercel_dns_record.a", testTeam()), - resource.TestCheckResourceAttr("vercel_dns_record.a", "domain", testDomain()), + testAccDNSRecordExists(testClient(t), "vercel_dns_record.a", testTeam(t)), + resource.TestCheckResourceAttr("vercel_dns_record.a", "domain", testDomain(t)), resource.TestCheckResourceAttr("vercel_dns_record.a", "type", "A"), resource.TestCheckResourceAttr("vercel_dns_record.a", "ttl", "120"), resource.TestCheckResourceAttr("vercel_dns_record.a", "value", "127.0.0.1"), resource.TestCheckResourceAttr("vercel_dns_record.a", "comment", "a"), - testAccDNSRecordExists("vercel_dns_record.aaaa", testTeam()), - resource.TestCheckResourceAttr("vercel_dns_record.aaaa", "domain", testDomain()), + testAccDNSRecordExists(testClient(t), "vercel_dns_record.aaaa", testTeam(t)), + resource.TestCheckResourceAttr("vercel_dns_record.aaaa", "domain", testDomain(t)), resource.TestCheckResourceAttr("vercel_dns_record.aaaa", "type", "AAAA"), resource.TestCheckResourceAttr("vercel_dns_record.aaaa", "ttl", "120"), resource.TestCheckResourceAttr("vercel_dns_record.aaaa", "value", "::1"), resource.TestCheckResourceAttr("vercel_dns_record.aaaa", "comment", "aaaa"), - testAccDNSRecordExists("vercel_dns_record.alias", testTeam()), - resource.TestCheckResourceAttr("vercel_dns_record.alias", "domain", testDomain()), + testAccDNSRecordExists(testClient(t), "vercel_dns_record.alias", testTeam(t)), + resource.TestCheckResourceAttr("vercel_dns_record.alias", "domain", testDomain(t)), resource.TestCheckResourceAttr("vercel_dns_record.alias", "type", "ALIAS"), resource.TestCheckResourceAttr("vercel_dns_record.alias", "ttl", "120"), resource.TestCheckResourceAttr("vercel_dns_record.alias", "value", "example.com."), resource.TestCheckResourceAttr("vercel_dns_record.alias", "comment", "alias"), - testAccDNSRecordExists("vercel_dns_record.caa", testTeam()), - resource.TestCheckResourceAttr("vercel_dns_record.caa", "domain", testDomain()), + testAccDNSRecordExists(testClient(t), "vercel_dns_record.caa", testTeam(t)), + resource.TestCheckResourceAttr("vercel_dns_record.caa", "domain", testDomain(t)), resource.TestCheckResourceAttr("vercel_dns_record.caa", "type", "CAA"), resource.TestCheckResourceAttr("vercel_dns_record.caa", "ttl", "120"), resource.TestCheckResourceAttr("vercel_dns_record.caa", "value", "0 issue \"letsencrypt.org\""), resource.TestCheckResourceAttr("vercel_dns_record.caa", "comment", "caa"), - testAccDNSRecordExists("vercel_dns_record.cname", testTeam()), - resource.TestCheckResourceAttr("vercel_dns_record.cname", "domain", testDomain()), + testAccDNSRecordExists(testClient(t), "vercel_dns_record.cname", testTeam(t)), + resource.TestCheckResourceAttr("vercel_dns_record.cname", "domain", testDomain(t)), resource.TestCheckResourceAttr("vercel_dns_record.cname", "type", "CNAME"), resource.TestCheckResourceAttr("vercel_dns_record.cname", "ttl", "120"), resource.TestCheckResourceAttr("vercel_dns_record.cname", "value", "example.com."), resource.TestCheckResourceAttr("vercel_dns_record.cname", "comment", "cname"), - testAccDNSRecordExists("vercel_dns_record.mx", testTeam()), - resource.TestCheckResourceAttr("vercel_dns_record.mx", "domain", testDomain()), + testAccDNSRecordExists(testClient(t), "vercel_dns_record.mx", testTeam(t)), + resource.TestCheckResourceAttr("vercel_dns_record.mx", "domain", testDomain(t)), resource.TestCheckResourceAttr("vercel_dns_record.mx", "type", "MX"), resource.TestCheckResourceAttr("vercel_dns_record.mx", "ttl", "120"), resource.TestCheckResourceAttr("vercel_dns_record.mx", "mx_priority", "123"), resource.TestCheckResourceAttr("vercel_dns_record.mx", "value", "example.com."), resource.TestCheckResourceAttr("vercel_dns_record.mx", "comment", "mx"), - testAccDNSRecordExists("vercel_dns_record.srv", testTeam()), - resource.TestCheckResourceAttr("vercel_dns_record.srv", "domain", testDomain()), + testAccDNSRecordExists(testClient(t), "vercel_dns_record.srv", testTeam(t)), + resource.TestCheckResourceAttr("vercel_dns_record.srv", "domain", testDomain(t)), resource.TestCheckResourceAttr("vercel_dns_record.srv", "type", "SRV"), resource.TestCheckResourceAttr("vercel_dns_record.srv", "ttl", "120"), resource.TestCheckResourceAttr("vercel_dns_record.srv", "srv.port", "5000"), @@ -124,22 +123,22 @@ func TestAcc_DNSRecord(t *testing.T) { resource.TestCheckResourceAttr("vercel_dns_record.srv", "srv.priority", "27"), resource.TestCheckResourceAttr("vercel_dns_record.srv", "srv.target", "example.com."), resource.TestCheckResourceAttr("vercel_dns_record.srv", "comment", "srv"), - testAccDNSRecordExists("vercel_dns_record.srv_no_target", testTeam()), - resource.TestCheckResourceAttr("vercel_dns_record.srv_no_target", "domain", testDomain()), + testAccDNSRecordExists(testClient(t), "vercel_dns_record.srv_no_target", testTeam(t)), + resource.TestCheckResourceAttr("vercel_dns_record.srv_no_target", "domain", testDomain(t)), resource.TestCheckResourceAttr("vercel_dns_record.srv_no_target", "type", "SRV"), resource.TestCheckResourceAttr("vercel_dns_record.srv_no_target", "ttl", "120"), resource.TestCheckResourceAttr("vercel_dns_record.srv_no_target", "srv.port", "5000"), resource.TestCheckResourceAttr("vercel_dns_record.srv_no_target", "srv.weight", "120"), resource.TestCheckResourceAttr("vercel_dns_record.srv_no_target", "srv.priority", "27"), resource.TestCheckResourceAttr("vercel_dns_record.srv_no_target", "comment", "srv no target"), - testAccDNSRecordExists("vercel_dns_record.txt", testTeam()), - resource.TestCheckResourceAttr("vercel_dns_record.txt", "domain", testDomain()), + testAccDNSRecordExists(testClient(t), "vercel_dns_record.txt", testTeam(t)), + resource.TestCheckResourceAttr("vercel_dns_record.txt", "domain", testDomain(t)), resource.TestCheckResourceAttr("vercel_dns_record.txt", "type", "TXT"), resource.TestCheckResourceAttr("vercel_dns_record.txt", "ttl", "120"), resource.TestCheckResourceAttr("vercel_dns_record.txt", "value", "terraform testing"), resource.TestCheckResourceAttr("vercel_dns_record.txt", "comment", "txt"), - testAccDNSRecordExists("vercel_dns_record.ns", testTeam()), - resource.TestCheckResourceAttr("vercel_dns_record.ns", "domain", testDomain()), + testAccDNSRecordExists(testClient(t), "vercel_dns_record.ns", testTeam(t)), + resource.TestCheckResourceAttr("vercel_dns_record.ns", "domain", testDomain(t)), resource.TestCheckResourceAttr("vercel_dns_record.ns", "type", "NS"), resource.TestCheckResourceAttr("vercel_dns_record.ns", "ttl", "120"), resource.TestCheckResourceAttr("vercel_dns_record.ns", "value", "example.com."), @@ -147,58 +146,58 @@ func TestAcc_DNSRecord(t *testing.T) { ), }, { - Config: testAccDNSRecordConfigUpdated(testDomain(), nameSuffix, teamIDConfig()), + Config: testAccDNSRecordConfigUpdated(testDomain(t), nameSuffix, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( - testAccDNSRecordExists("vercel_dns_record.a_without_ttl", testTeam()), - resource.TestCheckResourceAttr("vercel_dns_record.a_without_ttl", "domain", testDomain()), + testAccDNSRecordExists(testClient(t), "vercel_dns_record.a_without_ttl", testTeam(t)), + resource.TestCheckResourceAttr("vercel_dns_record.a_without_ttl", "domain", testDomain(t)), resource.TestCheckResourceAttr("vercel_dns_record.a_without_ttl", "type", "A"), resource.TestCheckResourceAttr("vercel_dns_record.a_without_ttl", "value", "127.0.0.1"), - testAccDNSRecordExists("vercel_dns_record.a", testTeam()), - resource.TestCheckResourceAttr("vercel_dns_record.a", "domain", testDomain()), + testAccDNSRecordExists(testClient(t), "vercel_dns_record.a", testTeam(t)), + resource.TestCheckResourceAttr("vercel_dns_record.a", "domain", testDomain(t)), resource.TestCheckResourceAttr("vercel_dns_record.a", "type", "A"), resource.TestCheckResourceAttr("vercel_dns_record.a", "ttl", "60"), resource.TestCheckResourceAttr("vercel_dns_record.a", "value", "192.168.0.1"), - testAccDNSRecordExists("vercel_dns_record.aaaa", testTeam()), - resource.TestCheckResourceAttr("vercel_dns_record.aaaa", "domain", testDomain()), + testAccDNSRecordExists(testClient(t), "vercel_dns_record.aaaa", testTeam(t)), + resource.TestCheckResourceAttr("vercel_dns_record.aaaa", "domain", testDomain(t)), resource.TestCheckResourceAttr("vercel_dns_record.aaaa", "type", "AAAA"), resource.TestCheckResourceAttr("vercel_dns_record.aaaa", "ttl", "60"), resource.TestCheckResourceAttr("vercel_dns_record.aaaa", "value", "::0"), - testAccDNSRecordExists("vercel_dns_record.alias", testTeam()), - resource.TestCheckResourceAttr("vercel_dns_record.alias", "domain", testDomain()), + testAccDNSRecordExists(testClient(t), "vercel_dns_record.alias", testTeam(t)), + resource.TestCheckResourceAttr("vercel_dns_record.alias", "domain", testDomain(t)), resource.TestCheckResourceAttr("vercel_dns_record.alias", "type", "ALIAS"), resource.TestCheckResourceAttr("vercel_dns_record.alias", "ttl", "60"), resource.TestCheckResourceAttr("vercel_dns_record.alias", "value", "example2.com."), - testAccDNSRecordExists("vercel_dns_record.caa", testTeam()), - resource.TestCheckResourceAttr("vercel_dns_record.caa", "domain", testDomain()), + testAccDNSRecordExists(testClient(t), "vercel_dns_record.caa", testTeam(t)), + resource.TestCheckResourceAttr("vercel_dns_record.caa", "domain", testDomain(t)), resource.TestCheckResourceAttr("vercel_dns_record.caa", "type", "CAA"), resource.TestCheckResourceAttr("vercel_dns_record.caa", "ttl", "60"), resource.TestCheckResourceAttr("vercel_dns_record.caa", "value", "1 issue \"letsencrypt.org\""), - testAccDNSRecordExists("vercel_dns_record.cname", testTeam()), - resource.TestCheckResourceAttr("vercel_dns_record.cname", "domain", testDomain()), + testAccDNSRecordExists(testClient(t), "vercel_dns_record.cname", testTeam(t)), + resource.TestCheckResourceAttr("vercel_dns_record.cname", "domain", testDomain(t)), resource.TestCheckResourceAttr("vercel_dns_record.cname", "type", "CNAME"), resource.TestCheckResourceAttr("vercel_dns_record.cname", "ttl", "60"), resource.TestCheckResourceAttr("vercel_dns_record.cname", "value", "example2.com."), - testAccDNSRecordExists("vercel_dns_record.mx", testTeam()), - resource.TestCheckResourceAttr("vercel_dns_record.mx", "domain", testDomain()), + testAccDNSRecordExists(testClient(t), "vercel_dns_record.mx", testTeam(t)), + resource.TestCheckResourceAttr("vercel_dns_record.mx", "domain", testDomain(t)), resource.TestCheckResourceAttr("vercel_dns_record.mx", "type", "MX"), resource.TestCheckResourceAttr("vercel_dns_record.mx", "ttl", "60"), resource.TestCheckResourceAttr("vercel_dns_record.mx", "mx_priority", "333"), resource.TestCheckResourceAttr("vercel_dns_record.mx", "value", "example2.com."), - testAccDNSRecordExists("vercel_dns_record.srv", testTeam()), - resource.TestCheckResourceAttr("vercel_dns_record.srv", "domain", testDomain()), + testAccDNSRecordExists(testClient(t), "vercel_dns_record.srv", testTeam(t)), + resource.TestCheckResourceAttr("vercel_dns_record.srv", "domain", testDomain(t)), resource.TestCheckResourceAttr("vercel_dns_record.srv", "type", "SRV"), resource.TestCheckResourceAttr("vercel_dns_record.srv", "ttl", "60"), resource.TestCheckResourceAttr("vercel_dns_record.srv", "srv.port", "6000"), resource.TestCheckResourceAttr("vercel_dns_record.srv", "srv.weight", "60"), resource.TestCheckResourceAttr("vercel_dns_record.srv", "srv.priority", "127"), resource.TestCheckResourceAttr("vercel_dns_record.srv", "srv.target", "example2.com."), - testAccDNSRecordExists("vercel_dns_record.txt", testTeam()), - resource.TestCheckResourceAttr("vercel_dns_record.txt", "domain", testDomain()), + testAccDNSRecordExists(testClient(t), "vercel_dns_record.txt", testTeam(t)), + resource.TestCheckResourceAttr("vercel_dns_record.txt", "domain", testDomain(t)), resource.TestCheckResourceAttr("vercel_dns_record.txt", "type", "TXT"), resource.TestCheckResourceAttr("vercel_dns_record.txt", "ttl", "60"), resource.TestCheckResourceAttr("vercel_dns_record.txt", "value", "terraform testing two"), - testAccDNSRecordExists("vercel_dns_record.ns", testTeam()), - resource.TestCheckResourceAttr("vercel_dns_record.ns", "domain", testDomain()), + testAccDNSRecordExists(testClient(t), "vercel_dns_record.ns", testTeam(t)), + resource.TestCheckResourceAttr("vercel_dns_record.ns", "domain", testDomain(t)), resource.TestCheckResourceAttr("vercel_dns_record.ns", "type", "NS"), resource.TestCheckResourceAttr("vercel_dns_record.ns", "ttl", "60"), resource.TestCheckResourceAttr("vercel_dns_record.ns", "value", "example2.com."), diff --git a/vercel/resource_edge_config_item_test.go b/vercel/resource_edge_config_item_test.go index d0ecb12a..f2eb7ce7 100644 --- a/vercel/resource_edge_config_item_test.go +++ b/vercel/resource_edge_config_item_test.go @@ -26,7 +26,7 @@ func getEdgeConfigItemImportID(n string) resource.ImportStateIdFunc { } } -func testCheckEdgeConfigItemDeleted(n, key, teamID string) resource.TestCheckFunc { +func testCheckEdgeConfigItemDeleted(testClient *client.Client, n, key, teamID string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -37,7 +37,7 @@ func testCheckEdgeConfigItemDeleted(n, key, teamID string) resource.TestCheckFun return fmt.Errorf("no ID is set") } - _, err := testClient().GetEdgeConfigItem(context.TODO(), client.EdgeConfigItemRequest{ + _, err := testClient.GetEdgeConfigItem(context.TODO(), client.EdgeConfigItemRequest{ TeamID: teamID, EdgeConfigID: rs.Primary.ID, Key: key, @@ -56,14 +56,13 @@ func testCheckEdgeConfigItemDeleted(n, key, teamID string) resource.TestCheckFun func TestAcc_EdgeConfigItemResource(t *testing.T) { name := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, - CheckDestroy: testCheckEdgeConfigDeleted("vercel_edge_config.test_item", testTeam()), + CheckDestroy: testCheckEdgeConfigDeleted(testClient(t), "vercel_edge_config.test_item", testTeam(t)), Steps: []resource.TestStep{ { - Config: testAccResourceEdgeConfigItem(name, teamIDConfig()), + Config: testAccResourceEdgeConfigItem(name, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( - testCheckEdgeConfigExists(testTeam(), "vercel_edge_config.test_item"), + testCheckEdgeConfigExists(testClient(t), testTeam(t), "vercel_edge_config.test_item"), resource.TestCheckResourceAttr("vercel_edge_config_item.test", "key", "foobar"), resource.TestCheckResourceAttr("vercel_edge_config_item.test", "value", "baz"), ), @@ -74,10 +73,10 @@ func TestAcc_EdgeConfigItemResource(t *testing.T) { ImportStateIdFunc: getEdgeConfigItemImportID("vercel_edge_config_item.test"), }, { - Config: testAccResourceEdgeConfigItemDeleted(name, teamIDConfig()), + Config: testAccResourceEdgeConfigItemDeleted(name, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( - testCheckEdgeConfigExists(testTeam(), "vercel_edge_config.test_item"), - testCheckEdgeConfigItemDeleted("vercel_edge_config.test_item", "foobar", testTeam()), + testCheckEdgeConfigExists(testClient(t), testTeam(t), "vercel_edge_config.test_item"), + testCheckEdgeConfigItemDeleted(testClient(t), "vercel_edge_config.test_item", "foobar", testTeam(t)), ), }, }, diff --git a/vercel/resource_edge_config_schema_test.go b/vercel/resource_edge_config_schema_test.go index d29a8222..148f00cf 100644 --- a/vercel/resource_edge_config_schema_test.go +++ b/vercel/resource_edge_config_schema_test.go @@ -12,7 +12,7 @@ import ( "github.com/vercel/terraform-provider-vercel/v2/client" ) -func testCheckEdgeConfigSchemaExists(teamID, n string) resource.TestCheckFunc { +func testCheckEdgeConfigSchemaExists(testClient *client.Client, teamID, n string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -23,7 +23,7 @@ func testCheckEdgeConfigSchemaExists(teamID, n string) resource.TestCheckFunc { return fmt.Errorf("no ID is set") } - _, err := testClient().GetEdgeConfigSchema(context.TODO(), rs.Primary.ID, teamID) + _, err := testClient.GetEdgeConfigSchema(context.TODO(), rs.Primary.ID, teamID) if err != nil { return fmt.Errorf("error getting %s/%s: %w", teamID, rs.Primary.ID, err) } @@ -31,7 +31,7 @@ func testCheckEdgeConfigSchemaExists(teamID, n string) resource.TestCheckFunc { } } -func testCheckEdgeConfigSchemaDeleted(n, teamID string) resource.TestCheckFunc { +func testCheckEdgeConfigSchemaDeleted(testClient *client.Client, n, teamID string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -42,7 +42,7 @@ func testCheckEdgeConfigSchemaDeleted(n, teamID string) resource.TestCheckFunc { return fmt.Errorf("no ID is set") } - _, err := testClient().GetEdgeConfigSchema(context.TODO(), rs.Primary.ID, teamID) + _, err := testClient.GetEdgeConfigSchema(context.TODO(), rs.Primary.ID, teamID) if err == nil { return fmt.Errorf("expected not_found error, but got no error") } @@ -57,9 +57,8 @@ func testCheckEdgeConfigSchemaDeleted(n, teamID string) resource.TestCheckFunc { func TestAcc_EdgeConfigSchemaResource(t *testing.T) { name := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, - CheckDestroy: testCheckEdgeConfigSchemaDeleted("vercel_edge_config_schema.test", testTeam()), + CheckDestroy: testCheckEdgeConfigSchemaDeleted(testClient(t), "vercel_edge_config_schema.test", testTeam(t)), Steps: []resource.TestStep{ { Config: ` @@ -75,17 +74,17 @@ func TestAcc_EdgeConfigSchemaResource(t *testing.T) { ExpectError: regexp.MustCompile("Value must be a valid JSON document"), }, { - Config: testAccResourceEdgeConfigSchema(name, teamIDConfig()), + Config: testAccResourceEdgeConfigSchema(name, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( - testCheckEdgeConfigSchemaExists(testTeam(), "vercel_edge_config_schema.test"), + testCheckEdgeConfigSchemaExists(testClient(t), testTeam(t), "vercel_edge_config_schema.test"), resource.TestCheckResourceAttrSet("vercel_edge_config_schema.test", "id"), resource.TestCheckResourceAttrSet("vercel_edge_config_schema.test", "definition"), ), }, { - Config: testAccResourceEdgeConfigSchemaUpdated(name, teamIDConfig()), + Config: testAccResourceEdgeConfigSchemaUpdated(name, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( - testCheckEdgeConfigSchemaExists(testTeam(), "vercel_edge_config_schema.test"), + testCheckEdgeConfigSchemaExists(testClient(t), testTeam(t), "vercel_edge_config_schema.test"), resource.TestCheckResourceAttrSet("vercel_edge_config_schema.test", "id"), resource.TestCheckResourceAttrSet("vercel_edge_config_schema.test", "definition"), ), diff --git a/vercel/resource_edge_config_test.go b/vercel/resource_edge_config_test.go index 7a05b08f..39d19749 100644 --- a/vercel/resource_edge_config_test.go +++ b/vercel/resource_edge_config_test.go @@ -11,7 +11,7 @@ import ( "github.com/vercel/terraform-provider-vercel/v2/client" ) -func testCheckEdgeConfigExists(teamID, n string) resource.TestCheckFunc { +func testCheckEdgeConfigExists(testClient *client.Client, teamID, n string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -22,12 +22,12 @@ func testCheckEdgeConfigExists(teamID, n string) resource.TestCheckFunc { return fmt.Errorf("no ID is set") } - _, err := testClient().GetEdgeConfig(context.TODO(), rs.Primary.ID, teamID) + _, err := testClient.GetEdgeConfig(context.TODO(), rs.Primary.ID, teamID) return err } } -func testCheckEdgeConfigDeleted(n, teamID string) resource.TestCheckFunc { +func testCheckEdgeConfigDeleted(testClient *client.Client, n, teamID string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -38,7 +38,7 @@ func testCheckEdgeConfigDeleted(n, teamID string) resource.TestCheckFunc { return fmt.Errorf("no ID is set") } - _, err := testClient().GetEdgeConfig(context.TODO(), rs.Primary.ID, teamID) + _, err := testClient.GetEdgeConfig(context.TODO(), rs.Primary.ID, teamID) if err == nil { return fmt.Errorf("expected not_found error, but got no error") } @@ -53,22 +53,21 @@ func testCheckEdgeConfigDeleted(n, teamID string) resource.TestCheckFunc { func TestAcc_EdgeConfigResource(t *testing.T) { name := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, - CheckDestroy: testCheckEdgeConfigDeleted("vercel_edge_config.test", testTeam()), + CheckDestroy: testCheckEdgeConfigDeleted(testClient(t), "vercel_edge_config.test", testTeam(t)), Steps: []resource.TestStep{ { - Config: testAccResourceEdgeConfig(name, teamIDConfig()), + Config: testAccResourceEdgeConfig(name, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( - testCheckEdgeConfigExists(testTeam(), "vercel_edge_config.test"), + testCheckEdgeConfigExists(testClient(t), testTeam(t), "vercel_edge_config.test"), resource.TestCheckResourceAttr("vercel_edge_config.test", "name", name), resource.TestCheckResourceAttrSet("vercel_edge_config.test", "id"), ), }, { - Config: testAccResourceEdgeConfigUpdated(name, teamIDConfig()), + Config: testAccResourceEdgeConfigUpdated(name, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( - testCheckEdgeConfigExists(testTeam(), "vercel_edge_config.test"), + testCheckEdgeConfigExists(testClient(t), testTeam(t), "vercel_edge_config.test"), resource.TestCheckResourceAttr("vercel_edge_config.test", "name", fmt.Sprintf("%s-updated", name)), resource.TestCheckResourceAttrSet("vercel_edge_config.test", "id"), ), diff --git a/vercel/resource_edge_config_token_test.go b/vercel/resource_edge_config_token_test.go index c29ddec1..3fd9eb64 100644 --- a/vercel/resource_edge_config_token_test.go +++ b/vercel/resource_edge_config_token_test.go @@ -11,7 +11,7 @@ import ( "github.com/vercel/terraform-provider-vercel/v2/client" ) -func testCheckEdgeConfigTokenExists(teamID, n string) resource.TestCheckFunc { +func testCheckEdgeConfigTokenExists(testClient *client.Client, teamID, n string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -22,7 +22,7 @@ func testCheckEdgeConfigTokenExists(teamID, n string) resource.TestCheckFunc { return fmt.Errorf("no ID is set") } - _, err := testClient().GetEdgeConfigToken(context.TODO(), client.EdgeConfigTokenRequest{ + _, err := testClient.GetEdgeConfigToken(context.TODO(), client.EdgeConfigTokenRequest{ Token: rs.Primary.Attributes["token"], EdgeConfigID: rs.Primary.Attributes["edge_config_id"], TeamID: teamID, @@ -34,7 +34,7 @@ func testCheckEdgeConfigTokenExists(teamID, n string) resource.TestCheckFunc { } } -func testCheckEdgeConfigTokenDeleted(n, teamID string) resource.TestCheckFunc { +func testCheckEdgeConfigTokenDeleted(testClient *client.Client, n, teamID string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -45,7 +45,7 @@ func testCheckEdgeConfigTokenDeleted(n, teamID string) resource.TestCheckFunc { return fmt.Errorf("no ID is set") } - _, err := testClient().GetEdgeConfigToken(context.TODO(), client.EdgeConfigTokenRequest{ + _, err := testClient.GetEdgeConfigToken(context.TODO(), client.EdgeConfigTokenRequest{ Token: rs.Primary.ID, EdgeConfigID: rs.Primary.Attributes["edge_config_id"], TeamID: teamID, @@ -64,14 +64,13 @@ func testCheckEdgeConfigTokenDeleted(n, teamID string) resource.TestCheckFunc { func TestAcc_EdgeConfigTokenResource(t *testing.T) { name := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, - CheckDestroy: testCheckEdgeConfigTokenDeleted("vercel_edge_config_token.test", testTeam()), + CheckDestroy: testCheckEdgeConfigTokenDeleted(testClient(t), "vercel_edge_config_token.test", testTeam(t)), Steps: []resource.TestStep{ { - Config: testAccResourceEdgeConfigToken(name, teamIDConfig()), + Config: testAccResourceEdgeConfigToken(name, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( - testCheckEdgeConfigTokenExists(testTeam(), "vercel_edge_config_token.test"), + testCheckEdgeConfigTokenExists(testClient(t), testTeam(t), "vercel_edge_config_token.test"), resource.TestCheckResourceAttr("vercel_edge_config_token.test", "label", "test token"), resource.TestCheckResourceAttrSet("vercel_edge_config_token.test", "id"), resource.TestCheckResourceAttrSet("vercel_edge_config_token.test", "edge_config_id"), diff --git a/vercel/resource_firewall_bypass_test.go b/vercel/resource_firewall_bypass_test.go index fcc3b5f3..7f1b90d8 100644 --- a/vercel/resource_firewall_bypass_test.go +++ b/vercel/resource_firewall_bypass_test.go @@ -13,11 +13,10 @@ import ( func TestAcc_FirewallBypassResource(t *testing.T) { name := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { - Config: testAccFirewallBypassConfigResource(name, teamIDConfig()), + Config: testAccFirewallBypassConfigResource(name, teamIDConfig(t), testGithubRepo(&testing.T{})), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("vercel_firewall_bypass.bypass_one", "domain", "test-acc-domain-"+name+".vercel.app"), resource.TestCheckResourceAttr("vercel_firewall_bypass.bypass_some", "domain", "*"), @@ -60,7 +59,7 @@ func TestAcc_FirewallBypassResource(t *testing.T) { }, }, { - Config: testAccFirewallBypassConfigResourceUpdated(name, teamIDConfig()), + Config: testAccFirewallBypassConfigResourceUpdated(name, teamIDConfig(t), testGithubRepo(t)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("vercel_firewall_bypass.bypass_one", "source_ip", "0.0.0.0/0"), resource.TestCheckResourceAttrWith("vercel_firewall_bypass.bypass_one", "id", func(id string) error { @@ -75,7 +74,7 @@ func TestAcc_FirewallBypassResource(t *testing.T) { }) } -func testAccFirewallBypassConfigResource(name, teamID string) string { +func testAccFirewallBypassConfigResource(name, teamID string, githubRepo string) string { return fmt.Sprintf(` resource "vercel_project" "bypass_project" { name = "test-acc-%[1]s-enabled" @@ -110,10 +109,10 @@ resource "vercel_firewall_bypass" "bypass_some" { depends_on = [vercel_project_domain.test] } -`, name, teamID, testGithubRepo()) +`, name, teamID, githubRepo) } -func testAccFirewallBypassConfigResourceUpdated(name, teamID string) string { +func testAccFirewallBypassConfigResourceUpdated(name, teamID string, githubRepo string) string { return fmt.Sprintf(` resource "vercel_project" "bypass_project" { name = "test-acc-%[1]s-enabled" @@ -139,5 +138,5 @@ resource "vercel_firewall_bypass" "bypass_one" { depends_on = [vercel_project_domain.test] } -`, name, teamID, testGithubRepo()) +`, name, teamID, githubRepo) } diff --git a/vercel/resource_firewall_config_test.go b/vercel/resource_firewall_config_test.go index 8010ee5c..07e10ba7 100644 --- a/vercel/resource_firewall_config_test.go +++ b/vercel/resource_firewall_config_test.go @@ -31,11 +31,10 @@ func getFirewallImportID(n string) resource.ImportStateIdFunc { func TestAcc_FirewallConfigResource(t *testing.T) { name := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { - Config: testAccFirewallConfigResource(name, teamIDConfig()), + Config: testAccFirewallConfigResource(name, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr( "vercel_firewall_config.managed", @@ -188,7 +187,7 @@ func TestAcc_FirewallConfigResource(t *testing.T) { ImportStateIdFunc: getFirewallImportID("vercel_firewall_config.ips"), }, { - Config: testAccFirewallConfigResourceUpdated(name, teamIDConfig()), + Config: testAccFirewallConfigResourceUpdated(name, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr( "vercel_firewall_config.managed", diff --git a/vercel/resource_integration_project_access_test.go b/vercel/resource_integration_project_access_test.go index c48682e7..7b18adac 100644 --- a/vercel/resource_integration_project_access_test.go +++ b/vercel/resource_integration_project_access_test.go @@ -8,16 +8,17 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" + "github.com/vercel/terraform-provider-vercel/v2/client" ) -func testCheckIntegrationProjectAccessDestroyed(n, teamID string) resource.TestCheckFunc { +func testCheckIntegrationProjectAccessDestroyed(testClient *client.Client, n, teamID string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { return fmt.Errorf("not found: %s", n) } - ipa, err := testClient().GetIntegrationProjectAccess(context.TODO(), rs.Primary.Attributes["integration_id"], rs.Primary.Attributes["project_id"], teamID) + ipa, err := testClient.GetIntegrationProjectAccess(context.TODO(), rs.Primary.Attributes["integration_id"], rs.Primary.Attributes["project_id"], teamID) if err != nil { return err } @@ -29,14 +30,14 @@ func testCheckIntegrationProjectAccessDestroyed(n, teamID string) resource.TestC } } -func testCheckIntegrationProjectAccessExists(n, teamID string) resource.TestCheckFunc { +func testCheckIntegrationProjectAccessExists(testClient *client.Client, n, teamID string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { return fmt.Errorf("not found: %s", n) } - ipa, err := testClient().GetIntegrationProjectAccess(context.TODO(), rs.Primary.Attributes["integration_id"], rs.Primary.Attributes["project_id"], teamID) + ipa, err := testClient.GetIntegrationProjectAccess(context.TODO(), rs.Primary.Attributes["integration_id"], rs.Primary.Attributes["project_id"], teamID) if err != nil { return err } @@ -51,15 +52,14 @@ func testCheckIntegrationProjectAccessExists(n, teamID string) resource.TestChec func TestAcc_IntegrationProjectAccess(t *testing.T) { name := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, - CheckDestroy: testCheckIntegrationProjectAccessDestroyed("vercel_integration_project_access.test_integration_access", testTeam()), + CheckDestroy: testCheckIntegrationProjectAccessDestroyed(testClient(t), "vercel_integration_project_access.test_integration_access", testTeam(t)), Steps: []resource.TestStep{ { - Config: testAccIntegrationProjectAccess(name, teamIDConfig(), testExistingIntegration()), + Config: testAccIntegrationProjectAccess(name, teamIDConfig(t), testExistingIntegration(t)), Check: resource.ComposeAggregateTestCheckFunc( - testCheckIntegrationProjectAccessExists("vercel_integration_project_access.test_integration_access", testTeam()), - resource.TestCheckResourceAttr("vercel_integration_project_access.test_integration_access", "team_id", testTeam()), + testCheckIntegrationProjectAccessExists(testClient(t), "vercel_integration_project_access.test_integration_access", testTeam(t)), + resource.TestCheckResourceAttr("vercel_integration_project_access.test_integration_access", "team_id", testTeam(t)), ), }, }, @@ -69,15 +69,14 @@ func TestAcc_IntegrationProjectAccess(t *testing.T) { func TestAcc_IntegrationProjectAccessWithoutExplicitTeam(t *testing.T) { name := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, - CheckDestroy: testCheckIntegrationProjectAccessDestroyed("vercel_integration_project_access.test_integration_access", testTeam()), + CheckDestroy: testCheckIntegrationProjectAccessDestroyed(testClient(t), "vercel_integration_project_access.test_integration_access", testTeam(t)), Steps: []resource.TestStep{ { - Config: testAccIntegrationProjectAccessUsingProvider(name, testTeam(), testExistingIntegration()), + Config: testAccIntegrationProjectAccessUsingProvider(name, testTeam(t), testExistingIntegration(t)), Check: resource.ComposeAggregateTestCheckFunc( - testCheckIntegrationProjectAccessExists("vercel_integration_project_access.test_integration_access", testTeam()), - resource.TestCheckResourceAttr("vercel_integration_project_access.test_integration_access", "team_id", testTeam()), + testCheckIntegrationProjectAccessExists(testClient(t), "vercel_integration_project_access.test_integration_access", testTeam(t)), + resource.TestCheckResourceAttr("vercel_integration_project_access.test_integration_access", "team_id", testTeam(t)), ), }, }, @@ -100,7 +99,7 @@ resource "vercel_integration_project_access" "test_integration_access" { project_id = vercel_project.test.id %[2]s } -`, name, team, integration, testTeam()) +`, name, team, integration) } func testAccIntegrationProjectAccessUsingProvider(name, team, integration string) string { diff --git a/vercel/resource_log_drain_test.go b/vercel/resource_log_drain_test.go index 2accd9c6..1431bf82 100644 --- a/vercel/resource_log_drain_test.go +++ b/vercel/resource_log_drain_test.go @@ -11,7 +11,7 @@ import ( "github.com/vercel/terraform-provider-vercel/v2/client" ) -func testCheckLogDrainExists(teamID, n string) resource.TestCheckFunc { +func testCheckLogDrainExists(testClient *client.Client, teamID, n string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -22,12 +22,12 @@ func testCheckLogDrainExists(teamID, n string) resource.TestCheckFunc { return fmt.Errorf("no ID is set") } - _, err := testClient().GetLogDrain(context.TODO(), rs.Primary.ID, teamID) + _, err := testClient.GetLogDrain(context.TODO(), rs.Primary.ID, teamID) return err } } -func testCheckLogDrainDeleted(n, teamID string) resource.TestCheckFunc { +func testCheckLogDrainDeleted(testClient *client.Client, n, teamID string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -38,7 +38,7 @@ func testCheckLogDrainDeleted(n, teamID string) resource.TestCheckFunc { return fmt.Errorf("no ID is set") } - _, err := testClient().GetLogDrain(context.TODO(), rs.Primary.ID, teamID) + _, err := testClient.GetLogDrain(context.TODO(), rs.Primary.ID, teamID) if err == nil { return fmt.Errorf("expected not_found error, but got no error") } @@ -53,14 +53,13 @@ func testCheckLogDrainDeleted(n, teamID string) resource.TestCheckFunc { func TestAcc_LogDrainResource(t *testing.T) { name := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, - CheckDestroy: testCheckLogDrainDeleted("vercel_log_drain.minimal", testTeam()), + CheckDestroy: testCheckLogDrainDeleted(testClient(t), "vercel_log_drain.minimal", testTeam(t)), Steps: []resource.TestStep{ { - Config: testAccResourceLogDrain(name, teamIDConfig()), + Config: testAccResourceLogDrain(name, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( - testCheckLogDrainExists(testTeam(), "vercel_log_drain.minimal"), + testCheckLogDrainExists(testClient(t), testTeam(t), "vercel_log_drain.minimal"), resource.TestCheckResourceAttr("vercel_log_drain.minimal", "delivery_format", "json"), resource.TestCheckResourceAttr("vercel_log_drain.minimal", "environments.#", "1"), resource.TestCheckResourceAttr("vercel_log_drain.minimal", "environments.0", "production"), @@ -71,7 +70,7 @@ func TestAcc_LogDrainResource(t *testing.T) { resource.TestCheckResourceAttrSet("vercel_log_drain.minimal", "team_id"), resource.TestCheckResourceAttrSet("vercel_log_drain.maximal", "secret"), - testCheckLogDrainExists(testTeam(), "vercel_log_drain.maximal"), + testCheckLogDrainExists(testClient(t), testTeam(t), "vercel_log_drain.maximal"), resource.TestCheckResourceAttr("vercel_log_drain.maximal", "delivery_format", "json"), resource.TestCheckResourceAttr("vercel_log_drain.maximal", "environments.#", "2"), resource.TestCheckResourceAttr("vercel_log_drain.maximal", "environments.0", "preview"), diff --git a/vercel/resource_microfrontend_group_test.go b/vercel/resource_microfrontend_group_test.go index 55ebecd2..7c8df691 100644 --- a/vercel/resource_microfrontend_group_test.go +++ b/vercel/resource_microfrontend_group_test.go @@ -8,9 +8,10 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" + "github.com/vercel/terraform-provider-vercel/v2/client" ) -func testCheckMicrofrontendGroupExists(teamID, n string) resource.TestCheckFunc { +func testCheckMicrofrontendGroupExists(testClient *client.Client, teamID, n string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -21,12 +22,12 @@ func testCheckMicrofrontendGroupExists(teamID, n string) resource.TestCheckFunc return fmt.Errorf("no ID is set") } - _, err := testClient().GetMicrofrontendGroup(context.TODO(), rs.Primary.ID, teamID) + _, err := testClient.GetMicrofrontendGroup(context.TODO(), rs.Primary.ID, teamID) return err } } -func testCheckMicrofrontendGroupDeleted(n, teamID string) resource.TestCheckFunc { +func testCheckMicrofrontendGroupDeleted(testClient *client.Client, n, teamID string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -37,7 +38,7 @@ func testCheckMicrofrontendGroupDeleted(n, teamID string) resource.TestCheckFunc return fmt.Errorf("no ID is set") } - _, err := testClient().GetMicrofrontendGroup(context.TODO(), rs.Primary.ID, teamID) + _, err := testClient.GetMicrofrontendGroup(context.TODO(), rs.Primary.ID, teamID) if err == nil { return fmt.Errorf("expected not_found error, but got no error") } @@ -52,9 +53,8 @@ func testCheckMicrofrontendGroupDeleted(n, teamID string) resource.TestCheckFunc func TestAcc_MicrofrontendGroupResource(t *testing.T) { name := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, - CheckDestroy: testCheckMicrofrontendGroupDeleted("vercel_microfrontend_group.test", testTeam()), + CheckDestroy: testCheckMicrofrontendGroupDeleted(testClient(t), "vercel_microfrontend_group.test", testTeam(t)), Steps: []resource.TestStep{ { Config: fmt.Sprintf(` @@ -78,9 +78,9 @@ func TestAcc_MicrofrontendGroupResource(t *testing.T) { microfrontend_group_id = vercel_microfrontend_group.test.id %[2]s } - `, name, teamIDConfig()), + `, name, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( - testCheckMicrofrontendGroupExists(testTeam(), "vercel_microfrontend_group.test"), + testCheckMicrofrontendGroupExists(testClient(t), testTeam(t), "vercel_microfrontend_group.test"), resource.TestCheckResourceAttr("vercel_microfrontend_group.test", "name", "test-acc-microfrontend-group-"+name), resource.TestCheckResourceAttrSet("vercel_microfrontend_group.test", "id"), resource.TestCheckResourceAttrSet("vercel_microfrontend_group.test", "default_app.project_id"), diff --git a/vercel/resource_project_deployment_retention_test.go b/vercel/resource_project_deployment_retention_test.go index e1ff42cb..1c786c2b 100644 --- a/vercel/resource_project_deployment_retention_test.go +++ b/vercel/resource_project_deployment_retention_test.go @@ -8,9 +8,10 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" + "github.com/vercel/terraform-provider-vercel/v2/client" ) -func testAccProjectDeploymentRetentionExists(n, teamID string) resource.TestCheckFunc { +func testAccProjectDeploymentRetentionExists(testClient *client.Client, n, teamID string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -21,7 +22,7 @@ func testAccProjectDeploymentRetentionExists(n, teamID string) resource.TestChec return fmt.Errorf("no ID is set") } - _, err := testClient().GetDeploymentRetention(context.TODO(), rs.Primary.Attributes["project_id"], teamID) + _, err := testClient.GetDeploymentRetention(context.TODO(), rs.Primary.Attributes["project_id"], teamID) return err } } @@ -29,16 +30,15 @@ func testAccProjectDeploymentRetentionExists(n, teamID string) resource.TestChec func TestAcc_ProjectDeploymentRetention(t *testing.T) { nameSuffix := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, CheckDestroy: resource.ComposeAggregateTestCheckFunc( - testAccProjectDestroy("vercel_project.example", testTeam()), + testAccProjectDestroy(testClient(t), "vercel_project.example", testTeam(t)), ), Steps: []resource.TestStep{ { - Config: testAccProjectDeploymentRetentionsConfigWithMissingFields(nameSuffix), + Config: testAccProjectDeploymentRetentionsConfigWithMissingFields(nameSuffix, testGithubRepo(t), teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( - testAccProjectDeploymentRetentionExists("vercel_project_deployment_retention.example", testTeam()), + testAccProjectDeploymentRetentionExists(testClient(t), "vercel_project_deployment_retention.example", testTeam(t)), resource.TestCheckResourceAttr("vercel_project_deployment_retention.example", "expiration_preview", "unlimited"), resource.TestCheckResourceAttr("vercel_project_deployment_retention.example", "expiration_production", "unlimited"), resource.TestCheckResourceAttr("vercel_project_deployment_retention.example", "expiration_canceled", "unlimited"), @@ -46,9 +46,9 @@ func TestAcc_ProjectDeploymentRetention(t *testing.T) { ), }, { - Config: testAccProjectDeploymentRetentionsConfig(nameSuffix), + Config: testAccProjectDeploymentRetentionsConfig(nameSuffix, testGithubRepo(t), teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( - testAccProjectDeploymentRetentionExists("vercel_project_deployment_retention.example", testTeam()), + testAccProjectDeploymentRetentionExists(testClient(t), "vercel_project_deployment_retention.example", testTeam(t)), resource.TestCheckResourceAttr("vercel_project_deployment_retention.example", "expiration_preview", "1m"), resource.TestCheckResourceAttr("vercel_project_deployment_retention.example", "expiration_production", "2m"), resource.TestCheckResourceAttr("vercel_project_deployment_retention.example", "expiration_canceled", "3m"), @@ -56,9 +56,9 @@ func TestAcc_ProjectDeploymentRetention(t *testing.T) { ), }, { - Config: testAccProjectDeploymentRetentionsConfigUpdated(nameSuffix), + Config: testAccProjectDeploymentRetentionsConfigUpdated(nameSuffix, testGithubRepo(t), teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( - testAccProjectDeploymentRetentionExists("vercel_project_deployment_retention.example", testTeam()), + testAccProjectDeploymentRetentionExists(testClient(t), "vercel_project_deployment_retention.example", testTeam(t)), resource.TestCheckResourceAttr("vercel_project_deployment_retention.example", "expiration_preview", "2m"), resource.TestCheckResourceAttr("vercel_project_deployment_retention.example", "expiration_production", "3m"), resource.TestCheckResourceAttr("vercel_project_deployment_retention.example", "expiration_canceled", "6m"), @@ -66,9 +66,9 @@ func TestAcc_ProjectDeploymentRetention(t *testing.T) { ), }, { - Config: testAccProjectDeploymentRetentionsConfigAllUnlimited(nameSuffix), + Config: testAccProjectDeploymentRetentionsConfigAllUnlimited(nameSuffix, testGithubRepo(t), teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( - testAccProjectDeploymentRetentionExists("vercel_project_deployment_retention.example", testTeam()), + testAccProjectDeploymentRetentionExists(testClient(t), "vercel_project_deployment_retention.example", testTeam(t)), resource.TestCheckResourceAttr("vercel_project_deployment_retention.example", "expiration_preview", "unlimited"), resource.TestCheckResourceAttr("vercel_project_deployment_retention.example", "expiration_production", "unlimited"), resource.TestCheckResourceAttr("vercel_project_deployment_retention.example", "expiration_canceled", "unlimited"), @@ -79,7 +79,7 @@ func TestAcc_ProjectDeploymentRetention(t *testing.T) { }) } -func testAccProjectDeploymentRetentionsConfig(projectName string) string { +func testAccProjectDeploymentRetentionsConfig(projectName string, githubRepo string, teamIDConfig string) string { return fmt.Sprintf(` resource "vercel_project" "example" { name = "test-acc-example-project-%[1]s" @@ -99,10 +99,10 @@ resource "vercel_project_deployment_retention" "example" { expiration_canceled = "3m" expiration_errored = "1y" } -`, projectName, testGithubRepo(), teamIDConfig()) +`, projectName, githubRepo, teamIDConfig) } -func testAccProjectDeploymentRetentionsConfigUpdated(projectName string) string { +func testAccProjectDeploymentRetentionsConfigUpdated(projectName string, githubRepo string, teamIDConfig string) string { return fmt.Sprintf(` resource "vercel_project" "example" { name = "test-acc-example-project-%[1]s" @@ -122,10 +122,10 @@ resource "vercel_project_deployment_retention" "example" { expiration_canceled = "6m" expiration_errored = "1m" } -`, projectName, testGithubRepo(), teamIDConfig()) +`, projectName, githubRepo, teamIDConfig) } -func testAccProjectDeploymentRetentionsConfigAllUnlimited(projectName string) string { +func testAccProjectDeploymentRetentionsConfigAllUnlimited(projectName string, githubRepo string, teamIDConfig string) string { return fmt.Sprintf(` resource "vercel_project" "example" { name = "test-acc-example-project-%[1]s" @@ -145,10 +145,10 @@ resource "vercel_project_deployment_retention" "example" { expiration_canceled = "unlimited" expiration_errored = "unlimited" } -`, projectName, testGithubRepo(), teamIDConfig()) +`, projectName, githubRepo, teamIDConfig) } -func testAccProjectDeploymentRetentionsConfigWithMissingFields(projectName string) string { +func testAccProjectDeploymentRetentionsConfigWithMissingFields(projectName string, githubRepo string, teamIDConfig string) string { return fmt.Sprintf(` resource "vercel_project" "example" { name = "test-acc-example-project-%[1]s" @@ -164,5 +164,5 @@ resource "vercel_project_deployment_retention" "example" { project_id = vercel_project.example.id %[3]s } -`, projectName, testGithubRepo(), teamIDConfig()) +`, projectName, githubRepo, teamIDConfig) } diff --git a/vercel/resource_project_domain_test.go b/vercel/resource_project_domain_test.go index 090f7167..1f5dc882 100644 --- a/vercel/resource_project_domain_test.go +++ b/vercel/resource_project_domain_test.go @@ -15,44 +15,43 @@ import ( func TestAcc_ProjectDomain(t *testing.T) { testTeamID := resource.TestCheckNoResourceAttr("vercel_project.test", "team_id") - if testTeam() != "" { - testTeamID = resource.TestCheckResourceAttr("vercel_project.test", "team_id", testTeam()) + if testTeam(t) != "" { + testTeamID = resource.TestCheckResourceAttr("vercel_project.test", "team_id", testTeam(t)) } projectSuffix := acctest.RandString(16) domain := acctest.RandString(30) + ".vercel.app" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, CheckDestroy: noopDestroyCheck, Steps: []resource.TestStep{ // Check error adding production domain { - Config: testAccProjectDomainWithProductionGitBranch(projectSuffix, "1"+domain, teamIDConfig()), + Config: testAccProjectDomainWithProductionGitBranch(projectSuffix, "1"+domain, teamIDConfig(t), testGithubRepo(t)), ExpectError: regexp.MustCompile( strings.ReplaceAll("the git_branch specified is the production branch. If you want to use this domain as a production domain, please omit the git_branch field.", " ", `\s*`), ), }, // Create and Read testing { - Config: testAccProjectDomainConfig(projectSuffix, "2"+domain, teamIDConfig()), + Config: testAccProjectDomainConfig(projectSuffix, "2"+domain, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( - testAccProjectDomainExists("vercel_project.test", testTeam(), "2"+domain), + testAccProjectDomainExists(testClient(t), "vercel_project.test", testTeam(t), "2"+domain), testTeamID, resource.TestCheckResourceAttr("vercel_project_domain.test", "domain", "2"+domain), ), }, // Update testing { - Config: testAccProjectDomainConfigUpdated(projectSuffix, "2"+domain, teamIDConfig()), + Config: testAccProjectDomainConfigUpdated(projectSuffix, "2"+domain, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("vercel_project_domain.test", "redirect"), ), }, // Redirect Update testing { - Config: testAccProjectDomainConfigUpdated2(projectSuffix, "2"+domain, teamIDConfig()), + Config: testAccProjectDomainConfigUpdated2(projectSuffix, "2"+domain, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("vercel_project_domain.test", "redirect"), resource.TestCheckResourceAttr("vercel_project_domain.test", "redirect_status_code", "307"), @@ -60,8 +59,8 @@ func TestAcc_ProjectDomain(t *testing.T) { }, // Delete testing { - Config: testAccProjectDomainConfigDeleted(projectSuffix, teamIDConfig()), - Check: testAccProjectDomainDestroy("vercel_project.test", testTeam(), domain), + Config: testAccProjectDomainConfigDeleted(projectSuffix, teamIDConfig(t)), + Check: testAccProjectDomainDestroy(testClient(t), "vercel_project.test", testTeam(t), domain), }, }, }) @@ -70,19 +69,18 @@ func TestAcc_ProjectDomain(t *testing.T) { func TestAcc_ProjectDomainCustomEnvironment(t *testing.T) { randomSuffix := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, CheckDestroy: noopDestroyCheck, Steps: []resource.TestStep{ // Ensure we can't have both git_branch and custom_environment_id { - Config: testAccProjectDomainConfigWithCustomEnvironmentAndGitBranch(randomSuffix), + Config: testAccProjectDomainConfigWithCustomEnvironmentAndGitBranch(randomSuffix, teamIDConfig(t), testGithubRepo(t)), ExpectError: regexp.MustCompile( strings.ReplaceAll("Attribute \"git_branch\" cannot be specified when \"custom_environment_id\" is specified", " ", `\s*`), ), }, { - Config: testAccProjectDomainConfigWithCustomEnvironment(randomSuffix), + Config: testAccProjectDomainConfigWithCustomEnvironment(randomSuffix, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("vercel_project_domain.test", "custom_environment_id"), ), @@ -91,7 +89,7 @@ func TestAcc_ProjectDomainCustomEnvironment(t *testing.T) { }) } -func testAccProjectDomainExists(n, teamID, domain string) resource.TestCheckFunc { +func testAccProjectDomainExists(testClient *client.Client, n, teamID, domain string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -102,12 +100,12 @@ func testAccProjectDomainExists(n, teamID, domain string) resource.TestCheckFunc return fmt.Errorf("no projectID is set") } - _, err := testClient().GetProjectDomain(context.TODO(), rs.Primary.ID, domain, teamID) + _, err := testClient.GetProjectDomain(context.TODO(), rs.Primary.ID, domain, teamID) return err } } -func testAccProjectDomainDestroy(n, teamID, domain string) resource.TestCheckFunc { +func testAccProjectDomainDestroy(testClient *client.Client, n, teamID, domain string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -118,7 +116,7 @@ func testAccProjectDomainDestroy(n, teamID, domain string) resource.TestCheckFun return fmt.Errorf("no projectID is set") } - _, err := testClient().GetProjectDomain(context.TODO(), rs.Primary.ID, domain, teamID) + _, err := testClient.GetProjectDomain(context.TODO(), rs.Primary.ID, domain, teamID) if err == nil { return fmt.Errorf("expected not_found error, but got no error") } @@ -129,7 +127,7 @@ func testAccProjectDomainDestroy(n, teamID, domain string) resource.TestCheckFun } } -func testAccProjectDomainWithProductionGitBranch(projectSuffix, domain, teamIDConfig string) string { +func testAccProjectDomainWithProductionGitBranch(projectSuffix, domain, teamIDConfig string, githubRepo string) string { return fmt.Sprintf(` resource "vercel_project" "test" { name = "test-acc-domain-%[1]s" @@ -146,7 +144,7 @@ resource "vercel_project_domain" "test" { git_branch = "main" project_id = vercel_project.test.id } -`, projectSuffix, teamIDConfig, domain, testGithubRepo()) +`, projectSuffix, teamIDConfig, domain, githubRepo) } func testAccProjectDomainConfig(projectSuffix, domain, extra string) string { @@ -226,7 +224,7 @@ resource "vercel_project" "test" { `, projectSuffix, extra) } -func testAccProjectDomainConfigWithCustomEnvironment(randomSuffix string) string { +func testAccProjectDomainConfigWithCustomEnvironment(randomSuffix string, teamIDConfig string) string { return fmt.Sprintf(` resource "vercel_project" "test" { name = "test-acc-domain-%[1]s" @@ -245,10 +243,10 @@ resource "vercel_project_domain" "test" { custom_environment_id = vercel_custom_environment.test.id %[2]s } -`, randomSuffix, teamIDConfig()) +`, randomSuffix, teamIDConfig) } -func testAccProjectDomainConfigWithCustomEnvironmentAndGitBranch(randomSuffix string) string { +func testAccProjectDomainConfigWithCustomEnvironmentAndGitBranch(randomSuffix string, teamIDConfig string, githubRepo string) string { return fmt.Sprintf(` resource "vercel_project" "test" { name = "test-acc-domain-%[1]s" @@ -272,5 +270,5 @@ resource "vercel_project_domain" "test" { git_branch = "staging" %[2]s } -`, randomSuffix, teamIDConfig(), testGithubRepo()) +`, randomSuffix, teamIDConfig, githubRepo) } diff --git a/vercel/resource_project_environment_variable_test.go b/vercel/resource_project_environment_variable_test.go index 48661c4a..cac31fbe 100644 --- a/vercel/resource_project_environment_variable_test.go +++ b/vercel/resource_project_environment_variable_test.go @@ -8,9 +8,10 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" + "github.com/vercel/terraform-provider-vercel/v2/client" ) -func testAccProjectEnvironmentVariableExists(n, teamID string) resource.TestCheckFunc { +func testAccProjectEnvironmentVariableExists(testClient *client.Client, n, teamID string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -21,12 +22,12 @@ func testAccProjectEnvironmentVariableExists(n, teamID string) resource.TestChec return fmt.Errorf("no ID is set") } - _, err := testClient().GetEnvironmentVariable(context.TODO(), rs.Primary.Attributes["project_id"], teamID, rs.Primary.ID) + _, err := testClient.GetEnvironmentVariable(context.TODO(), rs.Primary.Attributes["project_id"], teamID, rs.Primary.ID) return err } } -func testAccProjectEnvironmentVariableDoNotExist(n, teamID string) resource.TestCheckFunc { +func testAccProjectEnvironmentVariableDoNotExist(testClient *client.Client, n, teamID string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -37,7 +38,7 @@ func testAccProjectEnvironmentVariableDoNotExist(n, teamID string) resource.Test return fmt.Errorf("no ID is set") } - envs, err := testClient().GetEnvironmentVariables(context.TODO(), rs.Primary.ID, teamID) + envs, err := testClient.GetEnvironmentVariables(context.TODO(), rs.Primary.ID, teamID) if err != nil { return fmt.Errorf("could not fetch the project: %w", err) } @@ -53,34 +54,33 @@ func testAccProjectEnvironmentVariableDoNotExist(n, teamID string) resource.Test func TestAcc_ProjectEnvironmentVariable(t *testing.T) { nameSuffix := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, CheckDestroy: resource.ComposeAggregateTestCheckFunc( - testAccProjectDestroy("vercel_project.example", testTeam()), + testAccProjectDestroy(testClient(t), "vercel_project.example", testTeam(t)), ), Steps: []resource.TestStep{ { - Config: testAccProjectEnvironmentVariableConfig(nameSuffix), + Config: testAccProjectEnvironmentVariableConfig(nameSuffix, testGithubRepo(t), teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( - testAccProjectEnvironmentVariableExists("vercel_project_environment_variable.example", testTeam()), + testAccProjectEnvironmentVariableExists(testClient(t), "vercel_project_environment_variable.example", testTeam(t)), resource.TestCheckResourceAttr("vercel_project_environment_variable.example", "key", "foo"), resource.TestCheckResourceAttr("vercel_project_environment_variable.example", "value", "bar"), resource.TestCheckTypeSetElemAttr("vercel_project_environment_variable.example", "target.*", "production"), resource.TestCheckResourceAttr("vercel_project_environment_variable.example", "comment", "this is with a comment"), - testAccProjectEnvironmentVariableExists("vercel_project_environment_variable.example_git_branch", testTeam()), + testAccProjectEnvironmentVariableExists(testClient(t), "vercel_project_environment_variable.example_git_branch", testTeam(t)), resource.TestCheckResourceAttr("vercel_project_environment_variable.example_git_branch", "key", "foo"), resource.TestCheckResourceAttr("vercel_project_environment_variable.example_git_branch", "value", "bar-staging"), resource.TestCheckTypeSetElemAttr("vercel_project_environment_variable.example_git_branch", "target.*", "preview"), resource.TestCheckResourceAttr("vercel_project_environment_variable.example_git_branch", "git_branch", "production"), - testAccProjectEnvironmentVariableExists("vercel_project_environment_variable.example_sensitive", testTeam()), + testAccProjectEnvironmentVariableExists(testClient(t), "vercel_project_environment_variable.example_sensitive", testTeam(t)), resource.TestCheckResourceAttr("vercel_project_environment_variable.example_sensitive", "key", "foo_sensitive"), resource.TestCheckResourceAttr("vercel_project_environment_variable.example_sensitive", "value", "bar-sensitive"), resource.TestCheckTypeSetElemAttr("vercel_project_environment_variable.example_sensitive", "target.*", "production"), resource.TestCheckResourceAttr("vercel_project_environment_variable.example_sensitive", "sensitive", "true"), - testAccProjectEnvironmentVariableExists("vercel_project_environment_variable.example_not_sensitive", testTeam()), + testAccProjectEnvironmentVariableExists(testClient(t), "vercel_project_environment_variable.example_not_sensitive", testTeam(t)), resource.TestCheckResourceAttr("vercel_project_environment_variable.example_not_sensitive", "key", "foo_not_sensitive"), resource.TestCheckResourceAttr("vercel_project_environment_variable.example_not_sensitive", "value", "bar-not-sensitive"), resource.TestCheckTypeSetElemAttr("vercel_project_environment_variable.example_not_sensitive", "target.*", "production"), @@ -88,22 +88,22 @@ func TestAcc_ProjectEnvironmentVariable(t *testing.T) { ), }, { - Config: testAccProjectEnvironmentVariableConfigUpdated(nameSuffix), + Config: testAccProjectEnvironmentVariableConfigUpdated(nameSuffix, testGithubRepo(t), teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( - testAccProjectEnvironmentVariableExists("vercel_project_environment_variable.example", testTeam()), + testAccProjectEnvironmentVariableExists(testClient(t), "vercel_project_environment_variable.example", testTeam(t)), resource.TestCheckResourceAttr("vercel_project_environment_variable.example", "key", "foo"), resource.TestCheckResourceAttr("vercel_project_environment_variable.example", "value", "bar-new"), resource.TestCheckTypeSetElemAttr("vercel_project_environment_variable.example", "target.*", "production"), resource.TestCheckTypeSetElemAttr("vercel_project_environment_variable.example", "target.*", "preview"), resource.TestCheckResourceAttr("vercel_project_environment_variable.example", "comment", "this is an updated comment"), - testAccProjectEnvironmentVariableExists("vercel_project_environment_variable.example_git_branch", testTeam()), + testAccProjectEnvironmentVariableExists(testClient(t), "vercel_project_environment_variable.example_git_branch", testTeam(t)), resource.TestCheckResourceAttr("vercel_project_environment_variable.example_git_branch", "key", "foo"), resource.TestCheckResourceAttr("vercel_project_environment_variable.example_git_branch", "value", "bar-staging"), resource.TestCheckTypeSetElemAttr("vercel_project_environment_variable.example_git_branch", "target.*", "preview"), resource.TestCheckResourceAttr("vercel_project_environment_variable.example_git_branch", "git_branch", "test"), - testAccProjectEnvironmentVariableExists("vercel_project_environment_variable.example_sensitive", testTeam()), + testAccProjectEnvironmentVariableExists(testClient(t), "vercel_project_environment_variable.example_sensitive", testTeam(t)), resource.TestCheckResourceAttr("vercel_project_environment_variable.example_sensitive", "key", "foo_sensitive"), resource.TestCheckResourceAttr("vercel_project_environment_variable.example_sensitive", "value", "bar-sensitive-updated"), resource.TestCheckTypeSetElemAttr("vercel_project_environment_variable.example_sensitive", "target.*", "production"), @@ -123,9 +123,9 @@ func TestAcc_ProjectEnvironmentVariable(t *testing.T) { ImportStateIdFunc: getProjectEnvironmentVariableImportID("vercel_project_environment_variable.example_git_branch"), }, { - Config: testAccProjectEnvironmentVariableConfigDeleted(nameSuffix), + Config: testAccProjectEnvironmentVariableConfigDeleted(nameSuffix, testGithubRepo(t), teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( - testAccProjectEnvironmentVariableDoNotExist("vercel_project.example", testTeam()), + testAccProjectEnvironmentVariableDoNotExist(testClient(t), "vercel_project.example", testTeam(t)), ), }, }, @@ -150,7 +150,7 @@ func getProjectEnvironmentVariableImportID(n string) resource.ImportStateIdFunc } } -func testAccProjectEnvironmentVariableConfig(projectName string) string { +func testAccProjectEnvironmentVariableConfig(projectName string, githubRepo string, teamIDConfig string) string { return fmt.Sprintf(` resource "vercel_project" "example" { name = "test-acc-example-project-%[1]s" @@ -197,10 +197,10 @@ resource "vercel_project_environment_variable" "example_not_sensitive" { target = ["production"] sensitive = false } -`, projectName, testGithubRepo(), teamIDConfig()) +`, projectName, githubRepo, teamIDConfig) } -func testAccProjectEnvironmentVariableConfigUpdated(projectName string) string { +func testAccProjectEnvironmentVariableConfigUpdated(projectName string, githubRepo string, teamIDConfig string) string { return fmt.Sprintf(` resource "vercel_project" "example" { name = "test-acc-example-project-%[1]s" @@ -238,10 +238,10 @@ resource "vercel_project_environment_variable" "example_sensitive" { target = ["production"] sensitive = true } -`, projectName, testGithubRepo(), teamIDConfig()) +`, projectName, githubRepo, teamIDConfig) } -func testAccProjectEnvironmentVariableConfigDeleted(projectName string) string { +func testAccProjectEnvironmentVariableConfigDeleted(projectName string, githubRepo string, teamIDConfig string) string { return fmt.Sprintf(` resource "vercel_project" "example" { name = "test-acc-example-project-%[1]s" @@ -252,5 +252,5 @@ resource "vercel_project" "example" { repo = "%[2]s" } } -`, projectName, testGithubRepo(), teamIDConfig()) +`, projectName, githubRepo, teamIDConfig) } diff --git a/vercel/resource_project_environment_variables_test.go b/vercel/resource_project_environment_variables_test.go index 70d18d1f..8dc0a2a9 100644 --- a/vercel/resource_project_environment_variables_test.go +++ b/vercel/resource_project_environment_variables_test.go @@ -13,14 +13,13 @@ func TestAcc_ProjectEnvironmentVariables(t *testing.T) { resourceName := "vercel_project_environment_variables.test" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, CheckDestroy: resource.ComposeAggregateTestCheckFunc( - testAccProjectDestroy("vercel_project.test", testTeam()), + testAccProjectDestroy(testClient(t), "vercel_project.test", testTeam(t)), ), Steps: []resource.TestStep{ { - Config: testAccProjectEnvironmentVariablesConfig(projectName), + Config: testAccProjectEnvironmentVariablesConfig(projectName, teamIDConfig(t), testGithubRepo(t)), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(resourceName, "variables.#", "2"), resource.TestCheckTypeSetElemNestedAttrs(resourceName, "variables.*", map[string]string{ @@ -37,7 +36,7 @@ func TestAcc_ProjectEnvironmentVariables(t *testing.T) { ), }, { - Config: testAccProjectEnvironmentVariablesConfigUpdated(projectName), + Config: testAccProjectEnvironmentVariablesConfigUpdated(projectName, teamIDConfig(t), testGithubRepo(t)), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(resourceName, "variables.#", "4"), resource.TestCheckTypeSetElemNestedAttrs(resourceName, "variables.*", map[string]string{ @@ -66,7 +65,7 @@ func TestAcc_ProjectEnvironmentVariables(t *testing.T) { }) } -func testAccProjectEnvironmentVariablesConfig(projectName string) string { +func testAccProjectEnvironmentVariablesConfig(projectName string, teamIDConfig string, githubRepo string) string { return fmt.Sprintf(` resource "vercel_project" "test" { name = "%s" @@ -95,10 +94,10 @@ resource "vercel_project_environment_variables" "test" { } ] } -`, projectName, teamIDConfig(), testGithubRepo()) +`, projectName, teamIDConfig, githubRepo) } -func testAccProjectEnvironmentVariablesConfigUpdated(projectName string) string { +func testAccProjectEnvironmentVariablesConfigUpdated(projectName string, teamIDConfig string, githubRepo string) string { return fmt.Sprintf(` resource "vercel_project" "test" { name = "%s" @@ -137,5 +136,5 @@ resource "vercel_project_environment_variables" "test" { } ] } -`, projectName, teamIDConfig(), testGithubRepo()) +`, projectName, teamIDConfig, githubRepo) } diff --git a/vercel/resource_project_members_test.go b/vercel/resource_project_members_test.go index d54d6b9e..f9f8c8ed 100644 --- a/vercel/resource_project_members_test.go +++ b/vercel/resource_project_members_test.go @@ -11,26 +11,25 @@ import ( func TestAcc_ProjectMembers(t *testing.T) { projectSuffix := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, - CheckDestroy: testAccProjectDestroy("vercel_project.test", testTeam()), + CheckDestroy: testAccProjectDestroy(testClient(t), "vercel_project.test", testTeam(t)), Steps: []resource.TestStep{ { - Config: testAccProjectMembersConfig(projectSuffix), + Config: testAccProjectMembersConfig(projectSuffix, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("vercel_project_members.test", "project_id"), resource.TestCheckResourceAttr("vercel_project_members.test", "members.#", "1"), ), }, { - Config: testAccProjectMembersConfigUpdated(projectSuffix), + Config: testAccProjectMembersConfigUpdated(projectSuffix, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("vercel_project_members.test", "project_id"), resource.TestCheckResourceAttr("vercel_project_members.test", "members.#", "2"), ), }, { - Config: testAccProjectMembersConfigUpdatedAgain(projectSuffix), + Config: testAccProjectMembersConfigUpdatedAgain(projectSuffix, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("vercel_project_members.test", "project_id"), resource.TestCheckResourceAttr("vercel_project_members.test", "members.#", "1"), @@ -40,7 +39,7 @@ func TestAcc_ProjectMembers(t *testing.T) { }) } -func testAccProjectMembersConfig(projectSuffix string) string { +func testAccProjectMembersConfig(projectSuffix string, teamIDConfig string) string { return fmt.Sprintf(` resource "vercel_project" "test" { name = "test-acc-project-members-%[1]s" @@ -56,10 +55,10 @@ resource "vercel_project_members" "test" { role = "PROJECT_VIEWER" }] } -`, projectSuffix, teamIDConfig()) +`, projectSuffix, teamIDConfig) } -func testAccProjectMembersConfigUpdated(projectSuffix string) string { +func testAccProjectMembersConfigUpdated(projectSuffix string, teamIDConfig string) string { return fmt.Sprintf(` resource "vercel_project" "test" { name = "test-acc-project-members-%[1]s" @@ -80,10 +79,10 @@ resource "vercel_project_members" "test" { } ] } -`, projectSuffix, teamIDConfig()) +`, projectSuffix, teamIDConfig) } -func testAccProjectMembersConfigUpdatedAgain(projectSuffix string) string { +func testAccProjectMembersConfigUpdatedAgain(projectSuffix string, teamIDConfig string) string { return fmt.Sprintf(` resource "vercel_project" "test" { name = "test-acc-project-members-%[1]s" @@ -101,5 +100,5 @@ resource "vercel_project_members" "test" { } ] } -`, projectSuffix, teamIDConfig()) +`, projectSuffix, teamIDConfig) } diff --git a/vercel/resource_project_test.go b/vercel/resource_project_test.go index bc6d07d1..512f1937 100644 --- a/vercel/resource_project_test.go +++ b/vercel/resource_project_test.go @@ -19,15 +19,14 @@ import ( func TestAcc_Project(t *testing.T) { testTeamID := resource.TestCheckNoResourceAttr("vercel_project.test", "team_id") - if testTeam() != "" { - testTeamID = resource.TestCheckResourceAttr("vercel_project.test", "team_id", testTeam()) + if testTeam(t) != "" { + testTeamID = resource.TestCheckResourceAttr("vercel_project.test", "team_id", testTeam(t)) } projectSuffix := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, - CheckDestroy: testAccProjectDestroy("vercel_project.test", testTeam()), + CheckDestroy: testAccProjectDestroy(testClient(t), "vercel_project.test", testTeam(t)), Steps: []resource.TestStep{ // Ensure we get nice framework / serverless_function_region errors { @@ -50,9 +49,9 @@ func TestAcc_Project(t *testing.T) { }, // Create and Read testing { - Config: testAccProjectConfig(projectSuffix, teamIDConfig()), + Config: testAccProjectConfig(projectSuffix, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( - testAccProjectExists("vercel_project.test", testTeam()), + testAccProjectExists(testClient(t), "vercel_project.test", testTeam(t)), testTeamID, resource.TestCheckResourceAttr("vercel_project.test", "name", fmt.Sprintf("test-acc-project-%s", projectSuffix)), resource.TestCheckResourceAttr("vercel_project.test", "build_command", "npm run build"), @@ -89,7 +88,7 @@ func TestAcc_Project(t *testing.T) { }, // Update testing { - Config: testAccProjectConfigUpdated(projectSuffix, teamIDConfig()), + Config: testAccProjectConfigUpdated(projectSuffix, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("vercel_project.test", "name", fmt.Sprintf("test-acc-two-%s", projectSuffix)), resource.TestCheckNoResourceAttr("vercel_project.test", "build_command"), @@ -108,9 +107,9 @@ func TestAcc_ProjectFluidCompute(t *testing.T) { projectSuffix := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, - CheckDestroy: testAccProjectDestroy("vercel_project.test", testTeam()), + CheckDestroy: testAccProjectDestroy(testClient(t), "vercel_project.test", testTeam(t)), Steps: []resource.TestStep{ { // check we get a sensible error if fluid + invalid CPU combination. @@ -123,7 +122,7 @@ func TestAcc_ProjectFluidCompute(t *testing.T) { function_default_cpu_type = "standard_legacy" } } - `, projectSuffix, teamIDConfig()), + `, projectSuffix, teamIDConfig(t)), ExpectError: regexp.MustCompile(strings.ReplaceAll("\"standard_legacy\" is not a valid memory type for Fluid compute", " ", `\s*`)), }, { @@ -137,7 +136,7 @@ func TestAcc_ProjectFluidCompute(t *testing.T) { fluid = true } } - `, projectSuffix, teamIDConfig()), + `, projectSuffix, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("vercel_project.test", "name", fmt.Sprintf("test-acc-fluid-%s", projectSuffix)), resource.TestCheckResourceAttr("vercel_project.test", "resource_config.fluid", "true"), @@ -154,7 +153,7 @@ func TestAcc_ProjectFluidCompute(t *testing.T) { fluid = false } } - `, projectSuffix, teamIDConfig()), + `, projectSuffix, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("vercel_project.test", "name", fmt.Sprintf("test-acc-fluid-%s", projectSuffix)), resource.TestCheckResourceAttr("vercel_project.test", "resource_config.fluid", "false"), @@ -167,7 +166,7 @@ func TestAcc_ProjectFluidCompute(t *testing.T) { name = "test-acc-fluid-disabled-%[1]s" %[2]s } - `, projectSuffix, teamIDConfig()), + `, projectSuffix, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("vercel_project.test", "name", fmt.Sprintf("test-acc-fluid-disabled-%s", projectSuffix)), resource.TestCheckResourceAttr("vercel_project.test", "resource_config.fluid", "false"), @@ -180,20 +179,19 @@ func TestAcc_ProjectFluidCompute(t *testing.T) { func TestAcc_ProjectAddingEnvAfterInitialCreation(t *testing.T) { projectSuffix := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, - CheckDestroy: testAccProjectDestroy("vercel_project.test", testTeam()), + CheckDestroy: testAccProjectDestroy(testClient(t), "vercel_project.test", testTeam(t)), Steps: []resource.TestStep{ { - Config: testAccProjectConfigWithoutEnv(projectSuffix, teamIDConfig()), + Config: testAccProjectConfigWithoutEnv(projectSuffix, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( - testAccProjectExists("vercel_project.test", testTeam()), + testAccProjectExists(testClient(t), "vercel_project.test", testTeam(t)), ), }, { - Config: testAccProjectConfigUpdated(projectSuffix, teamIDConfig()), + Config: testAccProjectConfigUpdated(projectSuffix, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( - testAccProjectExists("vercel_project.test", testTeam()), + testAccProjectExists(testClient(t), "vercel_project.test", testTeam(t)), ), }, }, @@ -203,14 +201,13 @@ func TestAcc_ProjectAddingEnvAfterInitialCreation(t *testing.T) { func TestAcc_ProjectUpdateResourceConfig(t *testing.T) { projectSuffix := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, - CheckDestroy: testAccProjectDestroy("vercel_project.test", testTeam()), + CheckDestroy: testAccProjectDestroy(testClient(t), "vercel_project.test", testTeam(t)), Steps: []resource.TestStep{ { - Config: testAccProjectConfigBase(projectSuffix, teamIDConfig()), + Config: testAccProjectConfigBase(projectSuffix, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( - testAccProjectExists("vercel_project.test", testTeam()), + testAccProjectExists(testClient(t), "vercel_project.test", testTeam(t)), ), ConfigStateChecks: []statecheck.StateCheck{ statecheck.ExpectKnownValue( @@ -226,9 +223,9 @@ func TestAcc_ProjectUpdateResourceConfig(t *testing.T) { }, }, { - Config: testAccProjectConfigBase(projectSuffix, teamIDConfig()), + Config: testAccProjectConfigBase(projectSuffix, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( - testAccProjectExists("vercel_project.test", testTeam()), + testAccProjectExists(testClient(t), "vercel_project.test", testTeam(t)), ), ConfigPlanChecks: resource.ConfigPlanChecks{ PreApply: []plancheck.PlanCheck{ @@ -237,9 +234,9 @@ func TestAcc_ProjectUpdateResourceConfig(t *testing.T) { }, }, { - Config: testAccProjectConfigWithResourceConfig(projectSuffix, teamIDConfig()), + Config: testAccProjectConfigWithResourceConfig(projectSuffix, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( - testAccProjectExists("vercel_project.test", testTeam()), + testAccProjectExists(testClient(t), "vercel_project.test", testTeam(t)), ), ConfigStateChecks: []statecheck.StateCheck{ statecheck.ExpectKnownValue( @@ -255,9 +252,9 @@ func TestAcc_ProjectUpdateResourceConfig(t *testing.T) { }, }, { - Config: testAccProjectConfigWithResourceConfig(projectSuffix, teamIDConfig()), + Config: testAccProjectConfigWithResourceConfig(projectSuffix, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( - testAccProjectExists("vercel_project.test", testTeam()), + testAccProjectExists(testClient(t), "vercel_project.test", testTeam(t)), ), ConfigPlanChecks: resource.ConfigPlanChecks{ PreApply: []plancheck.PlanCheck{ @@ -272,16 +269,16 @@ func TestAcc_ProjectUpdateResourceConfig(t *testing.T) { func TestAcc_ProjectWithGitRepository(t *testing.T) { projectSuffix := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, - CheckDestroy: testAccProjectDestroy("vercel_project.test_git", testTeam()), + CheckDestroy: testAccProjectDestroy(testClient(t), "vercel_project.test_git", testTeam(t)), Steps: []resource.TestStep{ { - Config: testAccProjectConfigWithGitRepo(projectSuffix, teamIDConfig()), + Config: testAccProjectConfigWithGitRepo(projectSuffix, teamIDConfig(t), testGithubRepo(t)), Check: resource.ComposeAggregateTestCheckFunc( - testAccProjectExists("vercel_project.test_git", testTeam()), + testAccProjectExists(testClient(t), "vercel_project.test_git", testTeam(t)), resource.TestCheckResourceAttr("vercel_project.test_git", "git_repository.type", "github"), - resource.TestCheckResourceAttr("vercel_project.test_git", "git_repository.repo", testGithubRepo()), + resource.TestCheckResourceAttr("vercel_project.test_git", "git_repository.repo", testGithubRepo(t)), resource.TestCheckTypeSetElemNestedAttrs("vercel_project.test_git", "environment.*", map[string]string{ "key": "foo", "value": "bar", @@ -291,9 +288,9 @@ func TestAcc_ProjectWithGitRepository(t *testing.T) { ), }, { - Config: testAccProjectConfigWithGitRepoUpdated(projectSuffix, teamIDConfig()), + Config: testAccProjectConfigWithGitRepoUpdated(projectSuffix, teamIDConfig(t), testGithubRepo(t)), Check: resource.ComposeAggregateTestCheckFunc( - testAccProjectExists("vercel_project.test_git", testTeam()), + testAccProjectExists(testClient(t), "vercel_project.test_git", testTeam(t)), resource.TestCheckTypeSetElemNestedAttrs("vercel_project.test_git", "environment.*", map[string]string{ "key": "foo", "value": "bar2", @@ -302,9 +299,9 @@ func TestAcc_ProjectWithGitRepository(t *testing.T) { ), }, { - Config: testAccProjectConfigWithGitRepoRemoved(projectSuffix, teamIDConfig()), + Config: testAccProjectConfigWithGitRepoRemoved(projectSuffix, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( - testAccProjectExists("vercel_project.test_git", testTeam()), + testAccProjectExists(testClient(t), "vercel_project.test_git", testTeam(t)), resource.TestCheckNoResourceAttr("vercel_project.test_git", "git_repository"), ), }, @@ -315,14 +312,14 @@ func TestAcc_ProjectWithGitRepository(t *testing.T) { func TestAcc_ProjectWithVercelAuthAndPasswordProtectionAndTrustedIps(t *testing.T) { projectSuffix := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, - CheckDestroy: testAccProjectDestroy("vercel_project.enabled_to_start", testTeam()), + CheckDestroy: testAccProjectDestroy(testClient(t), "vercel_project.enabled_to_start", testTeam(t)), Steps: []resource.TestStep{ { - Config: testAccProjectConfigWithVercelAuthAndPasswordAndTrustedIpsAndOptionsAllowlist(projectSuffix, teamIDConfig()), + Config: testAccProjectConfigWithVercelAuthAndPasswordAndTrustedIpsAndOptionsAllowlist(projectSuffix, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( - testAccProjectExists("vercel_project.enabled_to_start", testTeam()), + testAccProjectExists(testClient(t), "vercel_project.enabled_to_start", testTeam(t)), resource.TestCheckResourceAttr("vercel_project.enabled_to_start", "vercel_authentication.deployment_type", "all_deployments"), resource.TestCheckResourceAttr("vercel_project.enabled_to_start", "password_protection.deployment_type", "all_deployments"), resource.TestCheckResourceAttr("vercel_project.enabled_to_start", "password_protection.password", "password"), @@ -337,13 +334,13 @@ func TestAcc_ProjectWithVercelAuthAndPasswordProtectionAndTrustedIps(t *testing. resource.TestCheckResourceAttr("vercel_project.enabled_to_start", "options_allowlist.paths.0.value", "/foo"), resource.TestCheckResourceAttr("vercel_project.enabled_to_start", "protection_bypass_for_automation", "true"), resource.TestCheckResourceAttrSet("vercel_project.enabled_to_start", "protection_bypass_for_automation_secret"), - testAccProjectExists("vercel_project.disabled_to_start", testTeam()), + testAccProjectExists(testClient(t), "vercel_project.disabled_to_start", testTeam(t)), resource.TestCheckResourceAttr("vercel_project.disabled_to_start", "vercel_authentication.deployment_type", "standard_protection"), resource.TestCheckNoResourceAttr("vercel_project.disabled_to_start", "password_protection"), resource.TestCheckNoResourceAttr("vercel_project.disabled_to_start", "trusted_ips"), resource.TestCheckNoResourceAttr("vercel_project.disabled_to_start", "protection_bypass_for_automation"), resource.TestCheckNoResourceAttr("vercel_project.disabled_to_start", "protection_bypass_for_automation_secret"), - testAccProjectExists("vercel_project.enabled_to_update", testTeam()), + testAccProjectExists(testClient(t), "vercel_project.enabled_to_update", testTeam(t)), resource.TestCheckResourceAttr("vercel_project.enabled_to_update", "vercel_authentication.deployment_type", "only_preview_deployments"), resource.TestCheckResourceAttr("vercel_project.enabled_to_update", "password_protection.deployment_type", "only_preview_deployments"), resource.TestCheckResourceAttr("vercel_project.enabled_to_update", "password_protection.password", "password"), @@ -361,7 +358,7 @@ func TestAcc_ProjectWithVercelAuthAndPasswordProtectionAndTrustedIps(t *testing. ), }, { - Config: testAccProjectConfigWithVercelAuthAndPasswordAndTrustedIpsAndOptionsAllowlistUpdated(projectSuffix, teamIDConfig()), + Config: testAccProjectConfigWithVercelAuthAndPasswordAndTrustedIpsAndOptionsAllowlistUpdated(projectSuffix, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("vercel_project.enabled_to_start", "vercel_authentication.deployment_type", "standard_protection"), resource.TestCheckNoResourceAttr("vercel_project.enabled_to_start", "password_protection"), @@ -407,30 +404,30 @@ func TestAcc_ProjectWithVercelAuthAndPasswordProtectionAndTrustedIps(t *testing. func TestAcc_ProjectWithAutomationBypass(t *testing.T) { projectSuffix := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, - CheckDestroy: testAccProjectDestroy("vercel_project.disabled_to_enabled_generated_secret", testTeam()), + CheckDestroy: testAccProjectDestroy(testClient(t), "vercel_project.disabled_to_enabled_generated_secret", testTeam(t)), Steps: []resource.TestStep{ { - Config: testAccProjectConfigAutomationBypass(projectSuffix, teamIDConfig()), + Config: testAccProjectConfigAutomationBypass(projectSuffix, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( - testAccProjectExists("vercel_project.disabled_to_enabled_generated_secret", testTeam()), + testAccProjectExists(testClient(t), "vercel_project.disabled_to_enabled_generated_secret", testTeam(t)), resource.TestCheckNoResourceAttr("vercel_project.disabled_to_enabled_generated_secret", "protection_bypass_for_automation"), - testAccProjectExists("vercel_project.disabled_to_enabled_custom_secret", testTeam()), + testAccProjectExists(testClient(t), "vercel_project.disabled_to_enabled_custom_secret", testTeam(t)), resource.TestCheckNoResourceAttr("vercel_project.disabled_to_enabled_custom_secret", "protection_bypass_for_automation"), - testAccProjectExists("vercel_project.enabled_generated_secret_to_enabled_custom_secret", testTeam()), + testAccProjectExists(testClient(t), "vercel_project.enabled_generated_secret_to_enabled_custom_secret", testTeam(t)), resource.TestCheckResourceAttr("vercel_project.enabled_generated_secret_to_enabled_custom_secret", "protection_bypass_for_automation", "true"), resource.TestCheckResourceAttrSet("vercel_project.enabled_generated_secret_to_enabled_custom_secret", "protection_bypass_for_automation_secret"), - testAccProjectExists("vercel_project.enabled_generated_secret_to_disabled", testTeam()), + testAccProjectExists(testClient(t), "vercel_project.enabled_generated_secret_to_disabled", testTeam(t)), resource.TestCheckResourceAttr("vercel_project.enabled_generated_secret_to_disabled", "protection_bypass_for_automation", "true"), resource.TestCheckResourceAttrSet("vercel_project.enabled_generated_secret_to_disabled", "protection_bypass_for_automation_secret"), - testAccProjectExists("vercel_project.enabled_custom_secret_to_disabled", testTeam()), + testAccProjectExists(testClient(t), "vercel_project.enabled_custom_secret_to_disabled", testTeam(t)), resource.TestCheckResourceAttr("vercel_project.enabled_custom_secret_to_disabled", "protection_bypass_for_automation", "true"), resource.TestCheckResourceAttr("vercel_project.enabled_custom_secret_to_disabled", "protection_bypass_for_automation_secret", "12345678912345678912345678912345"), ), }, { - Config: testAccProjectConfigAutomationBypassUpdate(projectSuffix, teamIDConfig()), + Config: testAccProjectConfigAutomationBypassUpdate(projectSuffix, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("vercel_project.disabled_to_enabled_generated_secret", "protection_bypass_for_automation", "true"), resource.TestCheckResourceAttrSet("vercel_project.disabled_to_enabled_generated_secret", "protection_bypass_for_automation_secret"), @@ -467,14 +464,14 @@ func getProjectImportID(n string) resource.ImportStateIdFunc { func TestAcc_ProjectImport(t *testing.T) { projectSuffix := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, - CheckDestroy: testAccProjectDestroy("vercel_project.test", testTeam()), + CheckDestroy: testAccProjectDestroy(testClient(t), "vercel_project.test", testTeam(t)), Steps: []resource.TestStep{ { - Config: projectConfigWithoutEnv(projectSuffix, teamIDConfig()), + Config: projectConfigWithoutEnv(projectSuffix, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( - testAccProjectExists("vercel_project.test", testTeam()), + testAccProjectExists(testClient(t), "vercel_project.test", testTeam(t)), ), }, { @@ -490,24 +487,24 @@ func TestAcc_ProjectImport(t *testing.T) { func TestAcc_ProjectEnablingAffectedProjectDeployments(t *testing.T) { projectSuffix := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, - CheckDestroy: testAccProjectDestroy("vercel_project.test", testTeam()), + CheckDestroy: testAccProjectDestroy(testClient(t), "vercel_project.test", testTeam(t)), Steps: []resource.TestStep{ { - Config: testAccProjectConfigWithoutEnableAffectedSet(projectSuffix, teamIDConfig()), + Config: testAccProjectConfigWithoutEnableAffectedSet(projectSuffix, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckNoResourceAttr("vercel_project.test", "enable_affected_projects_deployments"), ), }, { - Config: testAccProjectConfigWithEnableAffectedTrue(projectSuffix, teamIDConfig()), + Config: testAccProjectConfigWithEnableAffectedTrue(projectSuffix, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("vercel_project.test", "enable_affected_projects_deployments", "true"), ), }, { - Config: testAccProjectConfigWithEnableAffectedFalse(projectSuffix, teamIDConfig()), + Config: testAccProjectConfigWithEnableAffectedFalse(projectSuffix, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("vercel_project.test", "enable_affected_projects_deployments", "false"), ), @@ -516,7 +513,7 @@ func TestAcc_ProjectEnablingAffectedProjectDeployments(t *testing.T) { }) } -func testAccProjectExists(n, teamID string) resource.TestCheckFunc { +func testAccProjectExists(testClient *client.Client, n, teamID string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -527,12 +524,12 @@ func testAccProjectExists(n, teamID string) resource.TestCheckFunc { return fmt.Errorf("no projectID is set") } - _, err := testClient().GetProject(context.TODO(), rs.Primary.ID, teamID) + _, err := testClient.GetProject(context.TODO(), rs.Primary.ID, teamID) return err } } -func testAccProjectDestroy(n, teamID string) resource.TestCheckFunc { +func testAccProjectDestroy(testClient *client.Client, n, teamID string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -543,7 +540,7 @@ func testAccProjectDestroy(n, teamID string) resource.TestCheckFunc { return fmt.Errorf("no projectID is set") } - _, err := testClient().GetProject(context.TODO(), rs.Primary.ID, teamID) + _, err := testClient.GetProject(context.TODO(), rs.Primary.ID, teamID) if err == nil { return fmt.Errorf("expected not_found error, but got no error") } @@ -843,7 +840,7 @@ resource "vercel_project" "enabled_custom_secret_to_disabled" { `, projectSuffix, teamID) } -func testAccProjectConfigWithGitRepo(projectSuffix, teamID string) string { +func testAccProjectConfigWithGitRepo(projectSuffix, teamID string, githubRepo string) string { return fmt.Sprintf(` resource "vercel_project" "test_git" { name = "test-acc-two-%s" @@ -868,10 +865,10 @@ resource "vercel_project" "test_git" { } ] } - `, projectSuffix, teamID, testGithubRepo()) + `, projectSuffix, teamID, githubRepo) } -func testAccProjectConfigWithGitRepoUpdated(projectSuffix, teamID string) string { +func testAccProjectConfigWithGitRepoUpdated(projectSuffix, teamID string, githubRepo string) string { return fmt.Sprintf(` resource "vercel_project" "test_git" { name = "test-acc-two-%s" @@ -901,7 +898,7 @@ resource "vercel_project" "test_git" { } ] } - `, projectSuffix, teamID, testGithubRepo()) + `, projectSuffix, teamID, githubRepo) } func testAccProjectConfigWithGitRepoRemoved(projectSuffix, teamID string) string { diff --git a/vercel/resource_shared_environment_variable_project_link_test.go b/vercel/resource_shared_environment_variable_project_link_test.go index 27105540..831c4d31 100644 --- a/vercel/resource_shared_environment_variable_project_link_test.go +++ b/vercel/resource_shared_environment_variable_project_link_test.go @@ -9,9 +9,10 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" + "github.com/vercel/terraform-provider-vercel/v2/client" ) -func testCheckSharedEnvironmentVariableProjectUnlinked(envVarName, projectName, teamID string) resource.TestCheckFunc { +func testCheckSharedEnvironmentVariableProjectUnlinked(testClient *client.Client, envVarName, projectName, teamID string) resource.TestCheckFunc { return func(s *terraform.State) error { envVar, ok := s.RootModule().Resources[envVarName] if !ok { @@ -22,7 +23,7 @@ func testCheckSharedEnvironmentVariableProjectUnlinked(envVarName, projectName, return fmt.Errorf("project not found: %s", projectName) } - resp, err := testClient().GetSharedEnvironmentVariable(context.TODO(), teamID, envVar.Primary.Attributes["id"]) + resp, err := testClient.GetSharedEnvironmentVariable(context.TODO(), teamID, envVar.Primary.Attributes["id"]) if err != nil { return err } @@ -33,7 +34,7 @@ func testCheckSharedEnvironmentVariableProjectUnlinked(envVarName, projectName, } } -func testCheckSharedEnvironmentVariableProjectLinked(envVarName, projectName, teamID string) resource.TestCheckFunc { +func testCheckSharedEnvironmentVariableProjectLinked(testClient *client.Client, envVarName, projectName, teamID string) resource.TestCheckFunc { return func(s *terraform.State) error { envVar, ok := s.RootModule().Resources[envVarName] if !ok { @@ -44,7 +45,7 @@ func testCheckSharedEnvironmentVariableProjectLinked(envVarName, projectName, te return fmt.Errorf("project not found: %s", projectName) } - resp, err := testClient().GetSharedEnvironmentVariable(context.TODO(), teamID, envVar.Primary.Attributes["id"]) + resp, err := testClient.GetSharedEnvironmentVariable(context.TODO(), teamID, envVar.Primary.Attributes["id"]) if err != nil { return err } @@ -58,35 +59,34 @@ func testCheckSharedEnvironmentVariableProjectLinked(envVarName, projectName, te func TestAcc_SharedEnvironmentVariableProjectLink(t *testing.T) { name := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, CheckDestroy: resource.ComposeAggregateTestCheckFunc( - testCheckSharedEnvironmentVariableProjectUnlinked("data.vercel_shared_environment_variable.test", "vercel_project.test0", testTeam()), - testCheckSharedEnvironmentVariableProjectUnlinked("data.vercel_shared_environment_variable.test", "vercel_project.test1", testTeam()), - testCheckSharedEnvironmentVariableProjectUnlinked("data.vercel_shared_environment_variable.test", "vercel_project.test2", testTeam()), + testCheckSharedEnvironmentVariableProjectUnlinked(testClient(t), "data.vercel_shared_environment_variable.test", "vercel_project.test0", testTeam(t)), + testCheckSharedEnvironmentVariableProjectUnlinked(testClient(t), "data.vercel_shared_environment_variable.test", "vercel_project.test1", testTeam(t)), + testCheckSharedEnvironmentVariableProjectUnlinked(testClient(t), "data.vercel_shared_environment_variable.test", "vercel_project.test2", testTeam(t)), ), Steps: []resource.TestStep{ { - Config: testAccSharedEnvironmentVariableProjectLinkSetup(name, teamIDConfig()), + Config: testAccSharedEnvironmentVariableProjectLinkSetup(name, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( - testCheckSharedEnvironmentVariableProjectLinked("data.vercel_shared_environment_variable.test", "vercel_project.test0", testTeam()), - testCheckSharedEnvironmentVariableProjectLinked("data.vercel_shared_environment_variable.test", "vercel_project.test1", testTeam()), + testCheckSharedEnvironmentVariableProjectLinked(testClient(t), "data.vercel_shared_environment_variable.test", "vercel_project.test0", testTeam(t)), + testCheckSharedEnvironmentVariableProjectLinked(testClient(t), "data.vercel_shared_environment_variable.test", "vercel_project.test1", testTeam(t)), ), }, { - Config: testAccSharedEnvironmentVariableProjectLinkAdd1(name, teamIDConfig()), + Config: testAccSharedEnvironmentVariableProjectLinkAdd1(name, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( - testCheckSharedEnvironmentVariableProjectLinked("data.vercel_shared_environment_variable.test", "vercel_project.test0", testTeam()), - testCheckSharedEnvironmentVariableProjectLinked("data.vercel_shared_environment_variable.test", "vercel_project.test1", testTeam()), - testCheckSharedEnvironmentVariableProjectLinked("data.vercel_shared_environment_variable.test", "vercel_project.test2", testTeam()), + testCheckSharedEnvironmentVariableProjectLinked(testClient(t), "data.vercel_shared_environment_variable.test", "vercel_project.test0", testTeam(t)), + testCheckSharedEnvironmentVariableProjectLinked(testClient(t), "data.vercel_shared_environment_variable.test", "vercel_project.test1", testTeam(t)), + testCheckSharedEnvironmentVariableProjectLinked(testClient(t), "data.vercel_shared_environment_variable.test", "vercel_project.test2", testTeam(t)), ), }, { - Config: testAccSharedEnvironmentVariableProjectLinkDrop1(name, teamIDConfig()), + Config: testAccSharedEnvironmentVariableProjectLinkDrop1(name, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( - testCheckSharedEnvironmentVariableProjectLinked("data.vercel_shared_environment_variable.test", "vercel_project.test0", testTeam()), - testCheckSharedEnvironmentVariableProjectLinked("data.vercel_shared_environment_variable.test", "vercel_project.test1", testTeam()), - testCheckSharedEnvironmentVariableProjectUnlinked("data.vercel_shared_environment_variable.test", "vercel_project.test2", testTeam()), + testCheckSharedEnvironmentVariableProjectLinked(testClient(t), "data.vercel_shared_environment_variable.test", "vercel_project.test0", testTeam(t)), + testCheckSharedEnvironmentVariableProjectLinked(testClient(t), "data.vercel_shared_environment_variable.test", "vercel_project.test1", testTeam(t)), + testCheckSharedEnvironmentVariableProjectUnlinked(testClient(t), "data.vercel_shared_environment_variable.test", "vercel_project.test2", testTeam(t)), ), }, }, diff --git a/vercel/resource_shared_environment_variable_test.go b/vercel/resource_shared_environment_variable_test.go index c2a4ddff..73a10293 100644 --- a/vercel/resource_shared_environment_variable_test.go +++ b/vercel/resource_shared_environment_variable_test.go @@ -8,9 +8,10 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" + "github.com/vercel/terraform-provider-vercel/v2/client" ) -func testAccSharedEnvironmentVariableExists(n, teamID string) resource.TestCheckFunc { +func testAccSharedEnvironmentVariableExists(testClient *client.Client, n, teamID string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -21,7 +22,7 @@ func testAccSharedEnvironmentVariableExists(n, teamID string) resource.TestCheck return fmt.Errorf("no ID is set") } - _, err := testClient().GetSharedEnvironmentVariable(context.TODO(), teamID, rs.Primary.ID) + _, err := testClient.GetSharedEnvironmentVariable(context.TODO(), teamID, rs.Primary.ID) return err } } @@ -29,28 +30,27 @@ func testAccSharedEnvironmentVariableExists(n, teamID string) resource.TestCheck func TestAcc_SharedEnvironmentVariables(t *testing.T) { nameSuffix := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, CheckDestroy: resource.ComposeAggregateTestCheckFunc( - testAccProjectDestroy("vercel_project.example", testTeam()), + testAccProjectDestroy(testClient(t), "vercel_project.example", testTeam(t)), ), Steps: []resource.TestStep{ { - Config: testAccSharedEnvironmentVariablesConfig(nameSuffix), + Config: testAccSharedEnvironmentVariablesConfig(nameSuffix, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( - testAccSharedEnvironmentVariableExists("vercel_shared_environment_variable.example", testTeam()), + testAccSharedEnvironmentVariableExists(testClient(t), "vercel_shared_environment_variable.example", testTeam(t)), resource.TestCheckResourceAttr("vercel_shared_environment_variable.example", "key", fmt.Sprintf("test_acc_foo_%s", nameSuffix)), resource.TestCheckResourceAttr("vercel_shared_environment_variable.example", "value", "bar"), resource.TestCheckResourceAttr("vercel_shared_environment_variable.example", "comment", "Test comment for example"), resource.TestCheckTypeSetElemAttr("vercel_shared_environment_variable.example", "target.*", "production"), - testAccSharedEnvironmentVariableExists("vercel_shared_environment_variable.sensitive_example", testTeam()), + testAccSharedEnvironmentVariableExists(testClient(t), "vercel_shared_environment_variable.sensitive_example", testTeam(t)), resource.TestCheckResourceAttr("vercel_shared_environment_variable.sensitive_example", "key", fmt.Sprintf("test_acc_foo_sensitive_%s", nameSuffix)), resource.TestCheckResourceAttr("vercel_shared_environment_variable.sensitive_example", "value", "bar"), resource.TestCheckResourceAttr("vercel_shared_environment_variable.sensitive_example", "comment", "Test comment for sensitive example"), resource.TestCheckTypeSetElemAttr("vercel_shared_environment_variable.sensitive_example", "target.*", "production"), - testAccSharedEnvironmentVariableExists("vercel_shared_environment_variable.no_comment_example", testTeam()), + testAccSharedEnvironmentVariableExists(testClient(t), "vercel_shared_environment_variable.no_comment_example", testTeam(t)), resource.TestCheckResourceAttr("vercel_shared_environment_variable.no_comment_example", "key", fmt.Sprintf("test_acc_foo_no_comment_%s", nameSuffix)), resource.TestCheckResourceAttr("vercel_shared_environment_variable.no_comment_example", "value", "baz"), resource.TestCheckResourceAttr("vercel_shared_environment_variable.no_comment_example", "comment", ""), @@ -58,9 +58,9 @@ func TestAcc_SharedEnvironmentVariables(t *testing.T) { ), }, { - Config: testAccSharedEnvironmentVariablesConfigUpdated(nameSuffix), + Config: testAccSharedEnvironmentVariablesConfigUpdated(nameSuffix, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( - testAccSharedEnvironmentVariableExists("vercel_shared_environment_variable.example", testTeam()), + testAccSharedEnvironmentVariableExists(testClient(t), "vercel_shared_environment_variable.example", testTeam(t)), resource.TestCheckResourceAttr("vercel_shared_environment_variable.example", "key", fmt.Sprintf("test_acc_foo_%s", nameSuffix)), resource.TestCheckResourceAttr("vercel_shared_environment_variable.example", "value", "updated-bar"), resource.TestCheckTypeSetElemAttr("vercel_shared_environment_variable.example", "target.*", "development"), @@ -78,7 +78,7 @@ func TestAcc_SharedEnvironmentVariables(t *testing.T) { ImportStateIdFunc: getSharedEnvironmentVariableImportID("vercel_shared_environment_variable.example"), }, { - Config: testAccSharedEnvironmentVariablesConfigDeleted(nameSuffix), + Config: testAccSharedEnvironmentVariablesConfigDeleted(nameSuffix, teamIDConfig(t)), }, }, }) @@ -99,7 +99,7 @@ func getSharedEnvironmentVariableImportID(n string) resource.ImportStateIdFunc { } } -func testAccSharedEnvironmentVariablesConfig(projectName string) string { +func testAccSharedEnvironmentVariablesConfig(projectName string, teamIDConfig string) string { return fmt.Sprintf(` resource "vercel_project" "example" { name = "test-acc-example-project-%[1]s" @@ -138,10 +138,10 @@ resource "vercel_shared_environment_variable" "no_comment_example" { vercel_project.example.id ] } -`, projectName, teamIDConfig()) +`, projectName, teamIDConfig) } -func testAccSharedEnvironmentVariablesConfigUpdated(projectName string) string { +func testAccSharedEnvironmentVariablesConfigUpdated(projectName string, teamIDConfig string) string { return fmt.Sprintf(` resource "vercel_project" "example" { name = "test-acc-example-project-%[1]s" @@ -175,10 +175,10 @@ resource "vercel_shared_environment_variable" "sensitive_example" { vercel_project.example2.id ] } -`, projectName, teamIDConfig()) +`, projectName, teamIDConfig) } -func testAccSharedEnvironmentVariablesConfigDeleted(projectName string) string { +func testAccSharedEnvironmentVariablesConfigDeleted(projectName string, teamIDConfig string) string { return fmt.Sprintf(` resource "vercel_project" "example" { name = "test-acc-example-project-%[1]s" @@ -189,5 +189,5 @@ resource "vercel_project" "example2" { name = "test-acc-example-project-2-%[1]s" %[2]s } - `, projectName, teamIDConfig()) + `, projectName, teamIDConfig) } diff --git a/vercel/resource_team_config_test.go b/vercel/resource_team_config_test.go index 9810a9dc..85a95c0a 100644 --- a/vercel/resource_team_config_test.go +++ b/vercel/resource_team_config_test.go @@ -11,11 +11,10 @@ func TestAcc_TeamConfig(t *testing.T) { resourceName := "vercel_team_config.test" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { - Config: testAccVercelTeamConfigBasic(testTeam()), + Config: testAccVercelTeamConfigBasic(testTeam(t)), // Added since vercel_team_config schema version upgraded ExpectNonEmptyPlan: true, Check: resource.ComposeAggregateTestCheckFunc( @@ -25,7 +24,7 @@ func TestAcc_TeamConfig(t *testing.T) { ), }, { - Config: testAccVercelTeamConfigUpdated(testTeam()), + Config: testAccVercelTeamConfigUpdated(testTeam(t)), // Added since vercel_team_config schema version upgraded ExpectNonEmptyPlan: true, Check: resource.ComposeAggregateTestCheckFunc( diff --git a/vercel/resource_team_member_test.go b/vercel/resource_team_member_test.go index f669d96e..d93f7b35 100644 --- a/vercel/resource_team_member_test.go +++ b/vercel/resource_team_member_test.go @@ -23,12 +23,11 @@ func getTeamMemberImportID(n string) resource.ImportStateIdFunc { func TestAcc_TeamMemberResource(t *testing.T) { randomSuffix := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ // Create and Read testing { - Config: testAccTeamMemberResourceConfig("MEMBER"), + Config: testAccTeamMemberResourceConfig("MEMBER", teamIDConfig(t), testAdditionalUser(t)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("vercel_team_member.test", "team_id"), resource.TestCheckResourceAttrSet("vercel_team_member.test", "user_id"), @@ -45,7 +44,7 @@ func TestAcc_TeamMemberResource(t *testing.T) { }, // Update testing { - Config: testAccTeamMemberResourceConfig("VIEWER"), + Config: testAccTeamMemberResourceConfig("VIEWER", teamIDConfig(t), testAdditionalUser(t)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("vercel_team_member.test", "team_id"), resource.TestCheckResourceAttrSet("vercel_team_member.test", "user_id"), @@ -54,7 +53,7 @@ func TestAcc_TeamMemberResource(t *testing.T) { }, // Test with projects { - Config: testAccTeamMemberResourceConfigWithProjects(randomSuffix), + Config: testAccTeamMemberResourceConfigWithProjects(randomSuffix, teamIDConfig(t), testAdditionalUser(t)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("vercel_team_member.test", "team_id"), resource.TestCheckResourceAttrSet("vercel_team_member.test", "user_id"), @@ -64,7 +63,7 @@ func TestAcc_TeamMemberResource(t *testing.T) { }, // Test with access groups { - Config: testAccTeamMemberResourceConfigWithAccessGroups(randomSuffix), + Config: testAccTeamMemberResourceConfigWithAccessGroups(randomSuffix, teamIDConfig(t), testAdditionalUser(t)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("vercel_team_member.test", "team_id"), resource.TestCheckResourceAttrSet("vercel_team_member.test", "user_id"), @@ -76,17 +75,17 @@ func TestAcc_TeamMemberResource(t *testing.T) { }) } -func testAccTeamMemberResourceConfig(role string) string { +func testAccTeamMemberResourceConfig(role string, teamIDConfig string, user string) string { return fmt.Sprintf(` resource "vercel_team_member" "test" { %[1]s user_id = "%s" role = "%s" } -`, teamIDConfig(), testAdditionalUser(), role) +`, teamIDConfig, user, role) } -func testAccTeamMemberResourceConfigWithProjects(randomSuffix string) string { +func testAccTeamMemberResourceConfigWithProjects(randomSuffix string, teamIDConfig string, user string) string { return fmt.Sprintf(` resource "vercel_project" "test" { name = "test-acc-example-project-%[1]s" @@ -102,10 +101,10 @@ resource "vercel_team_member" "test" { role = "PROJECT_VIEWER" }] } -`, randomSuffix, teamIDConfig(), testAdditionalUser()) +`, randomSuffix, teamIDConfig, user) } -func testAccTeamMemberResourceConfigWithAccessGroups(randomSuffix string) string { +func testAccTeamMemberResourceConfigWithAccessGroups(randomSuffix string, teamIDConfig string, user string) string { return fmt.Sprintf(` resource "vercel_access_group" "test" { %[1]s @@ -119,5 +118,5 @@ resource "vercel_team_member" "test" { access_groups = [vercel_access_group.test.id] } -`, teamIDConfig(), testAdditionalUser(), randomSuffix) +`, teamIDConfig, user, randomSuffix) } diff --git a/vercel/resource_webhook_test.go b/vercel/resource_webhook_test.go index 8ce7bd06..a2e30548 100644 --- a/vercel/resource_webhook_test.go +++ b/vercel/resource_webhook_test.go @@ -11,7 +11,7 @@ import ( "github.com/vercel/terraform-provider-vercel/v2/client" ) -func testCheckWebhookExists(teamID, n string) resource.TestCheckFunc { +func testCheckWebhookExists(testClient *client.Client, teamID, n string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -22,12 +22,12 @@ func testCheckWebhookExists(teamID, n string) resource.TestCheckFunc { return fmt.Errorf("no ID is set") } - _, err := testClient().GetWebhook(context.TODO(), rs.Primary.ID, teamID) + _, err := testClient.GetWebhook(context.TODO(), rs.Primary.ID, teamID) return err } } -func testCheckWebhooksDeleted(n1, n2, teamID string) resource.TestCheckFunc { +func testCheckWebhooksDeleted(testClient *client.Client, n1, n2, teamID string) resource.TestCheckFunc { return func(s *terraform.State) error { for _, n := range []string{n1, n2} { rs, ok := s.RootModule().Resources[n] @@ -39,7 +39,7 @@ func testCheckWebhooksDeleted(n1, n2, teamID string) resource.TestCheckFunc { return fmt.Errorf("no ID is set") } - _, err := testClient().GetWebhook(context.TODO(), rs.Primary.ID, teamID) + _, err := testClient.GetWebhook(context.TODO(), rs.Primary.ID, teamID) if err == nil { return fmt.Errorf("expected not_found error, but got no error") } @@ -54,20 +54,19 @@ func testCheckWebhooksDeleted(n1, n2, teamID string) resource.TestCheckFunc { func TestAcc_WebhookResource(t *testing.T) { name := acctest.RandString(16) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, - CheckDestroy: testCheckWebhooksDeleted("vercel_webhook.with_project_ids", "vercel_webhook.without_project_ids", testTeam()), + CheckDestroy: testCheckWebhooksDeleted(testClient(t), "vercel_webhook.with_project_ids", "vercel_webhook.without_project_ids", testTeam(t)), Steps: []resource.TestStep{ { - Config: testAccResourceWebhook(name, teamIDConfig()), + Config: testAccResourceWebhook(name, teamIDConfig(t)), Check: resource.ComposeAggregateTestCheckFunc( - testCheckWebhookExists(testTeam(), "vercel_webhook.with_project_ids"), + testCheckWebhookExists(testClient(t), testTeam(t), "vercel_webhook.with_project_ids"), resource.TestCheckTypeSetElemAttr("vercel_webhook.with_project_ids", "events.*", "deployment.created"), resource.TestCheckTypeSetElemAttr("vercel_webhook.with_project_ids", "events.*", "deployment.succeeded"), resource.TestCheckResourceAttrSet("vercel_webhook.with_project_ids", "id"), resource.TestCheckResourceAttrSet("vercel_webhook.with_project_ids", "secret"), - testCheckWebhookExists(testTeam(), "vercel_webhook.without_project_ids"), + testCheckWebhookExists(testClient(t), testTeam(t), "vercel_webhook.without_project_ids"), resource.TestCheckTypeSetElemAttr("vercel_webhook.without_project_ids", "events.*", "deployment.created"), resource.TestCheckTypeSetElemAttr("vercel_webhook.without_project_ids", "events.*", "deployment.succeeded"), resource.TestCheckResourceAttrSet("vercel_webhook.without_project_ids", "id"),