Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix E2E Tests #440

Merged
merged 5 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/440.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
Fix issue with E2E tests failing
```
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ require (
github.com/imdario/mergo v0.3.13 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mitchellh/cli v1.1.4 // indirect
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
Expand All @@ -90,7 +90,7 @@ require (
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d // indirect
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect
golang.org/x/oauth2 v0.0.0-20201109201403-9fd604954f58 // indirect
golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8 // indirect
golang.org/x/sys v0.1.0 // indirect
golang.org/x/text v0.4.0 // indirect
google.golang.org/appengine v1.6.6 // indirect
google.golang.org/genproto v0.0.0-20200904004341-0bd0a958aa1d // indirect
Expand Down
11 changes: 7 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,14 @@ github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kN
github.com/matryer/is v1.2.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mitchellh/cli v1.1.4 h1:qj8czE26AU4PbiaPXK5uVmMSM+V5BYsFBiM9HhGRLUA=
github.com/mitchellh/cli v1.1.4/go.mod h1:vTLESy5mRhKOs9KDp0/RATawxP1UqBmdrpVRMnpcvKQ=
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ=
Expand Down Expand Up @@ -583,8 +585,9 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8 h1:h+EGohizhe9XlX18rfpa8k8RAc5XyaeamM+0VHRd4lc=
golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"

Expand Down Expand Up @@ -205,7 +205,7 @@ func isHCPOperational() (diags diag.Diagnostics) {
}
defer resp.Body.Close()

jsBytes, err := ioutil.ReadAll(resp.Body)
jsBytes, err := io.ReadAll(resp.Body)
if err != nil {
diags = append(diags, diag.Diagnostic{
Severity: diag.Warning,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ import (

var (
// using unique names for AWS resource to make debugging easier
tgwAttUniqueAWSName = fmt.Sprintf("hcp-provider-test-%s", time.Now().Format("200601021504"))
tgwAttUniqueAWSName = fmt.Sprintf("hcp-att-unique-test-%s", time.Now().Format("200601021504"))
tgwAttUniqueHvnName = fmt.Sprintf("att-hvn-name-%s", time.Now().Format("200601021504"))
testAccTGWAttachmentConfig = fmt.Sprintf(`
provider "aws" {
region = "us-west-2"
}

resource "hcp_hvn" "test" {
hvn_id = "%[1]s"
hvn_id = "%[2]s"
cloud_provider = "aws"
region = "us-west-2"
cidr_block = "172.25.16.0/20"
Expand Down Expand Up @@ -99,7 +100,7 @@ resource "aws_ec2_transit_gateway_vpc_attachment_accepter" "example" {
tgw_attachment_id = hcp_aws_transit_gateway_attachment.example.transit_gateway_attachment_id
}
}
`, tgwAttUniqueAWSName)
`, tgwAttUniqueAWSName, tgwAttUniqueHvnName)
)

func TestAccTGWAttachment(t *testing.T) {
Expand All @@ -120,7 +121,7 @@ func TestAccTGWAttachment(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckTGWAttachmentExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "transit_gateway_attachment_id", tgwAttUniqueAWSName),
resource.TestCheckResourceAttr(resourceName, "hvn_id", tgwAttUniqueAWSName),
resource.TestCheckResourceAttr(resourceName, "hvn_id", tgwAttUniqueHvnName),
resource.TestCheckResourceAttrSet(resourceName, "transit_gateway_id"),
resource.TestCheckResourceAttrSet(resourceName, "provider_transit_gateway_attachment_id"),
resource.TestCheckResourceAttrSet(resourceName, "state"),
Expand All @@ -142,7 +143,7 @@ func TestAccTGWAttachment(t *testing.T) {
return "", fmt.Errorf("not found: aws_ram_resource_share.example")
}

return fmt.Sprintf("test-hvn:example-tgw-attachment:%s", resourceShare.Primary.Attributes["arn"]), nil
return fmt.Sprintf("%s:%s:%s", tgwAttUniqueHvnName, tgwAttUniqueAWSName, resourceShare.Primary.Attributes["arn"]), nil
},
ImportStateVerify: true,
},
Expand All @@ -152,7 +153,7 @@ func TestAccTGWAttachment(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckTGWAttachmentExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "transit_gateway_attachment_id", tgwAttUniqueAWSName),
resource.TestCheckResourceAttr(resourceName, "hvn_id", tgwAttUniqueAWSName),
resource.TestCheckResourceAttr(resourceName, "hvn_id", tgwAttUniqueHvnName),
resource.TestCheckResourceAttrSet(resourceName, "transit_gateway_id"),
resource.TestCheckResourceAttrSet(resourceName, "provider_transit_gateway_attachment_id"),
resource.TestCheckResourceAttrSet(resourceName, "state"),
Expand Down
9 changes: 5 additions & 4 deletions internal/provider/resource_consul_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
)

var consulClusterUniqueID = fmt.Sprintf("test-%s", time.Now().Format("200601021504"))
var consulClusterHVNUniqueID = fmt.Sprintf("test-hvn-%s", time.Now().Format("200601021504"))

var consulCluster = fmt.Sprintf(`
resource "hcp_consul_cluster" "test" {
Expand All @@ -34,7 +35,7 @@ resource "hcp_consul_cluster" "test" {
func setTestAccConsulClusterConfig(consulCluster string) string {
return fmt.Sprintf(`
resource "hcp_hvn" "test" {
hvn_id = "test-hvn"
hvn_id = "%s"
cloud_provider = "aws"
region = "us-west-2"
}
Expand All @@ -50,7 +51,7 @@ func setTestAccConsulClusterConfig(consulCluster string) string {
resource "hcp_consul_cluster_root_token" "test" {
cluster_id = hcp_consul_cluster.test.cluster_id
}
`, consulCluster)
`, consulClusterHVNUniqueID, consulCluster)
}

// This includes tests against both the resource, the corresponding datasource,
Expand All @@ -73,7 +74,7 @@ func TestAccConsulCluster(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckConsulClusterExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "cluster_id", consulClusterUniqueID),
resource.TestCheckResourceAttr(resourceName, "hvn_id", "test-hvn"),
resource.TestCheckResourceAttr(resourceName, "hvn_id", consulClusterHVNUniqueID),
resource.TestCheckResourceAttr(resourceName, "tier", "DEVELOPMENT"),
resource.TestCheckResourceAttr(resourceName, "cloud_provider", "aws"),
resource.TestCheckResourceAttr(resourceName, "region", "us-west-2"),
Expand Down Expand Up @@ -121,7 +122,7 @@ func TestAccConsulCluster(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckConsulClusterExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "cluster_id", consulClusterUniqueID),
resource.TestCheckResourceAttr(resourceName, "hvn_id", "test-hvn"),
resource.TestCheckResourceAttr(resourceName, "hvn_id", consulClusterHVNUniqueID),
resource.TestCheckResourceAttr(resourceName, "tier", "DEVELOPMENT"),
resource.TestCheckResourceAttr(resourceName, "cloud_provider", "aws"),
resource.TestCheckResourceAttr(resourceName, "region", "us-west-2"),
Expand Down
22 changes: 13 additions & 9 deletions internal/provider/resource_consul_snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,33 @@ import (
"context"
"fmt"
"testing"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"github.com/hashicorp/terraform-provider-hcp/internal/clients"
)

var testAccConsulSnapshotConfig = `
var consulClusterSnapshotUniqueID = fmt.Sprintf("test-snapshot-%s", time.Now().Format("200601021504"))
var consulClusterSnapshotHVNUniqueID = fmt.Sprintf("test-snapshot-hvn-%s", time.Now().Format("200601021504"))

var testAccConsulSnapshotConfig = fmt.Sprintf(`
resource "hcp_hvn" "test" {
hvn_id = "test-hvn"
hvn_id = "%[1]s"
cloud_provider = "aws"
region = "us-west-2"
}

resource "hcp_consul_cluster" "test" {
cluster_id = "test-consul-cluster"
cluster_id = "%[2]s"
hvn_id = hcp_hvn.test.hvn_id
tier = "development"
}

resource "hcp_consul_snapshot" "test" {
cluster_id = hcp_consul_cluster.test.cluster_id
snapshot_name = "test"
}`
snapshot_name = "%[2]s"
}`, consulClusterSnapshotHVNUniqueID, consulClusterSnapshotUniqueID)

func TestAccConsulSnapshot(t *testing.T) {
resourceName := "hcp_consul_snapshot.test"
Expand All @@ -40,8 +44,8 @@ func TestAccConsulSnapshot(t *testing.T) {
Config: testConfig(testAccConsulSnapshotConfig),
Check: resource.ComposeTestCheckFunc(
testAccCheckConsulSnapshotExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "cluster_id", "test-consul-cluster"),
resource.TestCheckResourceAttr(resourceName, "snapshot_name", "test"),
resource.TestCheckResourceAttr(resourceName, "cluster_id", consulClusterSnapshotUniqueID),
resource.TestCheckResourceAttr(resourceName, "snapshot_name", consulClusterSnapshotUniqueID),
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
resource.TestCheckResourceAttrSet(resourceName, "snapshot_id"),
resource.TestCheckResourceAttrSet(resourceName, "organization_id"),
Expand All @@ -55,8 +59,8 @@ func TestAccConsulSnapshot(t *testing.T) {
Config: testConfig(testAccConsulSnapshotConfig),
Check: resource.ComposeTestCheckFunc(
testAccCheckConsulSnapshotExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "cluster_id", "test-consul-cluster"),
resource.TestCheckResourceAttr(resourceName, "snapshot_name", "test"),
resource.TestCheckResourceAttr(resourceName, "cluster_id", consulClusterSnapshotUniqueID),
resource.TestCheckResourceAttr(resourceName, "snapshot_name", consulClusterSnapshotUniqueID),
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
resource.TestCheckResourceAttrSet(resourceName, "snapshot_id"),
resource.TestCheckResourceAttrSet(resourceName, "organization_id"),
Expand Down