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

added testfiles for endpoint_security_group_selector #23

Merged
merged 2 commits into from
Dec 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions aci/data_source_aci_fvepselector.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ func dataSourceAciEndpointSecurityGroupSelector() *schema.Resource {
Type: schema.TypeString,
Required: true,
},
"annotation": {
"match_expression": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Required: true,
},
"match_expression": {
"annotation": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Expand Down
1 change: 1 addition & 0 deletions aci/resource_aci_fvepselector.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func resourceAciEndpointSecurityGroupSelectorImport(d *schema.ResourceData, m in
if err != nil {
return nil, err
}
d.Set("endpoint_security_group_dn",GetParentDn(dn,fmt.Sprintf("/epselector-[%s]",fvEPSelector.MatchExpression)))
schemaFilled, err := setEndpointSecurityGroupSelectorAttributes(fvEPSelector, d)
if err != nil {
return nil, err
Expand Down
120 changes: 0 additions & 120 deletions aci/resource_aci_fvepselector_test.go

This file was deleted.

229 changes: 229 additions & 0 deletions testacc/data_source_aci_fvepselector_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
package acctest

import (
"fmt"
"regexp"
"testing"

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

func TestAccAciEndpointSecurityGroupSelectorDataSource_Basic(t *testing.T) {
resourceName := "aci_endpoint_security_group_selector.test"
dataSourceName := "data.aci_endpoint_security_group_selector.test"
rName := makeTestVariable(acctest.RandString(5))
ip, _ := acctest.RandIpAddress("10.30.0.0/17")
ip = fmt.Sprintf("%s/17", ip)
randomParameter := acctest.RandStringFromCharSet(5, "abcdefghijklmnopqrstuvwxyz")
randomValue := acctest.RandString(5)
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAciEndpointSecurityGroupSelectorDestroy,
Steps: []resource.TestStep{
{
Config: CreateEndpointSecurityGroupSelectorDSWithoutRequired(rName, ip, "endpoint_security_group_dn"),
ExpectError: regexp.MustCompile(`Missing required argument`),
},
{
Config: CreateEndpointSecurityGroupSelectorDSWithoutRequired(rName, ip, "matchExpression"),
ExpectError: regexp.MustCompile(`Missing required argument`),
},
{
Config: CreateAccEndpointSecurityGroupSelectorDSConfig(rName, ip),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(dataSourceName, "endpoint_security_group_dn", resourceName, "endpoint_security_group_dn"),
resource.TestCheckResourceAttrPair(dataSourceName, "annotation", resourceName, "annotation"),
resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"),
resource.TestCheckResourceAttrPair(dataSourceName, "name", resourceName, "name"),
resource.TestCheckResourceAttrPair(dataSourceName, "name_alias", resourceName, "name_alias"),
resource.TestCheckResourceAttrPair(dataSourceName, "match_expression", resourceName, "match_expression"),
),
},
{
Config: CreateAccEndpointSecurityGroupSelectorDataSourceUpdateRandomAttr(rName, ip, randomParameter, randomValue),
ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`),
},
{
Config: CreateAccEndpointSecurityGroupDSWithInvalidEndpointSecurityGroup(rName, ip),
ExpectError: regexp.MustCompile(`(.)+ Object may not exists`),
},
{
Config: CreateAccEndpointSecurityGroupDSWithUpdatedResource(rName, ip, "description", randomValue),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"),
),
},
},
})
}

func CreateAccEndpointSecurityGroupDSWithUpdatedResource(rName, ip, key, value string) string {
fmt.Println("=== STEP testing endpoint_security_group_selector data source creation with updated resource")
resource := fmt.Sprintf(`

resource "aci_tenant" "test" {
name = "%s"
}

resource "aci_application_profile" "test" {
name = "%s"
tenant_dn = aci_tenant.test.id
}

resource "aci_endpoint_security_group" "test" {
name = "%s"
application_profile_dn = aci_application_profile.test.id
}

resource "aci_endpoint_security_group_selector" "test" {
endpoint_security_group_dn = aci_endpoint_security_group.test.id
match_expression = "ip=='%s'"
%s = "%s"
}

data "aci_endpoint_security_group_selector" "test" {
endpoint_security_group_dn = aci_endpoint_security_group_selector.test.endpoint_security_group_dn
match_expression = aci_endpoint_security_group_selector.test.match_expression
}
`, rName, rName, rName, ip, key, value)
return resource
}

func CreateAccEndpointSecurityGroupDSWithInvalidEndpointSecurityGroup(rName, ip string) string {
fmt.Println("=== STEP testing endpoint_security_group_selector data source creation with invalid endpoint_security_group_dn")
resource := fmt.Sprintf(`

resource "aci_tenant" "test" {
name = "%s"
}

resource "aci_application_profile" "test" {
name = "%s"
tenant_dn = aci_tenant.test.id
}

resource "aci_endpoint_security_group" "test" {
name = "%s"
application_profile_dn = aci_application_profile.test.id
}

resource "aci_endpoint_security_group_selector" "test" {
endpoint_security_group_dn = aci_endpoint_security_group.test.id
match_expression = "ip=='%s'"
}

data "aci_endpoint_security_group_selector" "test" {
endpoint_security_group_dn = "${aci_endpoint_security_group_selector.test.endpoint_security_group_dn}xyz"
match_expression = aci_endpoint_security_group_selector.test.match_expression
}
`, rName, rName, rName, ip)
return resource
}

func CreateAccEndpointSecurityGroupSelectorDataSourceUpdateRandomAttr(rName, ip, key, value string) string {
fmt.Println("=== STEP testing endpoint_security_group_selector data source creation with random parameter")
resource := fmt.Sprintf(`

resource "aci_tenant" "test" {
name = "%s"
}

resource "aci_application_profile" "test" {
name = "%s"
tenant_dn = aci_tenant.test.id
}

resource "aci_endpoint_security_group" "test" {
name = "%s"
application_profile_dn = aci_application_profile.test.id
}

resource "aci_endpoint_security_group_selector" "test" {
endpoint_security_group_dn = aci_endpoint_security_group.test.id
match_expression = "ip=='%s'"
}

data "aci_endpoint_security_group_selector" "test" {
endpoint_security_group_dn = aci_endpoint_security_group_selector.test.endpoint_security_group_dn
match_expression = aci_endpoint_security_group_selector.test.match_expression
%s = "%s"
}
`, rName, rName, rName, ip, key, value)
return resource
}

func CreateAccEndpointSecurityGroupSelectorDSConfig(rName, ip string) string {
fmt.Println("=== STEP testing endpoint_security_group_selector data source creation with required arguements only")
resource := fmt.Sprintf(`

resource "aci_tenant" "test" {
name = "%s"
}

resource "aci_application_profile" "test" {
name = "%s"
tenant_dn = aci_tenant.test.id
}

resource "aci_endpoint_security_group" "test" {
name = "%s"
application_profile_dn = aci_application_profile.test.id
}

resource "aci_endpoint_security_group_selector" "test" {
endpoint_security_group_dn = aci_endpoint_security_group.test.id
match_expression = "ip=='%s'"
}

data "aci_endpoint_security_group_selector" "test" {
endpoint_security_group_dn = aci_endpoint_security_group_selector.test.endpoint_security_group_dn
match_expression = aci_endpoint_security_group_selector.test.match_expression
}
`, rName, rName, rName, ip)
return resource
}

func CreateEndpointSecurityGroupSelectorDSWithoutRequired(rName, ip, attrName string) string {
fmt.Println("=== STEP Basic: testing endpoint_security_group_selector data source creation without ", attrName)
rBlock := `

resource "aci_tenant" "test" {
name = "%s"
}

resource "aci_application_profile" "test" {
name = "%s"
tenant_dn = aci_tenant.test.id
}

resource "aci_endpoint_security_group" "test" {
name = "%s"
application_profile_dn = aci_application_profile.test.id
}

resource "aci_endpoint_security_group_selector" "test" {
endpoint_security_group_dn = aci_endpoint_security_group.test.id
match_expression = "ip=='%s'"
}

`
switch attrName {
case "endpoint_security_group_dn":
rBlock += `
data "aci_endpoint_security_group_selector" "test" {
# endpoint_security_group_dn = aci_endpoint_security_group_selector.test.endpoint_security_group_dn
match_expression = aci_endpoint_security_group_selector.test.match_expression
}
`
case "matchExpression":
rBlock += `
data "aci_endpoint_security_group_selector" "test" {
endpoint_security_group_dn = aci_endpoint_security_group_selector.test.endpoint_security_group_dn
# match_expression = aci_endpoint_security_group_selector.test.match_expression
}
`
}
return fmt.Sprintf(rBlock, rName, rName, rName, ip)
}
Loading