Skip to content

Commit

Permalink
Add Go VCR Peering and import test
Browse files Browse the repository at this point in the history
  • Loading branch information
tbroden84 committed Dec 19, 2024
1 parent 7c26360 commit 1dd3da1
Show file tree
Hide file tree
Showing 4 changed files with 391 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cloudamqp/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ func cloudamqpResourceTest(t *testing.T, c resource.TestCase) {
fmt.Println("SKIP: PUT /api/instances/{id}/config", i.Request.URL, "error:", errStr)
i.DiscardOnSave = true
}
case i.Response.Code == 400 && i.Request.Method == "DELETE" &&
regexp.MustCompile(`api/vpcs/\d+/vpc-peering/pcx-[0-9].*$`).MatchString(i.Request.URL):
fmt.Println("SKIP: GET /api/vpcs/{id}/security/vpc-peering/request", i.Request.URL)
i.DiscardOnSave = true
}
return nil
}
Expand Down
78 changes: 78 additions & 0 deletions cloudamqp/resource_cloudamqp_vpc_peering_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package cloudamqp

import (
"fmt"
"testing"

"github.com/cloudamqp/terraform-provider-cloudamqp/cloudamqp/vcr-testing/configuration"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

// TestAccVpcPeering_Basic: Accept VPC peering and import.
func TestAccVpcPeering_Basic(t *testing.T) {
var (
fileNames = []string{"vpc_peering"}
vpcPeeringResourceName = "cloudamqp_vpc_peering.accepter"

params = map[string]string{
"VpcID": "186",
"PeeringID": "pcx-03ebf8d9ceac304d7",
}
)

cloudamqpResourceTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviderFactory,
PreventPostDestroyRefresh: true,
Steps: []resource.TestStep{
// {
// ResourceName: vpcResourceName,
// ImportStateId: vpcID,
// ImportState: true,
// ImportStateVerify: true,
// ImportStateVerifyIgnore: []string{},
// },
// {
// ResourceName: instanceResourceName,
// ImportStateId: instanceID,
// ImportState: true,
// ImportStateVerify: true,
// ImportStateVerifyIgnore: []string{},
// },
// {
// Config: configuration.GetTemplatedConfig(t, fileNames, params),
// Check: resource.ComposeAggregateTestCheckFunc(
// resource.TestCheckResourceAttr(vpcResourceName, "name", params["VpcName"]),
// resource.TestCheckResourceAttr(vpcResourceName, "id", vpcID),
// resource.TestCheckResourceAttr(vpcResourceName, "subnet", params["VpcSubnet"]),
// resource.TestCheckResourceAttr(vpcResourceName, "region", params["VpcRegion"]),
// resource.TestCheckResourceAttr(instanceResourceName, "name", params["InstanceName"]),
// resource.TestCheckResourceAttr(instanceResourceName, "name", params["InstanceName"]),
// resource.TestCheckResourceAttr(instanceResourceName, "name", params["InstanceName"]),
// ),
// },
// {
// ResourceName: vpcPeeringResourceName,
// ImportStateIdFunc: testAccImportVpcPeeringStateIdFunc("vpc", vpcResourceName, peeringID),
// ImportState: true,
// ImportStateVerify: true,
// ImportStateVerifyIgnore: []string{},
// },
{
Config: configuration.GetTemplatedConfig(t, fileNames, params),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(vpcPeeringResourceName, "vpc_id", params["VpcID"]),
resource.TestCheckResourceAttr(vpcPeeringResourceName, "peering_id", params["PeeringID"]),
resource.TestCheckResourceAttr(vpcPeeringResourceName, "status", "active"),
),
},
{
ResourceName: vpcPeeringResourceName,
ImportStateId: fmt.Sprintf("%s,%s,%s", "vpc", params["VpcID"], params["PeeringID"]),
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{},
},
},
})
}
4 changes: 4 additions & 0 deletions test/configurations/vpc_peering.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource "cloudamqp_vpc_peering" "accepter" {
vpc_id = {{.VpcID}}
peering_id = "{{.PeeringID}}"
}
Loading

0 comments on commit 1dd3da1

Please sign in to comment.