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

chore: Corrects order of checks in data_source_federated_settings_identity_providers_test #2064

Merged
merged 1 commit into from Mar 23, 2024

Conversation

oarbusi
Copy link
Collaborator

@oarbusi oarbusi commented Mar 22, 2024

Description

Change the order on which we check each IdP. The change in order is caused because now the API returns both SAML and OIDC in the same API call, instead of having to call the API 2 times (one for OIDC and one for SAML) and then appending the results.

Link to any related issue(s):

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.
  • If changes include removal or addition of 3rd party GitHub actions, I updated our internal document. Reach out to the APIx Integration slack channel to get access to the internal document.

Further comments

@oarbusi oarbusi marked this pull request as ready for review March 22, 2024 09:39
@oarbusi oarbusi requested a review from a team as a code owner March 22, 2024 09:39
@@ -28,12 +28,12 @@ func TestAccFederatedSettingsIdentityProvidersDS_basic(t *testing.T) {

resource.TestCheckResourceAttrSet(resourceName, "federation_settings_id"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Curious why this did not fail with the original PR that changed the request behaviour

Copy link
Member

Choose a reason for hiding this comment

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

i suppose it's not defined the API response order

resource.TestCheckResourceAttrSet(resourceName, "results.1.user_claim"),
resource.TestCheckResourceAttrSet(resourceName, "results.1.acs_url"),
resource.TestCheckResourceAttrSet(resourceName, "results.0.audience_claim.0"),
resource.TestCheckResourceAttrSet(resourceName, "results.0.client_id"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are we sure of this order? We should look into using TestCheckTypeSetElemAttr more for lists/sets.
An example where we use this already:
https://github.com/mongodb/terraform-provider-mongodbatlas/blob/master/internal/service/orginvitation/resource_org_invitation_test.go#L50

Copy link
Member

Choose a reason for hiding this comment

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

similar to @maastha , how about having tests that don't depend on the order using TestCheckTypeSetElemNestedAttrs? I don't know if it's possible in this case,
e.g.: https://github.com/mongodb/terraform-provider-mongodbatlas/blob/master/internal/service/cluster/resource_cluster_test.go#L1339

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Running the test now I consistently get this same order.
As per TestCheckTypeSetElemNestedAttrs and TestCheckTypeSetElemAttr I understand that this also checks a specific value has been set in at least one of the elements of the list/set. I don't like this for a couple of reasons:

  • Checks the specific value. This increases the coupling between the test and the current state of testing environment resources, which could change. This happens because this resources does not have create operation through terraform yet. Once create operation is available I would agree that checking value can be useful and valuable.
  • Majority of attributes being checked are only returned with a specific protocol(OIDC or SAML), so with these methods we could actually be missing edge cases where for some protocols the attributes are not being set when they should. But because it could be set in the other element of the list the check would be successful.

@maastha
Copy link
Collaborator

maastha commented Mar 22, 2024

also, can we change the PR title to be more specific? as it shows up in the Changelog

@oarbusi oarbusi changed the title chore: Change plural data source order of check chore: Corrects order of checks in data_source_federated_settings_identity_providers_test Mar 22, 2024
@lantoli lantoli merged commit 92831dd into master Mar 23, 2024
49 checks passed
@lantoli lantoli deleted the fix-idp-test branch March 23, 2024 04:22
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

5 participants