forked from CiscoDevNet/terraform-provider-aci
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Vishwa Patel <[email protected]>
- Loading branch information
1 parent
83ef21c
commit 937de0e
Showing
2 changed files
with
615 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
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 TestAccAciTabooContractDataSource_Basic(t *testing.T) { | ||
resourceName := "aci_taboo_contract.test" | ||
dataSourceName := "data.aci_taboo_contract.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: testAccCheckAciTabooContractDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: CreateTabooContractDSWithoutName(rName), | ||
ExpectError: regexp.MustCompile(`Missing required argument`), | ||
}, | ||
{ | ||
Config: CreateTabooContractDSWithoutTenantdn(rName), | ||
ExpectError: regexp.MustCompile(`Missing required argument`), | ||
}, | ||
{ | ||
Config: CreateAccTabooContractConfigDataSource(rName, rName), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrPair(dataSourceName, "tenant_dn", resourceName, "tenant_dn"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "annotation", resourceName, "annotation"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "name_alias", resourceName, "name_alias"), | ||
), | ||
}, | ||
{ | ||
Config: CreateAccTabooContractDataSourceUpdate(rName, rName, randomParameter, randomValue), | ||
ExpectError: regexp.MustCompile(`An argument named (.)+ is not expected here.`), | ||
}, | ||
|
||
{ | ||
Config: CreateAccTabooContractDSWithInvalidParentDn(rName, rName), | ||
ExpectError: regexp.MustCompile(`(.)+ Object may not exists`), | ||
}, | ||
{ | ||
Config: CreateAccTabooContractDataSourceUpdate(rName, rName, "annotation", "orchestrator:terraform-testacc"), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrPair(dataSourceName, "annotation", resourceName, "annotation"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func CreateAccTabooContractConfigDataSource(fvTenantName, rName string) string { | ||
fmt.Println("=== STEP testing taboo_contract creation with required arguements only") | ||
resource := fmt.Sprintf(` | ||
resource "aci_tenant" "test" { | ||
name = "%s" | ||
description = "tenant created while acceptance testing" | ||
} | ||
resource "aci_taboo_contract" "test" { | ||
tenant_dn = aci_tenant.test.id | ||
name = "%s" | ||
} | ||
data "aci_taboo_contract" "test" { | ||
tenant_dn = aci_tenant.test.id | ||
name = aci_taboo_contract.test.name | ||
depends_on = [ | ||
aci_taboo_contract.test | ||
] | ||
} | ||
`, fvTenantName, rName) | ||
return resource | ||
} | ||
func CreateAccTabooContractDSWithInvalidParentDn(fvTenantName, rName string) string { | ||
fmt.Println("=== STEP testing taboo_contract creation with Invalid Parent Dn") | ||
resource := fmt.Sprintf(` | ||
resource "aci_tenant" "test" { | ||
name = "%s" | ||
description = "tenant created while acceptance testing" | ||
} | ||
resource "aci_taboo_contract" "test" { | ||
tenant_dn = aci_tenant.test.id | ||
name = "%s" | ||
} | ||
data "aci_taboo_contract" "test" { | ||
tenant_dn = aci_tenant.test.id | ||
name = "${aci_taboo_contract.test.name}_invalid" | ||
depends_on = [ | ||
aci_taboo_contract.test | ||
] | ||
} | ||
`, fvTenantName, rName) | ||
return resource | ||
} | ||
|
||
func CreateAccTabooContractDataSourceUpdate(fvTenantName, rName, key, value string) string { | ||
fmt.Println("=== STEP testing taboo_contract creation with required arguements only") | ||
resource := fmt.Sprintf(` | ||
resource "aci_tenant" "test" { | ||
name = "%s" | ||
description = "tenant created while acceptance testing" | ||
} | ||
resource "aci_taboo_contract" "test" { | ||
tenant_dn = aci_tenant.test.id | ||
name = "%s" | ||
} | ||
data "aci_taboo_contract" "test" { | ||
tenant_dn = aci_tenant.test.id | ||
name = aci_taboo_contract.test.name | ||
%s = "%s" | ||
depends_on = [ | ||
aci_taboo_contract.test | ||
] | ||
} | ||
`, fvTenantName, rName, key, value) | ||
return resource | ||
} | ||
|
||
func CreateTabooContractDSWithoutName(rName string) string { | ||
fmt.Println("=== STEP Basic: testing Taboo Contract data source reading without giving name") | ||
resource := fmt.Sprintf(` | ||
resource "aci_tenant" "test" { | ||
name = "%s" | ||
description = "tenant created while acceptance testing" | ||
} | ||
resource "aci_taboo_contract" "test" { | ||
tenant_dn = aci_tenant.test.id | ||
name = "%s" | ||
} | ||
data "aci_taboo_contract" "test" { | ||
tenant_dn = aci_tenant.test.id | ||
depends_on = [ | ||
aci_taboo_contract.test | ||
] | ||
} | ||
`, rName, rName) | ||
return resource | ||
} | ||
|
||
func CreateTabooContractDSWithoutTenantdn(rName string) string { | ||
fmt.Println("=== STEP Basic: testing Taboo Contract data source reading without giving name") | ||
resource := fmt.Sprintf(` | ||
resource "aci_tenant" "test" { | ||
name = "%s" | ||
description = "tenant created while acceptance testing" | ||
} | ||
resource "aci_taboo_contract" "test" { | ||
tenant_dn = aci_tenant.test.id | ||
name = "%s" | ||
} | ||
data "aci_taboo_contract" "test" { | ||
name = aci_taboo_contract.test.name | ||
depends_on = [ | ||
aci_taboo_contract.test | ||
] | ||
} | ||
`, rName, rName) | ||
return resource | ||
} |
Oops, something went wrong.