Skip to content

Commit

Permalink
chore: Reuses project in tests - project_ip_access_list (#2067)
Browse files Browse the repository at this point in the history
* TestAccProjectIPAccesslist_SettingIPAddress

* join data source tests with resource ones

* mig tests for resource no data sources

* parallel tests

* common checks

* TestAccProjectIPAccessList_settingMultiple

* remove duplicated tests, they don't belong to project resource

* configWithIPAddress

* configWithCIDRBlock

* configWithAWSSecurityGroup

* configWithMultiple

* use mig global project

* importStateIDFunc

* checkDestroy

* checkExists

* fix mig test

* improve comment
  • Loading branch information
lantoli authored Mar 25, 2024
1 parent 92831dd commit 13e4c80
Show file tree
Hide file tree
Showing 8 changed files with 315 additions and 663 deletions.
129 changes: 0 additions & 129 deletions internal/service/project/resource_project_migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,132 +190,3 @@ func TestMigProjectRS_withLimits(t *testing.T) {
},
})
}

func TestMigProjectRSProjectIPAccesslist_withSettingIPAddress(t *testing.T) {
var (
resourceName = "mongodbatlas_project_ip_access_list.test"
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acc.RandomProjectName()
ipAddress = acc.RandomIP(179, 154, 226)
comment = fmt.Sprintf("TestAcc for ipAddress (%s)", ipAddress)
)

resource.Test(t, resource.TestCase{
PreCheck: func() { mig.PreCheckBasic(t) },
CheckDestroy: acc.CheckDestroyProjectIPAccessList,
Steps: []resource.TestStep{
{
ExternalProviders: mig.ExternalProviders(),
Config: acc.ConfigProjectIPAccessListWithIPAddress(orgID, projectName, ipAddress, comment),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
resource.TestCheckResourceAttrSet(resourceName, "ip_address"),
resource.TestCheckResourceAttrSet(resourceName, "comment"),
resource.TestCheckResourceAttr(resourceName, "ip_address", ipAddress),
resource.TestCheckResourceAttr(resourceName, "comment", comment),
),
},
{
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
Config: acc.ConfigProjectIPAccessListWithIPAddress(orgID, projectName, ipAddress, comment),
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
acc.DebugPlan(),
plancheck.ExpectEmptyPlan(),
},
},
},
},
})
}

func TestMigProjectRSProjectIPAccessList_withSettingCIDRBlock(t *testing.T) {
var (
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
resourceName = "mongodbatlas_project_ip_access_list.test"
projectName = acc.RandomProjectName()
cidrBlock = acc.RandomIP(179, 154, 226) + "/32"
comment = fmt.Sprintf("TestAcc for cidrBlock (%s)", cidrBlock)
)

resource.Test(t, resource.TestCase{
PreCheck: func() { mig.PreCheckBasic(t) },
CheckDestroy: acc.CheckDestroyProjectIPAccessList,
Steps: []resource.TestStep{
{
ExternalProviders: mig.ExternalProviders(),
Config: acc.ConfigProjectIPAccessListWithCIDRBlock(orgID, projectName, cidrBlock, comment),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
resource.TestCheckResourceAttrSet(resourceName, "cidr_block"),
resource.TestCheckResourceAttrSet(resourceName, "comment"),
resource.TestCheckResourceAttr(resourceName, "cidr_block", cidrBlock),
resource.TestCheckResourceAttr(resourceName, "comment", comment),
),
},
{
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
Config: acc.ConfigProjectIPAccessListWithCIDRBlock(orgID, projectName, cidrBlock, comment),
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
acc.DebugPlan(),
plancheck.ExpectEmptyPlan(),
},
},
},
},
})
}

func TestMigProjectRSProjectIPAccessList_withMultipleSetting(t *testing.T) {
var (
resourceName = "mongodbatlas_project_ip_access_list.test_1"
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
accessList = make([]map[string]string, 0)
ipWhiteListCount = 20
projectName = acc.RandomProjectName()
)

for i := 0; i < ipWhiteListCount; i++ {
entry := make(map[string]string)
entryName := ""
ipAddr := ""

if i%2 == 0 {
entryName = "cidr_block"
entry["cidr_block"] = acc.RandomIP(byte(i), 2, 3) + "/32"
ipAddr = entry["cidr_block"]
} else {
entryName = "ip_address"
entry["ip_address"] = acc.RandomIP(byte(i), 2, 3)
ipAddr = entry["ip_address"]
}
entry["comment"] = fmt.Sprintf("TestAcc for %s (%s)", entryName, ipAddr)

accessList = append(accessList, entry)
}

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { mig.PreCheckBasic(t) },
CheckDestroy: acc.CheckDestroyProjectIPAccessList,
Steps: []resource.TestStep{
{
ExternalProviders: mig.ExternalProviders(),
Config: acc.ConfigProjectIPAccessListWithMultiple(projectName, orgID, accessList, false),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
),
},
{
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
Config: acc.ConfigProjectIPAccessListWithMultiple(projectName, orgID, accessList, false),
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
acc.DebugPlan(),
plancheck.ExpectEmptyPlan(),
},
},
},
},
})
}

This file was deleted.

Loading

0 comments on commit 13e4c80

Please sign in to comment.