Skip to content

Conversation

lantoli
Copy link
Member

@lantoli lantoli commented Mar 12, 2024

Description

Run Go tests using specific packages.

This allows to have a cleaner test output log and better performance as only the needed packages are run.

It also reduces the risk of skipping tests in CI because bad test names.

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

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

In future PRs there might be some opportunities to reduce duplication, e.g. generic config includes:

          generic:
            - 'internal/service/backupcompliancepolicy/*.go'
            - 'internal/service/auditing/*.go'
            - 'internal/service/x509authenticationdatabaseuser/*.go'

          ACCTEST_PACKAGES: |
            ./internal/service/backupcompliancepolicy
            ./internal/service/auditing
            ./internal/service/x509authenticationdatabaseuser

Example of new test log for assume-role (much less verbose):

TF_ACC=1 go test ./internal/provider -run '^TestAcc' -skip '^TestAccMigration' -v -parallel 20  -timeout 300m -ldflags="-s -w -X 'github.com/mongodb/terraform-provider-mongodbatlas/version.ProviderVersion=acc'"
=== RUN   TestAccSTSAssumeRole_basic
=== PAUSE TestAccSTSAssumeRole_basic
=== CONT  TestAccSTSAssumeRole_basic
--- PASS: TestAccSTSAssumeRole_basic (4.79s)
PASS
ok  	github.com/mongodb/terraform-provider-mongodbatlas/internal/provider	4.807s

Example of existing log:

?   	github.com/mongodb/terraform-provider-mongodbatlas	[no test files]
?   	github.com/mongodb/terraform-provider-mongodbatlas/internal/common/constant	[no test files]
?   	github.com/mongodb/terraform-provider-mongodbatlas/internal/common/retrystrategy	[no test files]
testing: warning: no tests to run
PASS
ok  	github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion	0.005s [no tests to run]
testing: warning: no tests to run
PASS
ok  	github.com/mongodb/terraform-provider-mongodbatlas/internal/common/dsschema	0.002s [no tests to run]
?   	github.com/mongodb/terraform-provider-mongodbatlas/internal/config	[no test files]
testing: warning: no tests to run
PASS
ok  	github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate	0.032s [no tests to run]
=== RUN   TestAccSTSAssumeRole_basic
=== PAUSE TestAccSTSAssumeRole_basic
=== CONT  TestAccSTSAssumeRole_basic
--- PASS: TestAccSTSAssumeRole_basic (8.68s)
PASS
ok  	github.com/mongodb/terraform-provider-mongodbatlas/internal/provider	8.701s


170 MORE LINES OMITTED

@lantoli lantoli marked this pull request as ready for review March 13, 2024 05:17
@lantoli lantoli requested a review from a team as a code owner March 13, 2024 05:17
Copy link
Collaborator

@oarbusi oarbusi left a comment

Choose a reason for hiding this comment

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

Nice improvement!!

Comment on lines -458 to +489
TEST_REGEX: "^TestAccConfig"
ACCTEST_PACKAGES: |
./internal/service/alertconfiguration
./internal/service/atlasuser
./internal/service/databaseuser
./internal/service/projectapikey
Copy link
Member

@AgustinBettati AgustinBettati Mar 13, 2024

Choose a reason for hiding this comment

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

like how each test group now defines explicitly which resources are included without relying on the naming indirection. Nice side benefit from the package restructure some months back.

@marcosuma
Copy link
Collaborator

This looks more neat!

@lantoli lantoli merged commit 499350a into master Mar 13, 2024
@lantoli lantoli deleted the CLOUDP-237342_go_test_packages branch March 13, 2024 14:11
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.

5 participants