Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Reuses projects in executions in some resources and rename mig tests #2007

Merged
merged 12 commits into from
Mar 15, 2024
1 change: 0 additions & 1 deletion .github/workflows/acceptance-tests-runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ env:
TF_LOG: ${{ vars.LOG_LEVEL }}
ACCTEST_TIMEOUT: ${{ vars.ACCTEST_TIMEOUT }}
ACCTEST_REGEX_RUN: "^TestAcc"
ACCTEST_REGEX_SKIP: "^TestAccMigration"
MONGODB_ATLAS_BASE_URL: ${{ inputs.mongodb_atlas_base_url }}
MONGODB_ATLAS_ORG_ID: ${{ inputs.mongodb_atlas_org_id }}
MONGODB_ATLAS_PUBLIC_KEY: ${{ secrets.mongodb_atlas_public_key }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/migration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ env:
TF_ACC: 1
TF_LOG: ${{ vars.LOG_LEVEL }}
ACCTEST_TIMEOUT: ${{ vars.ACCTEST_TIMEOUT }}
ACCTEST_REGEX_RUN: "^TestAccMigration"
ACCTEST_REGEX_RUN: "^TestMig"
marcosuma marked this conversation as resolved.
Show resolved Hide resolved
andreaangiolillo marked this conversation as resolved.
Show resolved Hide resolved
MONGODB_ATLAS_BASE_URL: ${{ vars.MONGODB_ATLAS_BASE_URL }}
MONGODB_ATLAS_ORG_ID: ${{ vars.MONGODB_ATLAS_ORG_ID_CLOUD_DEV }}
MONGODB_ATLAS_PUBLIC_KEY: ${{ secrets.MONGODB_ATLAS_PUBLIC_KEY_CLOUD_DEV }}
Expand Down
2 changes: 1 addition & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ test: fmtcheck
.PHONY: testacc
testacc: fmtcheck
@$(eval VERSION=acc)
TF_ACC=1 go test $(ACCTEST_PACKAGES) -run '$(ACCTEST_REGEX_RUN)' -skip '$(ACCTEST_REGEX_SKIP)' -v -parallel $(PARALLEL_GO_TEST) $(TESTARGS) -timeout $(ACCTEST_TIMEOUT) -ldflags="$(LINKER_FLAGS)"
TF_ACC=1 go test $(ACCTEST_PACKAGES) -run '$(ACCTEST_REGEX_RUN)' -v -parallel $(PARALLEL_GO_TEST) $(TESTARGS) -timeout $(ACCTEST_TIMEOUT) -ldflags="$(LINKER_FLAGS)"

.PHONY: testaccgov
testaccgov: fmtcheck
Expand Down
15 changes: 15 additions & 0 deletions internal/service/accesslistapikey/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package accesslistapikey_test

import (
"os"
"testing"

"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc"
)

func TestMain(m *testing.M) {
cleanup := acc.SetupSharedResources()
exitCode := m.Run()
cleanup()
os.Exit(exitCode)
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/mig"
)

func TestAccMigrationProjectAccesslistAPIKey_SettingIPAddress(t *testing.T) {
func TestMigProjectAccesslistAPIKey_SettingIPAddress(t *testing.T) {
andreaangiolillo marked this conversation as resolved.
Show resolved Hide resolved
var (
resourceName = "mongodbatlas_access_list_api_key.test"
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
Expand All @@ -37,7 +37,7 @@ func TestAccMigrationProjectAccesslistAPIKey_SettingIPAddress(t *testing.T) {
})
}

func TestAccMigrationProjectAccesslistAPIKey_SettingCIDRBlock(t *testing.T) {
func TestMigProjectAccesslistAPIKey_SettingCIDRBlock(t *testing.T) {
mig.SkipIfVersionBelow(t, "1.14.0") // 1.14.0 is the version when this resource was migrated to the new Atlas SDK

var (
Expand Down Expand Up @@ -75,7 +75,7 @@ func TestAccMigrationProjectAccesslistAPIKey_SettingCIDRBlock(t *testing.T) {
})
}

func TestAccMigrationProjectAccesslistAPIKey_SettingCIDRBlock_WideCIDR_SDKMigration(t *testing.T) {
func TestMigProjectAccesslistAPIKey_SettingCIDRBlock_WideCIDR_SDKMigration(t *testing.T) {
mig.SkipIfVersionBelow(t, "1.14.0") // 1.14.0 is the version when this resource was migrated to the new Atlas SDK

var (
Expand Down
15 changes: 15 additions & 0 deletions internal/service/advancedcluster/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package advancedcluster_test

import (
"os"
"testing"

"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc"
)

func TestMain(m *testing.M) {
cleanup := acc.SetupSharedResources()
exitCode := m.Run()
cleanup()
os.Exit(exitCode)
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/mig"
)

func TestAccMigrationAdvancedCluster_singleAWSProvider(t *testing.T) {
func TestMigAdvancedCluster_singleAWSProvider(t *testing.T) {
var (
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acc.RandomProjectName()
Expand Down Expand Up @@ -40,7 +40,7 @@ func TestAccMigrationAdvancedCluster_singleAWSProvider(t *testing.T) {
})
}

func TestAccMigrationAdvancedCluster_multiCloud(t *testing.T) {
func TestMigAdvancedCluster_multiCloud(t *testing.T) {
var (
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acc.RandomProjectName()
Expand Down Expand Up @@ -69,7 +69,7 @@ func TestAccMigrationAdvancedCluster_multiCloud(t *testing.T) {
})
}

func TestAccMigrationAdvancedCluster_partialAdvancedConf(t *testing.T) {
func TestMigAdvancedCluster_partialAdvancedConf(t *testing.T) {
var (
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acc.RandomProjectName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc"
)

func TestAccMigrationAdvancedCluster_empty_advancedConfig(t *testing.T) {
func TestMigAdvancedCluster_empty_advancedConfig(t *testing.T) {
acc.SkipInUnitTest(t) // needed because TF test infra is not used
v0State := map[string]any{
"project_id": "test-id",
Expand Down Expand Up @@ -62,7 +62,7 @@ func TestAccMigrationAdvancedCluster_empty_advancedConfig(t *testing.T) {
}
}

func TestAccMigrationAdvancedCluster_v0StateUpgrade_ReplicationSpecs(t *testing.T) {
func TestMigAdvancedCluster_v0StateUpgrade_ReplicationSpecs(t *testing.T) {
acc.SkipInUnitTest(t) // needed because TF test infra is not used
v0State := map[string]any{
"project_id": "test-id",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,15 @@ package alertconfiguration_test

import (
"fmt"
"os"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc"
"go.mongodb.org/atlas-sdk/v20231115007/admin"
)

func TestAccConfigDSAlertConfiguration_basic(t *testing.T) {
var (
alert = &admin.GroupAlertsConfig{}
dataSourceName = "data.mongodbatlas_alert_configuration.test"
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acc.RandomProjectName()
projectID = acc.ProjectIDExecution(t)
)

resource.ParallelTest(t, resource.TestCase{
Expand All @@ -24,10 +19,10 @@ func TestAccConfigDSAlertConfiguration_basic(t *testing.T) {
CheckDestroy: checkDestroy,
Steps: []resource.TestStep{
{
Config: configBasicDS(orgID, projectName),
Config: configBasicDS(projectID),
Check: resource.ComposeTestCheckFunc(
checkExists(dataSourceName, alert),
resource.TestCheckResourceAttrSet(dataSourceName, "project_id"),
checkExists(dataSourceName),
resource.TestCheckResourceAttr(dataSourceName, "project_id", projectID),
resource.TestCheckResourceAttr(dataSourceName, "notification.#", "1"),
resource.TestCheckResourceAttrSet(dataSourceName, "notification.0.notifier_id"),
resource.TestCheckResourceAttr(dataSourceName, "matcher.#", "1"),
Expand All @@ -41,10 +36,7 @@ func TestAccConfigDSAlertConfiguration_basic(t *testing.T) {

func TestAccConfigDSAlertConfiguration_withThreshold(t *testing.T) {
var (
alert = &admin.GroupAlertsConfig{}
dataSourceName = "data.mongodbatlas_alert_configuration.test"
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acc.RandomProjectName()
projectID = acc.ProjectIDExecution(t)
)

resource.ParallelTest(t, resource.TestCase{
Expand All @@ -53,11 +45,10 @@ func TestAccConfigDSAlertConfiguration_withThreshold(t *testing.T) {
CheckDestroy: checkDestroy,
Steps: []resource.TestStep{
{
Config: configWithThreshold(orgID, projectName, true, 1),
Config: configWithThreshold(projectID, true, 1),
Check: resource.ComposeTestCheckFunc(
checkExists(dataSourceName, alert),
resource.TestCheckResourceAttrSet(dataSourceName, "project_id"),
resource.TestCheckResourceAttrSet(dataSourceName, "project_id"),
checkExists(dataSourceName),
resource.TestCheckResourceAttr(dataSourceName, "project_id", projectID),
resource.TestCheckResourceAttr(dataSourceName, "notification.#", "1"),
resource.TestCheckResourceAttr(dataSourceName, "matcher.#", "1"),
resource.TestCheckResourceAttr(dataSourceName, "metric_threshold_config.#", "0"),
Expand All @@ -70,11 +61,8 @@ func TestAccConfigDSAlertConfiguration_withThreshold(t *testing.T) {

func TestAccConfigDSAlertConfiguration_withOutput(t *testing.T) {
var (
alert = &admin.GroupAlertsConfig{}
dataSourceName = "data.mongodbatlas_alert_configuration.test"
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acc.RandomProjectName()
outputLabel = "resource_import"
projectID = acc.ProjectIDExecution(t)
outputLabel = "resource_import"
)

resource.ParallelTest(t, resource.TestCase{
Expand All @@ -83,11 +71,10 @@ func TestAccConfigDSAlertConfiguration_withOutput(t *testing.T) {
CheckDestroy: checkDestroy,
Steps: []resource.TestStep{
{
Config: configWithOutputs(orgID, projectName, outputLabel),
Config: configWithOutputs(projectID, outputLabel),
Check: resource.ComposeTestCheckFunc(
checkExists(dataSourceName, alert),
resource.TestCheckResourceAttrSet(dataSourceName, "project_id"),
resource.TestCheckResourceAttrSet(dataSourceName, "project_id"),
checkExists(dataSourceName),
resource.TestCheckResourceAttr(dataSourceName, "project_id", projectID),
resource.TestCheckResourceAttr(dataSourceName, "notification.#", "1"),
resource.TestCheckResourceAttr(dataSourceName, "output.0.label", outputLabel),
resource.TestCheckResourceAttr(dataSourceName, "output.0.type", "resource_import"),
Expand All @@ -103,37 +90,30 @@ func TestAccConfigDSAlertConfiguration_withOutput(t *testing.T) {

func TestAccConfigDSAlertConfiguration_withPagerDuty(t *testing.T) {
var (
alert = &admin.GroupAlertsConfig{}
dataSourceName = "data.mongodbatlas_alert_configuration.test"
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acc.RandomProjectName()
serviceKey = dummy32CharKey
projectID = acc.ProjectIDExecution(t)
serviceKey = dummy32CharKey
)

resource.Test(t, resource.TestCase{
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acc.PreCheckBasic(t) },
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
CheckDestroy: checkDestroy,
Steps: []resource.TestStep{
{
Config: configWithPagerDutyDS(orgID, projectName, serviceKey, true),
Config: configWithPagerDutyDS(projectID, serviceKey, true),
Check: resource.ComposeTestCheckFunc(
checkExists(dataSourceName, alert),
resource.TestCheckResourceAttrSet(dataSourceName, "project_id"),
checkExists(dataSourceName),
resource.TestCheckResourceAttr(dataSourceName, "project_id", projectID),
),
},
},
})
}

func configBasicDS(orgID, projectName string) string {
func configBasicDS(projectID string) string {
return fmt.Sprintf(`
resource "mongodbatlas_project" "test" {
name = %[2]q
org_id = %[1]q
}
resource "mongodbatlas_alert_configuration" "test" {
project_id = mongodbatlas_project.test.id
project_id = %[1]q
event_type = "OUTSIDE_METRIC_THRESHOLD"
enabled = true

Expand Down Expand Up @@ -161,22 +141,18 @@ func configBasicDS(orgID, projectName string) string {
}

data "mongodbatlas_alert_configuration" "test" {
project_id = "${mongodbatlas_alert_configuration.test.project_id}"
alert_configuration_id = "${mongodbatlas_alert_configuration.test.id}"
project_id = mongodbatlas_alert_configuration.test.project_id
alert_configuration_id = mongodbatlas_alert_configuration.test.id
}
`, orgID, projectName)
`, projectID)
}

func configWithThreshold(orgID, projectName string, enabled bool, threshold float64) string {
func configWithThreshold(projectID string, enabled bool, threshold float64) string {
return fmt.Sprintf(`
resource "mongodbatlas_project" "test" {
name = %[2]q
org_id = %[1]q
}
resource "mongodbatlas_alert_configuration" "test" {
project_id = mongodbatlas_project.test.id
project_id = %[1]q
enabled = %[2]t
event_type = "REPLICATION_OPLOG_WINDOW_RUNNING_OUT"
enabled = "%[3]t"

notification {
type_name = "GROUP"
Expand All @@ -196,25 +172,21 @@ func configWithThreshold(orgID, projectName string, enabled bool, threshold floa
threshold_config {
operator = "LESS_THAN"
units = "HOURS"
threshold = %[4]f
threshold = %[3]f
}
}

data "mongodbatlas_alert_configuration" "test" {
project_id = "${mongodbatlas_alert_configuration.test.project_id}"
alert_configuration_id = "${mongodbatlas_alert_configuration.test.id}"
project_id = mongodbatlas_alert_configuration.test.project_id
alert_configuration_id = mongodbatlas_alert_configuration.test.id
}
`, orgID, projectName, enabled, threshold)
`, projectID, enabled, threshold)
}

func configWithOutputs(orgID, projectName, outputLabel string) string {
func configWithOutputs(projectID, outputLabel string) string {
return fmt.Sprintf(`
resource "mongodbatlas_project" "test" {
name = %[2]q
org_id = %[1]q
}
resource "mongodbatlas_alert_configuration" "test" {
project_id = mongodbatlas_project.test.id
project_id = %[1]q

event_type = "NO_PRIMARY"
enabled = true
Expand All @@ -230,42 +202,38 @@ func configWithOutputs(orgID, projectName, outputLabel string) string {
}

data "mongodbatlas_alert_configuration" "test" {
project_id = "${mongodbatlas_alert_configuration.test.project_id}"
alert_configuration_id = "${mongodbatlas_alert_configuration.test.id}"
project_id = mongodbatlas_alert_configuration.test.project_id
alert_configuration_id = mongodbatlas_alert_configuration.test.id

output {
type = "resource_import"
label = %[3]q
label = %[2]q
}
output {
type = "resource_hcl"
label = %[3]q
label = %[2]q
}
}
`, orgID, projectName, outputLabel)
`, projectID, outputLabel)
}

func configWithPagerDutyDS(orgID, projectName, serviceKey string, enabled bool) string {
func configWithPagerDutyDS(projectID, serviceKey string, enabled bool) string {
return fmt.Sprintf(`
resource "mongodbatlas_project" "test" {
name = %[2]q
org_id = %[1]q
}
resource "mongodbatlas_alert_configuration" "test" {
project_id = mongodbatlas_project.test.id
event_type = "NO_PRIMARY"
enabled = "%[4]t"
resource "mongodbatlas_alert_configuration" "test" {
project_id = %[1]q
enabled = "%[3]t"
event_type = "NO_PRIMARY"

notification {
type_name = "PAGER_DUTY"
service_key = %[3]q
delay_min = 0
}
}
notification {
type_name = "PAGER_DUTY"
service_key = %[2]q
delay_min = 0
}
}

data "mongodbatlas_alert_configuration" "test" {
project_id = "${mongodbatlas_alert_configuration.test.project_id}"
alert_configuration_id = "${mongodbatlas_alert_configuration.test.id}"
}
`, orgID, projectName, serviceKey, enabled)
data "mongodbatlas_alert_configuration" "test" {
project_id = mongodbatlas_alert_configuration.test.project_id
alert_configuration_id = mongodbatlas_alert_configuration.test.id
}
`, projectID, serviceKey, enabled)
}
Loading