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

test: Fixes tests after updating terraform-plugin-testing from 1.5.1 to 1.6.0 #1792

Merged
merged 5 commits into from Dec 28, 2023

Conversation

AgustinBettati
Copy link
Collaborator

@AgustinBettati AgustinBettati commented Dec 27, 2023

Description

Link to any related issue(s): CLOUDP-219141

This PR uses the dependabot PR as the base branch which is updating terraform-plugin-testing from 1.5.1 to 1.6.0.
Due to some changes introduced in this new version some of our tests where impacted (seen in the following CI execution that was triggered manually):

  • (caused by 1) TestAccClusterRSCluster_withDefaultBiConnectorAndAdvancedConfiguration_maintainsBackwardCompatibility
  • (caused by 2) TestAccFederatedDatabaseInstance_basic
  • (caused by 2) TestAccConfigRSCustomDBRoles_importBasic

The failing test are due to 2 causes.

1. Changes in the behaviour of PlanOnly

I raised an issue to HashiCorp with the details of the failing test and guidance was provided: hashicorp/terraform-plugin-testing#256.
In summary, the failing case defines a migration test from an old provider version to the latest, and during these version one attribute is removed from the schema. After terraform-plugin-testing v1.6.0 when using PlanOnly the state is not automatically updated with the current provider schema before the destroy begins, leading to the error.
The suggested way moving forward is to avoid using PlanOnly: true, and instead use plancheck.ExpectEmptyPlan(). This is only needed when the underlying provider schema changes between TestSteps.

2. Changes in the behaviour of ImportState

Examples of the failing test:

--- FAIL: TestAccConfigRSCustomDBRoles_importBasic (18.63s)
    /Users/agustin.bettati/mongodb/terraform-provider-mongodbatlas/internal/service/customdbrole/resource_custom_db_role_test.go:442: Step 2/3 error running import: ImportStateVerify attributes not equivalent. Difference is shown below. The - symbol indicates attributes missing after import.
        
          map[string]string{
        + 	"actions.0.resources.0.cluster": "false",
          }

As seen in the message, after terraform-plugin-testing v1.6.0 the ImportStateVerify: true, config verifies if there are attributes that are present in the state, but not in the config. Before this version this check only verified missing attributes in the state. I verified that in both cases these additional attributes do not cause a non-empty plan (and also added in test cases), and add these additional attribute in the ImportStateVerifyIgnore array.

Type of change:

  • Bug fix (non-breaking change which fixes an issue). Please, add the "bug" label to the PR.
  • New feature (non-breaking change which adds functionality). Please, add the "enhancement" label to the PR.
  • Breaking change (fix or feature that would cause existing functionality to not work as expected). Please, add the "breaking change" label to the PR.
  • This change requires a documentation update
  • Documentation fix/enhancement

Required Checklist:

  • I have signed the MongoDB CLA
  • I have read the contribution guidelines
  • I have checked that this change does not generate any credentials and that they are NOT accidentally logged anywhere.
  • I have added tests that prove my fix is effective or that my feature works per HashiCorp requirements
  • I have added any necessary documentation (if appropriate)
  • I have run make fmt and formatted my code
  • If changes include deprecations or removals, I defined an isolated PR with a relevant title as it will be used in the auto-generated changelog.

Further comments

dependabot bot and others added 3 commits December 21, 2023 16:32
Bumps [github.com/hashicorp/terraform-plugin-testing](https://github.com/hashicorp/terraform-plugin-testing) from 1.5.1 to 1.6.0.
- [Release notes](https://github.com/hashicorp/terraform-plugin-testing/releases)
- [Changelog](https://github.com/hashicorp/terraform-plugin-testing/blob/main/CHANGELOG.md)
- [Commits](hashicorp/terraform-plugin-testing@v1.5.1...v1.6.0)

---
updated-dependencies:
- dependency-name: github.com/hashicorp/terraform-plugin-testing
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
@AgustinBettati AgustinBettati changed the base branch from master to dependabot/go_modules/github.com/hashicorp/terraform-plugin-testing-1.6.0 December 27, 2023 10:34
@AgustinBettati AgustinBettati changed the title test: make adjustment in tests after updating terraform-plugin-testing from 1.5.1 to 1.6.0 test: Fixes tests after updating terraform-plugin-testing from 1.5.1 to 1.6.0 Dec 27, 2023
@AgustinBettati
Copy link
Collaborator Author

AgustinBettati commented Dec 27, 2023

failing test in cluster group (TestAccClusterRSCluster_tenant) is not related, will followup with a CLOUDP ticket for that issue as I am also seeing it in QA executions (flaky scenario). Also ran all acceptance tests/migrations test to verify no other failing test was left out after the fix.

@andreaangiolillo andreaangiolillo marked this pull request as ready for review December 28, 2023 10:23
@andreaangiolillo andreaangiolillo requested a review from a team as a code owner December 28, 2023 10:23
Copy link
Collaborator

@andreaangiolillo andreaangiolillo left a comment

Choose a reason for hiding this comment

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

LGTM

},
},
PlanOnly: true,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we do a quick search/replace of PlanOnly in the repo? 👀

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sorry I did not understand this point

Copy link
Collaborator

Choose a reason for hiding this comment

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

just updated the message. I am wondering if we should search for PlanOnly in the repo and remove it

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah, was waiting for confirmation here as the migration test documentation still mentions PlanOnly usage. Can do this in a followup PR.

},
},
PlanOnly: true,
Copy link
Collaborator

Choose a reason for hiding this comment

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

[not-blocking] Should we document these errors somewhere so that we do not forget them in the future? I am not sure about an ideal location 🤔 leave this here to think about it

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Our terraform wiki can be good starting point, helpful for referencing in the future if it is encountered again.

@@ -1451,9 +1451,9 @@ func TestAccClusterRSCluster_withDefaultBiConnectorAndAdvancedConfiguration_main
ConfigPlanChecks: resource.ConfigPlanChecks{
PostApplyPreRefresh: []plancheck.PlanCheck{
acc.DebugPlan(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we still need this as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

thanks for noting, not necessary as ExpectEmptyPlan() gives details of the plan if it is non empty.

@AgustinBettati AgustinBettati changed the base branch from dependabot/go_modules/github.com/hashicorp/terraform-plugin-testing-1.6.0 to master December 28, 2023 13:36
@AgustinBettati AgustinBettati merged commit 4203246 into master Dec 28, 2023
33 checks passed
@AgustinBettati AgustinBettati deleted the CLOUDP-219141 branch December 28, 2023 13:38
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

3 participants