generated from hashicorp/terraform-provider-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 43
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
Adds acceptance tests for datasources for HVN, Consul and Vault clusters #135
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c4d704d
Adds acceptance tests for data sources
lackeyjb 268deea
Move datasource tests to resource tests to decrease test time
lackeyjb 191c55f
Add comments to explain steps in acc tests with datasources added
lackeyjb b3bce89
Relocate comments
lackeyjb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// This includes tests against both the resource and the corresponding datasource | ||
// to shorten testing time. | ||
package provider | ||
|
||
import ( | ||
|
@@ -10,29 +12,34 @@ import ( | |
"github.com/hashicorp/terraform-provider-hcp/internal/clients" | ||
) | ||
|
||
var ( | ||
testAccConsulClusterConfig = fmt.Sprintf(` | ||
var testAccConsulClusterConfig = ` | ||
resource "hcp_hvn" "test" { | ||
hvn_id = "test-hvn" | ||
cloud_provider = "aws" | ||
region = "us-west-2" | ||
} | ||
|
||
resource "hcp_consul_cluster" "test" { | ||
cluster_id = "test-consul-cluster" | ||
hvn_id = hcp_hvn.test.hvn_id | ||
tier = "development" | ||
}`) | ||
) | ||
} | ||
|
||
data "hcp_consul_cluster" "test" { | ||
cluster_id = hcp_consul_cluster.test.cluster_id | ||
} | ||
` | ||
|
||
func TestAccConsulCluster(t *testing.T) { | ||
resourceName := "hcp_consul_cluster.test" | ||
dataSourceName := "data.hcp_consul_cluster.test" | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t, false) }, | ||
ProviderFactories: providerFactories, | ||
CheckDestroy: testAccCheckConsulClusterDestroy, | ||
Steps: []resource.TestStep{ | ||
// Tests create | ||
{ | ||
Config: testConfig(testAccConsulClusterConfig), | ||
Check: resource.ComposeTestCheckFunc( | ||
|
@@ -62,6 +69,7 @@ func TestAccConsulCluster(t *testing.T) { | |
resource.TestCheckResourceAttrSet(resourceName, "size"), | ||
), | ||
}, | ||
// Tests import | ||
{ | ||
ResourceName: resourceName, | ||
ImportState: true, | ||
|
@@ -76,6 +84,7 @@ func TestAccConsulCluster(t *testing.T) { | |
ImportStateVerify: true, | ||
ImportStateVerifyIgnore: []string{"consul_root_token_accessor_id", "consul_root_token_secret_id"}, | ||
}, | ||
// Tests read | ||
{ | ||
Config: testConfig(testAccConsulClusterConfig), | ||
Check: resource.ComposeTestCheckFunc( | ||
|
@@ -105,6 +114,34 @@ func TestAccConsulCluster(t *testing.T) { | |
resource.TestCheckResourceAttrSet(resourceName, "size"), | ||
), | ||
}, | ||
// Tests datasource | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Two things on each of these tests:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I split the configs up the tests errored out, so I ended up just adding comments to each step in the tests |
||
Config: testConfig(testAccConsulClusterConfig), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrPair(resourceName, "cluster_id", dataSourceName, "cluster_id"), | ||
resource.TestCheckResourceAttrPair(resourceName, "project_id", dataSourceName, "project_id"), | ||
resource.TestCheckResourceAttrPair(resourceName, "organization_id", dataSourceName, "organization_id"), | ||
resource.TestCheckResourceAttrPair(resourceName, "hvn_id", dataSourceName, "hvn_id"), | ||
resource.TestCheckResourceAttrPair(resourceName, "cloud_provider", dataSourceName, "cloud_provider"), | ||
resource.TestCheckResourceAttrPair(resourceName, "region", dataSourceName, "region"), | ||
resource.TestCheckResourceAttrPair(resourceName, "public_endpoint", dataSourceName, "public_endpoint"), | ||
resource.TestCheckResourceAttrPair(resourceName, "datacenter", dataSourceName, "datacenter"), | ||
resource.TestCheckResourceAttrPair(resourceName, "connect_enabled", dataSourceName, "connect_enabled"), | ||
resource.TestCheckResourceAttrPair(resourceName, "consul_automatic_upgrades", dataSourceName, "consul_automatic_upgrades"), | ||
resource.TestCheckResourceAttrPair(resourceName, "consul_snapshot_interval", dataSourceName, "consul_snapshot_interval"), | ||
resource.TestCheckResourceAttrPair(resourceName, "consul_snapshot_retention", dataSourceName, "consul_snapshot_retention"), | ||
resource.TestCheckResourceAttrPair(resourceName, "consul_config_file", dataSourceName, "consul_config_file"), | ||
resource.TestCheckResourceAttrPair(resourceName, "consul_ca_file", dataSourceName, "consul_ca_file"), | ||
resource.TestCheckResourceAttrPair(resourceName, "consul_version", dataSourceName, "consul_version"), | ||
resource.TestCheckResourceAttrPair(resourceName, "consul_public_endpoint_url", dataSourceName, "consul_public_endpoint_url"), | ||
resource.TestCheckResourceAttrPair(resourceName, "consul_private_endpoint_url", dataSourceName, "consul_private_endpoint_url"), | ||
resource.TestCheckResourceAttrPair(resourceName, "scale", dataSourceName, "scale"), | ||
resource.TestCheckResourceAttrPair(resourceName, "tier", dataSourceName, "tier"), | ||
resource.TestCheckResourceAttrPair(resourceName, "size", dataSourceName, "size"), | ||
resource.TestCheckResourceAttrPair(resourceName, "self_link", dataSourceName, "self_link"), | ||
resource.TestCheckResourceAttrPair(resourceName, "primary_link", dataSourceName, "primary_link"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for adding these! last thing: can you bump this down to above L33? Same for the others? I don't usually see comments above the package in go so I think this'll be easy to miss.