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 test files for 02-02-22 #142

Merged
merged 1 commit into from
Feb 2, 2022
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
161 changes: 161 additions & 0 deletions testacc/data_source_aci_configexportp_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
package testacc

import (
"fmt"
"regexp"
"testing"

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

func TestAccAciConfigurationExportPolicyDataSource_Basic(t *testing.T) {
resourceName := "aci_configuration_export_policy.test"
dataSourceName := "data.aci_configuration_export_policy.test"
randomParameter := acctest.RandStringFromCharSet(10, "abcdefghijklmnopqrstuvwxyz")
randomValue := acctest.RandString(10)
rName := makeTestVariable(acctest.RandString(5))

resource.ParallelTest(t, resource.TestCase{
PreCheck: func(){ testAccPreCheck(t) },
ProviderFactories: testAccProviders,
CheckDestroy: testAccCheckAciConfigurationExportPolicyDestroy,
Steps: []resource.TestStep{

{
Config: CreateConfigurationExportPolicyDSWithoutRequired(rName, "name"),
ExpectError: regexp.MustCompile(`Missing required argument`),
},
{
Config: CreateAccConfigurationExportPolicyConfigDataSource(rName),
Check: resource.ComposeTestCheckFunc(

resource.TestCheckResourceAttrPair(dataSourceName, "name", resourceName, "name"),
resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"),
resource.TestCheckResourceAttrPair(dataSourceName, "annotation", resourceName, "annotation"),
resource.TestCheckResourceAttrPair(dataSourceName, "name_alias", resourceName, "name_alias"),
resource.TestCheckResourceAttrPair(dataSourceName, "admin_st", resourceName, "admin_st"),
resource.TestCheckResourceAttrPair(dataSourceName, "format", resourceName, "format"),
resource.TestCheckResourceAttrPair(dataSourceName, "include_secure_fields", resourceName, "include_secure_fields"),
resource.TestCheckResourceAttrPair(dataSourceName, "max_snapshot_count", resourceName, "max_snapshot_count"),
resource.TestCheckResourceAttrPair(dataSourceName, "snapshot", resourceName, "snapshot"),
resource.TestCheckResourceAttrPair(dataSourceName, "target_dn", resourceName, "target_dn"),

),
},
{
Config: CreateAccConfigurationExportPolicyDataSourceUpdate(rName, randomParameter, randomValue),
ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`),
},

{
Config: CreateAccConfigurationExportPolicyDSWithInvalidName(rName),
ExpectError: regexp.MustCompile(`(.)+ Object may not exists`),
},
{
Config: CreateAccConfigurationExportPolicyDataSourceUpdatedResource(rName, "annotation", "orchestrator:terraform-testacc"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(dataSourceName, "annotation", resourceName, "annotation"),
),
},
},
})
}


func CreateAccConfigurationExportPolicyConfigDataSource(rName string) string {
fmt.Println("=== STEP testing configuration_export_policy Data Source with required arguments only")
resource := fmt.Sprintf(`

resource "aci_configuration_export_policy" "test" {

name = "%s"
}

data "aci_configuration_export_policy" "test" {

name = aci_configuration_export_policy.test.name
depends_on = [ aci_configuration_export_policy.test ]
}
`, rName)
return resource
}

func CreateConfigurationExportPolicyDSWithoutRequired(rName, attrName string) string {
fmt.Println("=== STEP Basic: testing configuration_export_policy Data Source without ",attrName)
rBlock := `

resource "aci_configuration_export_policy" "test" {

name = "%s"
}
`
switch attrName {
case "name":
rBlock += `
data "aci_configuration_export_policy" "test" {

# name = aci_configuration_export_policy.test.name
depends_on = [ aci_configuration_export_policy.test ]
}
`
}
return fmt.Sprintf(rBlock,rName)
}


func CreateAccConfigurationExportPolicyDSWithInvalidName(rName string) string {
fmt.Println("=== STEP testing configuration_export_policy Data Source with invalid name")
resource := fmt.Sprintf(`

resource "aci_configuration_export_policy" "test" {

name = "%s"
}

data "aci_configuration_export_policy" "test" {

name = "${aci_configuration_export_policy.test.name}_invalid"
depends_on = [ aci_configuration_export_policy.test ]
}
`, rName)
return resource
}

func CreateAccConfigurationExportPolicyDataSourceUpdate(rName, key, value string) string {
fmt.Println("=== STEP testing configuration_export_policy Data Source with random attribute")
resource := fmt.Sprintf(`

resource "aci_configuration_export_policy" "test" {

name = "%s"
}

data "aci_configuration_export_policy" "test" {

name = aci_configuration_export_policy.test.name
%s = "%s"
depends_on = [ aci_configuration_export_policy.test ]
}
`, rName,key,value)
return resource
}

func CreateAccConfigurationExportPolicyDataSourceUpdatedResource(rName, key, value string) string {
fmt.Println("=== STEP testing configuration_export_policy Data Source with updated resource")
resource := fmt.Sprintf(`

resource "aci_configuration_export_policy" "test" {

name = "%s"
%s = "%s"
}

data "aci_configuration_export_policy" "test" {

name = aci_configuration_export_policy.test.name
depends_on = [ aci_configuration_export_policy.test ]
}
`, rName,key,value)
return resource
}
219 changes: 219 additions & 0 deletions testacc/data_source_aci_spanspanlbl_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
package testacc

import (
"fmt"
"regexp"
"testing"

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

func TestAccAciSPANSourcedestinationGroupMatchLabelDataSource_Basic(t *testing.T) {
resourceName := "aci_span_sourcedestination_group_match_label.test"
dataSourceName := "data.aci_span_sourcedestination_group_match_label.test"
randomParameter := acctest.RandStringFromCharSet(10, "abcdefghijklmnopqrstuvwxyz")
randomValue := acctest.RandString(10)
rName := makeTestVariable(acctest.RandString(5))

fvTenantName := makeTestVariable(acctest.RandString(5))
spanSrcGrpName := makeTestVariable(acctest.RandString(5))
resource.ParallelTest(t, resource.TestCase{
PreCheck: func(){ testAccPreCheck(t) },
ProviderFactories: testAccProviders,
CheckDestroy: testAccCheckAciSPANSourcedestinationGroupMatchLabelDestroy,
Steps: []resource.TestStep{
{
Config: CreateSPANSourcedestinationGroupMatchLabelDSWithoutRequired(fvTenantName, spanSrcGrpName, rName,"span_source_group_dn"),
ExpectError: regexp.MustCompile(`Missing required argument`),
},
{
Config: CreateSPANSourcedestinationGroupMatchLabelDSWithoutRequired(fvTenantName, spanSrcGrpName, rName, "name"),
ExpectError: regexp.MustCompile(`Missing required argument`),
},
{
Config: CreateAccSPANSourcedestinationGroupMatchLabelConfigDataSource(fvTenantName, spanSrcGrpName, rName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(dataSourceName, "span_source_group_dn", resourceName, "span_source_group_dn",),
resource.TestCheckResourceAttrPair(dataSourceName, "name", resourceName, "name"),
resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"),
resource.TestCheckResourceAttrPair(dataSourceName, "annotation", resourceName, "annotation"),
resource.TestCheckResourceAttrPair(dataSourceName, "name_alias", resourceName, "name_alias"),
resource.TestCheckResourceAttrPair(dataSourceName, "tag", resourceName, "tag"),

),
},
{
Config: CreateAccSPANSourcedestinationGroupMatchLabelDataSourceUpdate(fvTenantName, spanSrcGrpName, rName, randomParameter, randomValue),
ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`),
},

{
Config: CreateAccSPANSourcedestinationGroupMatchLabelDSWithInvalidParentDn(fvTenantName, spanSrcGrpName, rName),
ExpectError: regexp.MustCompile(`(.)+ Object may not exists`),
},

{
Config: CreateAccSPANSourcedestinationGroupMatchLabelDataSourceUpdatedResource(fvTenantName, spanSrcGrpName, rName, "annotation", "orchestrator:terraform-testacc"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(dataSourceName, "annotation", resourceName, "annotation"),
),
},
},
})
}


