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

Adds acceptance tests for datasources for HVN, Consul and Vault clusters #135

Merged
merged 4 commits into from
Jun 10, 2021

Conversation

lackeyjb
Copy link
Contributor

@lackeyjb lackeyjb commented Jun 3, 2021

πŸ› οΈ Description

Adds acceptance tests for datasources for HVN, Consul and Vault clusters.

πŸ—οΈ Acceptance tests

  • Are there any feature flags that are required to use this functionality? no
  • Have you added an acceptance test for the functionality being added? no new functionality
  • Have you run the acceptance tests on this branch?

Output from acceptance testing:

$ make testacc
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/... -v  -timeout 120m
?   	github.com/hashicorp/terraform-provider-hcp/internal/clients	[no test files]
=== RUN   Test_RecommendedVersion
=== RUN   Test_RecommendedVersion/with_a_recommended_version
=== RUN   Test_RecommendedVersion/without_a_recommended_version
--- PASS: Test_RecommendedVersion (0.00s)
    --- PASS: Test_RecommendedVersion/with_a_recommended_version (0.00s)
    --- PASS: Test_RecommendedVersion/without_a_recommended_version (0.00s)
=== RUN   Test_IsValidVersion
=== RUN   Test_IsValidVersion/with_a_valid_version
=== RUN   Test_IsValidVersion/with_an_invalid_version
=== RUN   Test_IsValidVersion/with_no_valid_versions
--- PASS: Test_IsValidVersion (0.00s)
    --- PASS: Test_IsValidVersion/with_a_valid_version (0.00s)
    --- PASS: Test_IsValidVersion/with_an_invalid_version (0.00s)
    --- PASS: Test_IsValidVersion/with_no_valid_versions (0.00s)
=== RUN   Test_VersionsToString
=== RUN   Test_VersionsToString/nil_input
=== RUN   Test_VersionsToString/with_a_recommended_version
=== RUN   Test_VersionsToString/without_a_recommended_version
=== RUN   Test_VersionsToString/no_other_versions_but_recommended
=== RUN   Test_VersionsToString/nil_values
--- PASS: Test_VersionsToString (0.00s)
    --- PASS: Test_VersionsToString/nil_input (0.00s)
    --- PASS: Test_VersionsToString/with_a_recommended_version (0.00s)
    --- PASS: Test_VersionsToString/without_a_recommended_version (0.00s)
    --- PASS: Test_VersionsToString/no_other_versions_but_recommended (0.00s)
    --- PASS: Test_VersionsToString/nil_values (0.00s)
PASS
ok  	github.com/hashicorp/terraform-provider-hcp/internal/consul	(cached)
=== RUN   Test_NormalizeVersion
=== RUN   Test_NormalizeVersion/with_a_prefixed_v
=== RUN   Test_NormalizeVersion/without_a_prefixed_v
--- PASS: Test_NormalizeVersion (0.00s)
    --- PASS: Test_NormalizeVersion/with_a_prefixed_v (0.00s)
    --- PASS: Test_NormalizeVersion/without_a_prefixed_v (0.00s)
PASS
ok  	github.com/hashicorp/terraform-provider-hcp/internal/input	(cached)
=== RUN   TestAccDataSourceConsulCluster
--- PASS: TestAccDataSourceConsulCluster (705.65s)
=== RUN   TestAccDataSourceHvn
--- PASS: TestAccDataSourceHvn (60.51s)
=== RUN   TestAccDataSourceVaultCluster
--- PASS: TestAccDataSourceVaultCluster (857.93s)
=== RUN   Test_linkURL
=== RUN   Test_linkURL/valid_ID
=== RUN   Test_linkURL/missing_organization_ID
=== RUN   Test_linkURL/missing_project_ID
=== RUN   Test_linkURL/missing_resource_type
=== RUN   Test_linkURL/missing_resource_ID
=== RUN   Test_linkURL/missing_Location
--- PASS: Test_linkURL (0.00s)
    --- PASS: Test_linkURL/valid_ID (0.00s)
    --- PASS: Test_linkURL/missing_organization_ID (0.00s)
    --- PASS: Test_linkURL/missing_project_ID (0.00s)
    --- PASS: Test_linkURL/missing_resource_type (0.00s)
    --- PASS: Test_linkURL/missing_resource_ID (0.00s)
    --- PASS: Test_linkURL/missing_Location (0.00s)
