Skip to content

Commit

Permalink
refactor vault cluster test config to use variable
Browse files Browse the repository at this point in the history
vault cluster
  • Loading branch information
bcmdarroch committed Jun 18, 2021
1 parent d9ed3fc commit bc4aa53
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions internal/provider/resource_vault_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,39 @@ import (
"github.com/hashicorp/terraform-provider-hcp/internal/clients"
)

var testAccVaultClusterConfig = `
resource "hcp_hvn" "test" {
hvn_id = "test-hvn"
cloud_provider = "aws"
region = "us-west-2"
}
var vaultCluster = `
resource "hcp_vault_cluster" "test" {
cluster_id = "test-vault-cluster"
hvn_id = hcp_hvn.test.hvn_id
tier = "dev"
}
`

data "hcp_vault_cluster" "test" {
cluster_id = hcp_vault_cluster.test.cluster_id
// sets public_endpoint to true
var updatedVaultCluster = `
resource "hcp_vault_cluster" "test" {
cluster_id = "test-vault-cluster"
hvn_id = hcp_hvn.test.hvn_id
tier = "dev"
public_endpoint = true
}
`

var testAccUpdatedVaultClusterConfig = `
func setTestAccVaultClusterConfig(vaultCluster string) string {
return fmt.Sprintf(`
resource "hcp_hvn" "test" {
hvn_id = "test-hvn"
cloud_provider = "aws"
region = "us-west-2"
}
resource "hcp_vault_cluster" "test" {
cluster_id = "test-vault-cluster"
hvn_id = hcp_hvn.test.hvn_id
tier = "dev"
public_endpoint = true
}
%s
data "hcp_vault_cluster" "test" {
cluster_id = hcp_vault_cluster.test.cluster_id
}
`
`, vaultCluster)
}

// This includes tests against both the resource and the corresponding datasource
// to shorten testing time.
Expand All @@ -60,7 +57,7 @@ func TestAccVaultCluster(t *testing.T) {
Steps: []resource.TestStep{
// Tests create
{
Config: testConfig(testAccVaultClusterConfig),
Config: testConfig(setTestAccVaultClusterConfig(vaultCluster)),
Check: resource.ComposeTestCheckFunc(
testAccCheckVaultClusterExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "cluster_id", "test-vault-cluster"),
Expand Down Expand Up @@ -95,7 +92,7 @@ func TestAccVaultCluster(t *testing.T) {
},
// This step is a subsequent terraform apply that verifies that no state is modified.
{
Config: testConfig(testAccVaultClusterConfig),
Config: testConfig(setTestAccVaultClusterConfig(vaultCluster)),
Check: resource.ComposeTestCheckFunc(
testAccCheckVaultClusterExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "cluster_id", "test-vault-cluster"),
Expand All @@ -116,7 +113,7 @@ func TestAccVaultCluster(t *testing.T) {
},
// Tests datasource
{
Config: testConfig(testAccVaultClusterConfig),
Config: testConfig(setTestAccVaultClusterConfig(vaultCluster)),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(resourceName, "cluster_id", dataSourceName, "cluster_id"),
resource.TestCheckResourceAttrPair(resourceName, "hvn_id", dataSourceName, "hvn_id"),
Expand All @@ -137,7 +134,7 @@ func TestAccVaultCluster(t *testing.T) {
},
// This step verifies the successful update of updatable fields.
{
Config: testConfig(testAccUpdatedVaultClusterConfig),
Config: testConfig(setTestAccVaultClusterConfig(updatedVaultCluster)),
Check: resource.ComposeTestCheckFunc(
testAccCheckVaultClusterExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "public_endpoint", "true"),
Expand Down

0 comments on commit bc4aa53

Please sign in to comment.