Skip to content

Commit

Permalink
[AV-65762]Fix allowlist acceptance tests (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
SaicharanCB authored Nov 29, 2023
1 parent 5819a61 commit 593cafc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 21 deletions.
24 changes: 5 additions & 19 deletions internal/resources/acceptance_tests/allowlist_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestAccAllowListTestCases(t *testing.T) {
resourceReference := "capella_cluster." + resourceName
projectResourceName := "terraform_project"
projectResourceReference := "capella_project." + projectResourceName
cidr := "10.0.2.0/23"
cidr := "10.250.250.0/23"

testCfg := acctest.Cfg
resource.Test(t, resource.TestCase{
Expand Down Expand Up @@ -70,7 +70,7 @@ func TestAccAllowListTestCases(t *testing.T) {

//Add SameIP (this ip is same as the one added with required fields teststep and the config of that test step is retained)
{
Config: testAccAddIPSameIP(testCfg, "add_allowlist_sameIP", "10.1.4.1/32"),
Config: testAccAddIPSameIP(testCfg, "add_allowlist_sameIP", "10.1.1.1/32"),
ExpectError: regexp.MustCompile("CIDR provided already exists for the cluster"),
},
//Delete expired IP
Expand All @@ -93,7 +93,7 @@ func TestAccAllowedIPDeleteIP(t *testing.T) {
clusterResourceReference := "capella_cluster." + clusterName
projectResourceName := "terraform_project"
projectResourceReference := "capella_project." + projectResourceName
cidr := "10.3.2.0/23"
cidr := "10.250.250.0/23"

testCfg := acctest.Cfg
resource.Test(t, resource.TestCase{
Expand Down Expand Up @@ -172,7 +172,7 @@ resource "capella_cluster" "%[2]s" {
organization_id = var.organization_id
project_id = %[4]s.id
name = "Terraform Acceptance Test Cluster"
description = "My first test cluster for multiple services"
description = "terraform acceptance test cluster"
couchbase_server = {
version = "7.1"
}
Expand Down Expand Up @@ -288,20 +288,6 @@ resource "capella_allowlist" "%[2]s_1" {
comment = "terraform allow list acceptance test"
expires_at = "%[4]s"
}
output "%[2]s_2"{
value = capella_allowlist.%[2]s_2
}
resource "capella_allowlist" "%[2]s_2" {
organization_id = var.organization_id
project_id = capella_project.terraform_project.id
cluster_id = capella_cluster.new_cluster.id
cidr = "%[3]s"
comment = "terraform allow list acceptance test"
expires_at = "%[4]s"
}
`, cfg, resourceName, cidr, expiryTime)
}

Expand Down Expand Up @@ -376,7 +362,7 @@ func testAccDeleteAllowIP(clusterResourceReference, projectResourceReference, al
host := os.Getenv("TF_VAR_host")
orgid := os.Getenv("TF_VAR_organization_id")
authToken := os.Getenv("TF_VAR_auth_token")
url := fmt.Sprintf("%s/v4/organizations/%s/projects/%s/clusters/%s//allowedcidrs/%s", host, orgid, projectState["id"], clusterState["id"], allowListState["id"])
url := fmt.Sprintf("%s/v4/organizations/%s/projects/%s/clusters/%s/allowedcidrs/%s", host, orgid, projectState["id"], clusterState["id"], allowListState["id"])
cfg := api.EndpointCfg{Url: url, Method: http.MethodDelete, SuccessStatus: http.StatusNoContent}
_, err = data.Client.Execute(
cfg,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1575,7 +1575,16 @@ func testAccDeleteCluster(clusterResourceReference, projectResourceReference str
if err != nil {
return err
}

//get the cluster state
err = checkClusterStatus(data, context.Background(), orgid, projectState["id"], clusterState["id"])
resourceNotFound, errString := api.CheckResourceNotFoundError(err)
if !resourceNotFound {
return fmt.Errorf(errString)
}
fmt.Printf("successfully deleted")
return nil

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import (
"net/http"
"os"
"terraform-provider-capella/internal/api"
"testing"

"terraform-provider-capella/internal/provider"
acctest "terraform-provider-capella/internal/testing"
"testing"

"github.com/hashicorp/terraform-plugin-framework/providerserver"
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
Expand Down

0 comments on commit 593cafc

Please sign in to comment.