=== RUN   Test_parseLinkURL
=== RUN   Test_parseLinkURL/valid_URL
=== RUN   Test_parseLinkURL/missing_project_ID
=== RUN   Test_parseLinkURL/missing_resource_type
=== RUN   Test_parseLinkURL/mismatched_resource_type
=== RUN   Test_parseLinkURL/missing_resource_id
=== RUN   Test_parseLinkURL/missing_a_field
=== RUN   Test_parseLinkURL/too_many_fields_before
=== RUN   Test_parseLinkURL/too_many_fields_after
--- PASS: Test_parseLinkURL (0.00s)
    --- PASS: Test_parseLinkURL/valid_URL (0.00s)
    --- PASS: Test_parseLinkURL/missing_project_ID (0.00s)
    --- PASS: Test_parseLinkURL/missing_resource_type (0.00s)
    --- PASS: Test_parseLinkURL/mismatched_resource_type (0.00s)
    --- PASS: Test_parseLinkURL/missing_resource_id (0.00s)
    --- PASS: Test_parseLinkURL/missing_a_field (0.00s)
    --- PASS: Test_parseLinkURL/too_many_fields_before (0.00s)
    --- PASS: Test_parseLinkURL/too_many_fields_after (0.00s)
=== RUN   TestProvider
--- PASS: TestProvider (0.00s)
=== RUN   TestAccConsulCluster
--- PASS: TestAccConsulCluster (668.79s)
=== RUN   TestAccConsulSnapshot
--- PASS: TestAccConsulSnapshot (723.84s)
=== RUN   TestAccHvn
--- PASS: TestAccHvn (69.58s)
=== RUN   TestAccVaultClusterAdminToken
--- PASS: TestAccVaultClusterAdminToken (831.21s)
=== RUN   TestAccVaultCluster
--- PASS: TestAccVaultCluster (977.02s)
=== RUN   Test_validateStringNotEmpty
=== RUN   Test_validateStringNotEmpty/valid_string
=== RUN   Test_validateStringNotEmpty/empty_string
--- PASS: Test_validateStringNotEmpty (0.00s)
    --- PASS: Test_validateStringNotEmpty/valid_string (0.00s)
    --- PASS: Test_validateStringNotEmpty/empty_string (0.00s)
=== RUN   Test_validateStringInSlice
=== RUN   Test_validateStringInSlice/contains_the_input_(matches_case)
=== RUN   Test_validateStringInSlice/contains_the_input_(case_invariant)
=== RUN   Test_validateStringInSlice/does_not_contain_the_input
--- PASS: Test_validateStringInSlice (0.00s)
    --- PASS: Test_validateStringInSlice/contains_the_input_(matches_case) (0.00s)
    --- PASS: Test_validateStringInSlice/contains_the_input_(case_invariant) (0.00s)
    --- PASS: Test_validateStringInSlice/does_not_contain_the_input (0.00s)
=== RUN   Test_validateSemVer
=== RUN   Test_validateSemVer/valid_semver_without_prefixed_v
=== RUN   Test_validateSemVer/invalid_semver
=== RUN   Test_validateSemVer/valid_semver_with_prefixed_v
--- PASS: Test_validateSemVer (0.00s)
    --- PASS: Test_validateSemVer/valid_semver_without_prefixed_v (0.00s)
    --- PASS: Test_validateSemVer/invalid_semver (0.00s)
    --- PASS: Test_validateSemVer/valid_semver_with_prefixed_v (0.00s)
=== RUN   Test_validateSlugID
=== RUN   Test_validateSlugID/too_long
=== RUN   Test_validateSlugID/valid_id
=== RUN   Test_validateSlugID/empty_string
=== RUN   Test_validateSlugID/invalid_characters
=== RUN   Test_validateSlugID/too_short
--- PASS: Test_validateSlugID (0.00s)
    --- PASS: Test_validateSlugID/too_long (0.00s)
    --- PASS: Test_validateSlugID/valid_id (0.00s)
    --- PASS: Test_validateSlugID/empty_string (0.00s)
    --- PASS: Test_validateSlugID/invalid_characters (0.00s)
    --- PASS: Test_validateSlugID/too_short (0.00s)
