Skip to content

Conversation

@adambarreiro
Copy link
Contributor

@adambarreiro adambarreiro commented Mar 7, 2025

This PR fixes the test failure:

=== RUN   TestAccVcfaContentLibraryTenant
    resource_vcfa_content_library_test.go:285: Step 4/6 error: Error running pre-apply refresh: exit status 1
        
        Error: error getting Storage Class by Name 'vSAN Default Storage Policy': error retrieving all entities of type 'Storage Class': error getting all pages for endpoint https://my-vcfa.com/cloudapi/vcf/storageClasses/: error in HTTP GET request: NOT_AUTHENTICATED - [ 3258-2025-03-07-00-07-32-260--218b64dc-ad8d-43c6-9f9f-4c6eff270d9e ] This operation is denied.
        
          with data.vcfa_storage_class.sc-tenant,
          on terraform_plugin_test.tf line 167, in data "vcfa_storage_class" "sc-tenant":
         167: data "vcfa_storage_class" "sc-tenant" {
        
--- FAIL: TestAccVcfaContentLibraryTenant (220.57s)

The issue happens because there is one test, TestAccVcfaContentLibraryItemTenant, which is run before TestAccVcfaContentLibraryTenant, that creates an Organization user and performs a login with it, caching its data in the client cache. When the test finishes, the user is destroyed, but it remains in the client cache.

When TestAccVcfaContentLibraryTenant kicks in afterwards, it creates again the same user (it re-uses same HCL), so when the login comes, it reuses wrong cached info, therefore all subsequent queries will end up with NOT_AUTHENTICATED errors.

The fix consists of resetting the cached clients when these kind of tests complete.

Extra fix: Disable anti-virus scanning in created Org in these tests, to avoid blocking tasks.

To reproduce:

go test -tags functional -vcfa-add-provider -run 'TestAccVcfaContentLibraryTenant|TestAccVcfaContentLibraryItemTenant' -v -timeout 0

This will fail without this fix with the error above. With the fix, both should pass

@adambarreiro adambarreiro changed the title Fix NOT_AUTHENTICATED errors in tests Fix NOT_AUTHENTICATED errors in Content Library tests Mar 7, 2025
@adambarreiro adambarreiro marked this pull request as ready for review March 7, 2025 11:48
Copy link

@lvirbalas lvirbalas left a comment

Choose a reason for hiding this comment

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

Beautiful find!

@adambarreiro adambarreiro self-assigned this Mar 7, 2025
@adambarreiro adambarreiro merged commit 2cebf7e into vmware:main Mar 7, 2025
2 checks passed
@adambarreiro adambarreiro deleted the fix-test branch March 7, 2025 12:01
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.

3 participants