func CreateAccSPANSourcedestinationGroupMatchLabelConfigDataSource(fvTenantName, spanSrcGrpName, rName string) string {
fmt.Println("=== STEP testing span_sourcedestination_group_match_label Data Source with required arguments only")
resource := fmt.Sprintf(`

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

}

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

resource "aci_span_sourcedestination_group_match_label" "test" {
span_source_group_dn = aci_span_source_group.test.id
name = "%s"
}

data "aci_span_sourcedestination_group_match_label" "test" {
span_source_group_dn = aci_span_source_group.test.id
name = aci_span_sourcedestination_group_match_label.test.name
depends_on = [ aci_span_sourcedestination_group_match_label.test ]
}
`, fvTenantName, spanSrcGrpName, rName)
return resource
}

func CreateSPANSourcedestinationGroupMatchLabelDSWithoutRequired(fvTenantName, spanSrcGrpName, rName, attrName string) string {
fmt.Println("=== STEP Basic: testing span_sourcedestination_group_match_label Data Source without ",attrName)
rBlock := `

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

}

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

resource "aci_span_sourcedestination_group_match_label" "test" {
span_source_group_dn = aci_span_source_group.test.id
name = "%s"
}
`
switch attrName {
case "span_source_group_dn":
rBlock += `
data "aci_span_sourcedestination_group_match_label" "test" {
# span_source_group_dn = aci_span_source_group.test.id
name = aci_span_sourcedestination_group_match_label.test.name
depends_on = [ aci_span_sourcedestination_group_match_label.test ]
}
`
case "name":
rBlock += `
data "aci_span_sourcedestination_group_match_label" "test" {
span_source_group_dn = aci_span_source_group.test.id
# name = aci_span_sourcedestination_group_match_label.test.name
depends_on = [ aci_span_sourcedestination_group_match_label.test ]
}
`
}
return fmt.Sprintf(rBlock,fvTenantName, spanSrcGrpName, rName)
}

func CreateAccSPANSourcedestinationGroupMatchLabelDSWithInvalidParentDn(fvTenantName, spanSrcGrpName, rName string) string {
fmt.Println("=== STEP testing span_sourcedestination_group_match_label Data Source with Invalid Parent Dn")
resource := fmt.Sprintf(`

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

}

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

resource "aci_span_sourcedestination_group_match_label" "test" {
span_source_group_dn = aci_span_source_group.test.id
name = "%s"
}

data "aci_span_sourcedestination_group_match_label" "test" {
span_source_group_dn = aci_span_source_group.test.id
name = "${aci_span_sourcedestination_group_match_label.test.name}_invalid"
depends_on = [ aci_span_sourcedestination_group_match_label.test ]
}
`, fvTenantName, spanSrcGrpName, rName)
return resource
}

func CreateAccSPANSourcedestinationGroupMatchLabelDataSourceUpdate(fvTenantName, spanSrcGrpName, rName, key, value string) string {
fmt.Println("=== STEP testing span_sourcedestination_group_match_label Data Source with random attribute")
resource := fmt.Sprintf(`

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

}

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

resource "aci_span_sourcedestination_group_match_label" "test" {
span_source_group_dn = aci_span_source_group.test.id
name = "%s"
}

data "aci_span_sourcedestination_group_match_label" "test" {
span_source_group_dn = aci_span_source_group.test.id
name = aci_span_sourcedestination_group_match_label.test.name
%s = "%s"
depends_on = [ aci_span_sourcedestination_group_match_label.test ]
}
`, fvTenantName, spanSrcGrpName, rName,key,value)
return resource
}

func CreateAccSPANSourcedestinationGroupMatchLabelDataSourceUpdatedResource(fvTenantName, spanSrcGrpName, rName, key, value string) string {
fmt.Println("=== STEP testing span_sourcedestination_group_match_label Data Source with updated resource")
resource := fmt.Sprintf(`

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

}

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

resource "aci_span_sourcedestination_group_match_label" "test" {
span_source_group_dn = aci_span_source_group.test.id
name = "%s"
%s = "%s"
}

data "aci_span_sourcedestination_group_match_label" "test" {
span_source_group_dn = aci_span_source_group.test.id
name = aci_span_sourcedestination_group_match_label.test.name
depends_on = [ aci_span_sourcedestination_group_match_label.test ]
}
`, fvTenantName, spanSrcGrpName, rName,key,value)
return resource
}
Loading