=== RUN   Test_validateDatacenter
=== RUN   Test_validateDatacenter/valid_datacenter
=== RUN   Test_validateDatacenter/empty_string
=== RUN   Test_validateDatacenter/invalid_characters
=== RUN   Test_validateDatacenter/uppercase_characters
=== RUN   Test_validateDatacenter/too_short
=== RUN   Test_validateDatacenter/too_long
--- PASS: Test_validateDatacenter (0.00s)
    --- PASS: Test_validateDatacenter/valid_datacenter (0.00s)
    --- PASS: Test_validateDatacenter/empty_string (0.00s)
    --- PASS: Test_validateDatacenter/invalid_characters (0.00s)
    --- PASS: Test_validateDatacenter/uppercase_characters (0.00s)
    --- PASS: Test_validateDatacenter/too_short (0.00s)
    --- PASS: Test_validateDatacenter/too_long (0.00s)
=== RUN   Test_validateConsulClusterTier
=== RUN   Test_validateConsulClusterTier/valid_tier_lowercase
=== RUN   Test_validateConsulClusterTier/valid_tier_uppercase
=== RUN   Test_validateConsulClusterTier/valid_tier_mixedcase
=== RUN   Test_validateConsulClusterTier/invalid_tier
--- PASS: Test_validateConsulClusterTier (0.00s)
    --- PASS: Test_validateConsulClusterTier/valid_tier_lowercase (0.00s)
    --- PASS: Test_validateConsulClusterTier/valid_tier_uppercase (0.00s)
    --- PASS: Test_validateConsulClusterTier/valid_tier_mixedcase (0.00s)
    --- PASS: Test_validateConsulClusterTier/invalid_tier (0.00s)
=== RUN   Test_validateConsulClusterSize
=== RUN   Test_validateConsulClusterSize/valid_size_mixedcase
=== RUN   Test_validateConsulClusterSize/invalid_tier
=== RUN   Test_validateConsulClusterSize/valid_size
=== RUN   Test_validateConsulClusterSize/valid_size_lowercase
=== RUN   Test_validateConsulClusterSize/valid_size_uppercase
--- PASS: Test_validateConsulClusterSize (0.00s)
    --- PASS: Test_validateConsulClusterSize/valid_size_mixedcase (0.00s)
    --- PASS: Test_validateConsulClusterSize/invalid_tier (0.00s)
    --- PASS: Test_validateConsulClusterSize/valid_size (0.00s)
    --- PASS: Test_validateConsulClusterSize/valid_size_lowercase (0.00s)
    --- PASS: Test_validateConsulClusterSize/valid_size_uppercase (0.00s)
PASS
ok  	github.com/hashicorp/terraform-provider-hcp/internal/provider	4895.504s

@lackeyjb lackeyjb requested a review from a team June 3, 2021 20:41
tier = "development"
}

data "hcp_consul_cluster" "test" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm getting a bit concerned about test time. Since we have to create the resource here, maybe we could take this config and add it in a new test step on the resource tests. We'll have to document the pattern/leave comments, but I think it's worthwhile to save test time, since the creation/teardown of these cloud resources takes at least 10 minutes.

@lackeyjb lackeyjb force-pushed the hcpe-1095-data-source-acc-tests branch from ba2c8e8 to 268deea Compare June 7, 2021 19:05
Copy link
Contributor

@bcmdarroch bcmdarroch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work on these! I've got two suggestions that shouldn't take too long to fix.

@@ -105,6 +109,33 @@ func TestAccConsulCluster(t *testing.T) {
resource.TestCheckResourceAttrSet(resourceName, "size"),
),
},
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things on each of these tests:

  1. Since we have a few test steps now, it'd be great to add some guidance comments at the beginning of each step. I.e. first step testsCreate, second step tests Import, third step tests Updates, and fourth step tests the datasource. It might even be worth an intro comment at the top explaining that the datasource test is incorporated in the resource test.
  2. To have more separation between the test cases, I'm thinking it'd be worth having two TF configs, one with just the resource and the other adding the data source (which we'd use just in this last step).

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

@@ -1,3 +1,5 @@
// This includes tests against both the resource and the corresponding datasource
Copy link
Contributor

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.

@lackeyjb lackeyjb merged commit 641cd53 into main Jun 10, 2021
@lackeyjb lackeyjb deleted the hcpe-1095-data-source-acc-tests branch June 10, 2021 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants