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

testing: Update acceptance tests to use new statecheck package and value comparers #599

Merged
merged 14 commits into from
Aug 9, 2024

Conversation

austinvalle
Copy link
Member

@austinvalle austinvalle commented Aug 7, 2024

Ref: hashicorp/terraform-plugin-testing#295, hashicorp/terraform-plugin-testing#266

With this refactor, all of the assertions should be equivalent except for a few where I made the test assertions more restrictive/exact. Let me know if I missed anything!

go.mod Outdated Show resolved Hide resolved
resource.TestCheckNoResourceAttr("random_password.default", "numeric"),
beforeUpgradeStateChecks: []statecheck.StateCheck{
statecheck.ExpectKnownValue("random_password.default", tfjsonpath.New("number"), knownvalue.Bool(true)),
randomtest.ExpectNoAttribute("random_password.default", tfjsonpath.New("numeric")),
Copy link
Member Author

@austinvalle austinvalle Aug 7, 2024

Choose a reason for hiding this comment

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

A fun (and expected) quirk of our new state checks are that they will recognize if an attribute doesn't exist and fail, so certain usages of resource.TestCheckNoResourceAttr will not be able to be replaced by statecheck.ExpectKnownValue with a knownvalue.Null()

I'm not sure how common it is to check for an attribute not existing, but if it's common we can move the ExpectNoAttribute into the terraform-plugin-testing Go module

@austinvalle austinvalle marked this pull request as ready for review August 8, 2024 21:17
@austinvalle austinvalle requested a review from a team as a code owner August 8, 2024 21:17
@austinvalle austinvalle merged commit 3c20ad7 into main Aug 9, 2024
46 checks passed
@austinvalle austinvalle deleted the av/state-checks branch August 9, 2024 18:32
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants