Skip to content

Commit

Permalink
test: fix and improve acceptance tests (#390)
Browse files Browse the repository at this point in the history
  • Loading branch information
wai-wong-edb authored Nov 8, 2023
1 parent 400e7f9 commit f897b77
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
1 change: 1 addition & 0 deletions pkg/provider/resource_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ func (c *clusterResource) Schema(ctx context.Context, req resource.SchemaRequest
},
"name": schema.StringAttribute{
MarkdownDescription: "Name.",
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()},
},
Expand Down
4 changes: 4 additions & 0 deletions pkg/provider/resource_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func TestAccResourceCluster_basic(t *testing.T) {
resource.TestCheckResourceAttr("biganimal_cluster.acctest_cluster", "backup_retention_period", "10d"),
resource.TestCheckResourceAttr("biganimal_cluster.acctest_cluster", "cluster_architecture.id", "ha"),
resource.TestCheckResourceAttr("biganimal_cluster.acctest_cluster", "cluster_architecture.nodes", "2"),
resource.TestCheckResourceAttr("biganimal_cluster.acctest_cluster", "cluster_architecture.name", "Primary/Standby High Availability"),
),
},
},
Expand Down Expand Up @@ -103,6 +104,7 @@ func clusterResourceConfig(cluster_name, projectID, provider, region string) str
pg_version = "15"
private_networking = false
read_only_connections = false
superuser_access = true
}`, cluster_name, projectID, provider, region)
}

Expand All @@ -118,6 +120,7 @@ func clusterResourceConfigForUpdate(cluster_name, projectID, provider, region st
cluster_architecture {
id = "ha"
nodes = 2
name = "Primary/Standby High Availability"
}
csp_auth = true
Expand Down Expand Up @@ -153,5 +156,6 @@ func clusterResourceConfigForUpdate(cluster_name, projectID, provider, region st
pg_version = "15"
private_networking = false
read_only_connections = false
superuser_access = true
}`, cluster_name, projectID, provider, region)
}
22 changes: 13 additions & 9 deletions pkg/provider/resource_pgd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"testing"
"time"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)
Expand All @@ -12,10 +13,13 @@ func TestAccResourcePGD_basic(t *testing.T) {
var (
acc_env_vars_checklist = []string{
"BA_TF_ACC_VAR_pgd_project_id",
"BA_TF_ACC_VAR_pgd_name",
"BA_TF_ACC_VAR_pgd_region_dg1",
"BA_TF_ACC_VAR_pgd_provider_dg1",
}
accPGDName = os.Getenv("BA_TF_ACC_VAR_pgd_name")
accProjectID = os.Getenv("BA_TF_ACC_VAR_pgd_project_id")
accPgdClusterName = fmt.Sprintf("acctest_pgd_cluster_basic_%v", time.Now().Unix())
accProjectID = os.Getenv("BA_TF_ACC_VAR_pgd_project_id")
accRegionDg1 = os.Getenv("BA_TF_ACC_VAR_pgd_region_dg1")
accProviderDg1 = os.Getenv("BA_TF_ACC_VAR_pgd_provider_dg1")
)

resource.Test(t, resource.TestCase{
Expand All @@ -26,18 +30,18 @@ func TestAccResourcePGD_basic(t *testing.T) {
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
Config: pgdResourceConfig(accPGDName, accProjectID),
Config: pgdResourceConfig(accPgdClusterName, accProjectID, accProviderDg1, accRegionDg1),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("biganimal_pgd.acctest_pgd", "project_id", accProjectID),
resource.TestCheckResourceAttr("biganimal_pgd.acctest_pgd", "cluster_name", accPGDName),
resource.TestCheckResourceAttr("biganimal_pgd.acctest_pgd", "cluster_name", accPgdClusterName),
resource.TestCheckResourceAttrSet("biganimal_pgd.acctest_pgd", "cluster_id"),
),
},
},
})
}

func pgdResourceConfig(cluster_name, projectID string) string {
func pgdResourceConfig(cluster_name, projectID, providerDg1, regionDg1 string) string {
return fmt.Sprintf(`resource "biganimal_pgd" "acctest_pgd" {
cluster_name = "%s"
project_id = "%s"
Expand Down Expand Up @@ -86,10 +90,10 @@ func pgdResourceConfig(cluster_name, projectID string) string {
}
private_networking = false
cloud_provider = {
cloud_provider_id = "azure"
cloud_provider_id = "%s"
}
region = {
region_id = "northeurope"
region_id = "%s"
}
maintenance_window = {
is_enabled = true
Expand All @@ -98,5 +102,5 @@ func pgdResourceConfig(cluster_name, projectID string) string {
}
},
]
}`, cluster_name, projectID)
}`, cluster_name, projectID, providerDg1, regionDg1)
}

0 comments on commit f897b77

Please sign in to comment.