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

Add support for Plan Checks with plancheck.ExpectResourceAction, plancheck.ExpectEmptyPlan, and plancheck.ExpectNonEmptyPlan #63

Merged
merged 37 commits into from
Mar 22, 2023

Conversation

austinvalle
Copy link
Member

@austinvalle austinvalle commented Feb 28, 2023

This PR introduces generic plan check functionality that can be run at different points in a test step (pre-apply, post-apply, etc). These checks can inspect the plan and return an error to fail the test.

The plancheck.PlanCheck interface can be implemented by provider developers, however, this PR contains a new package plancheck that contains implementations for common use cases:

  • plancheck.ExpectResourceAction: For #61 - Allow asserting that a resource will undergo a specific action type, such as Create, Update, NoOp, Replace, etc.
  • plancheck.ExpectEmptyPlan: Allows asserting that a plan is empty
  • plancheck.ExpectNonEmptyPlan: Allows asserting that a plan is not empty

Work left for this PR

  • Continue investigating if we need ResourceActionType or if we can re-use tfjson.Action
  • Add content for the new documentation page in website/docs/plugin/testing/acceptance-testing/plan-checks.mdx
  • Add changelogs for feature enhancement and new package/subsystem

Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

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

The RFC overall looks good to me, so I'll start code commenting for tactical feedback. 👍

helper/plancheck/expect_empty_plan.go Outdated Show resolved Hide resolved
helper/plancheck/expect_empty_plan.go Outdated Show resolved Hide resolved
helper/plancheck/expect_empty_plan_test.go Outdated Show resolved Hide resolved
helper/plancheck/expect_empty_plan_test.go Outdated Show resolved Hide resolved
helper/plancheck/resource_action.go Outdated Show resolved Hide resolved
helper/resource/plan_check.go Outdated Show resolved Hide resolved
helper/resource/plan_check.go Outdated Show resolved Hide resolved
@austinvalle austinvalle added this to the v1.2.0 milestone Mar 20, 2023
@austinvalle austinvalle changed the title (WIP) Add support for PlanAsserts + Implement ResourceActionChange PlanAssert Add support for Plan Checks with plancheck.ExpectResourceAction, plancheck.ExpectEmptyPlan, and plancheck.ExpectNonEmptyPlan Mar 20, 2023
@austinvalle austinvalle marked this pull request as ready for review March 20, 2023 21:07
@austinvalle austinvalle requested a review from a team as a code owner March 20, 2023 21:07
Copy link
Contributor

@bendbennett bendbennett left a comment

Choose a reason for hiding this comment

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

Looks great! Nice work.

plancheck/expect_resource_action_test.go Show resolved Hide resolved
@bflad bflad added the enhancement New feature or request label Mar 21, 2023
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

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

Looks good to me 🚀

helper/resource/testing_new_config_test.go Show resolved Hide resolved
plancheck/expect_resource_action.go Outdated Show resolved Hide resolved
plancheck/expect_resource_action.go Show resolved Hide resolved
plancheck/expect_resource_action.go Outdated Show resolved Hide resolved
plancheck/expect_resource_action_test.go Show resolved Hide resolved
website/docs/plugin/testing/acceptance-tests/teststep.mdx Outdated Show resolved Hide resolved
@austinvalle austinvalle merged commit 31836a5 into main Mar 22, 2023
@austinvalle austinvalle deleted the av/diff-changes branch March 22, 2023 15:43
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Core FR: Check that only an 'update' occurred in a test
3 participants