Skip to content

fix(acctest): compare in depth request body with cassette body #3135

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

Merged
merged 3 commits into from
Jun 18, 2025

Conversation

Gnoale
Copy link
Contributor

@Gnoale Gnoale commented Jun 3, 2025

Intro

When comparing a json request body with the cassette ones, if the json dict is nested, like in such case :

{
  "organization_id": "6867048b-fe12-4e96-835e-41c79a39604b",
  "tags": [
    "bar"
  ],
  "member": {
    "email": "[email protected]",
    "send_password_email": false,
    "send_welcome_email": false,
    "username": "bar",
    "password": "",
    "first_name": "",
    "last_name": "",
    "phone_number": "",
    "locale": ""
  }
}

The comparison will return true even if the nested values are different (values inside the "member" key)

This lead to behavior such as constant Terraform drift when attempting to replay some query, in particular when creating different objects with nested values like scaleway_iam_user https://github.com/scaleway/terraform-provider-scaleway/pull/3126/files#diff-23bcf61d4790cd7c6dff0968222979dc54e167151bfb42c6dbf1f2abfdb26c48

Features

Perform in depth comparison between request body and cassette body:

  • remove ignored field recursively (not only in the outside json dict)
  • inspect the inner json struct and recursively handle
    • primitives, map[string]any, any
    • slice of interfaces:
    • cast to string or float64: sort and compare
    • slice of map[string]interface{}: compare out of order

Add a few exceptions for fields that where ignored before, related to mnq

@Gnoale Gnoale requested a review from remyleone as a code owner June 3, 2025 07:13
@Gnoale Gnoale requested a review from a team as a code owner June 3, 2025 16:28
@github-actions github-actions bot added the iam IAM issues, bugs and feature requests label Jun 3, 2025
@Gnoale Gnoale force-pushed the bugfix-vcr branch 4 times, most recently from 7d3d395 to 76968d6 Compare June 4, 2025 14:14
@Gnoale Gnoale changed the title fix(acctest): perform deepequality on nested request body fix(acctest): compare in depth request body with cassette body Jun 4, 2025
@Gnoale Gnoale added tests and removed iam IAM issues, bugs and feature requests labels Jun 4, 2025
@Gnoale Gnoale force-pushed the bugfix-vcr branch 6 times, most recently from 0d03b41 to 168b45f Compare June 10, 2025 15:19
@yfodil yfodil requested a review from a team as a code owner June 10, 2025 15:34
@Mia-Cross Mia-Cross requested a review from a team as a code owner June 10, 2025 15:44
@github-actions github-actions bot added the instance Instance issues, bugs and feature requests label Jun 10, 2025
@remyleone remyleone added this pull request to the merge queue Jun 18, 2025
Merged via the queue into master with commit e052f9f Jun 18, 2025
47 checks passed
@remyleone remyleone deleted the bugfix-vcr branch June 18, 2025 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
instance Instance issues, bugs and feature requests tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants