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

doc: Documents testing best practices #2132

Merged
merged 30 commits into from
Apr 12, 2024
Merged

Conversation

lantoli
Copy link
Member

@lantoli lantoli commented Apr 10, 2024

Description

Documents testing best practices

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

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 contributing guides
  • 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

@lantoli lantoli marked this pull request as ready for review April 10, 2024 08:57
@lantoli lantoli requested a review from a team as a code owner April 10, 2024 08:57
Copy link
Member

@AgustinBettati AgustinBettati left a comment

Choose a reason for hiding this comment

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

LGTM, great to have this in place. Left minor suggestions.

contributing/testing-best-practices.md Outdated Show resolved Hide resolved
contributing/testing-best-practices.md Outdated Show resolved Hide resolved
contributing/testing-best-practices.md Outdated Show resolved Hide resolved
contributing/testing-best-practices.md Outdated Show resolved Hide resolved
contributing/testing-best-practices.md Outdated Show resolved Hide resolved
contributing/testing-best-practices.md Outdated Show resolved Hide resolved
@@ -0,0 +1,49 @@

# Testing Best Practices
Copy link
Collaborator

Choose a reason for hiding this comment

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

comment for the different sections so leaving it here. Can you add examples to our current tests when describing the guidelines? You can even pick a resource and always refer to it

Copy link
Member Author

Choose a reason for hiding this comment

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

do you mean for instance when describing variable MONGODB_ATLAS_PROJECT_ID, function ProjectIDExecution, etc. to link to some part in the code?

if that's the case I'm not sure I would do that because it's easy that links to code get outdated when we change the code/tests.

I think it's better that people just search for words like MONGODB_ATLAS_PROJECT_ID in the code to see how it can be used.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I left a couple of cases below of where to leave an example.

it's easy that links to code get outdated when we change the code/tests.
Not properly, you can make a link to a file by fixing the commit. Also if an example ever gets outdated it means also the guideline is outdated, so it doesn't really create an extra effort.

Rationale is to think: how can I speed up my team to implement the right practices and "see" what I mean?

Copy link
Member Author

Choose a reason for hiding this comment

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

adding examples


- There must be at least one `basic acceptance test` for each resource
- `Basic import tests` are done as the last step in the `basic acceptance tests`, not as a different test. Exceptions apply for more specific import tests, e.g. testing with incorrect IDs.
- Data sources are tested in the same tests as the resources. There are not specific test files or tests for data sources as a resource must typically be created. (There are very few exceptions to this, e.g. when there is only data sources but not resource)
Copy link
Collaborator

Choose a reason for hiding this comment

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

add example.

Suggested change
- Data sources are tested in the same tests as the resources. There are not specific test files or tests for data sources as a resource must typically be created. (There are very few exceptions to this, e.g. when there is only data sources but not resource)
- Data sources are tested in the same tests as the resources. There are no separate test files or tests for data sources as a resource must typically be created. (There are very few exceptions to this, e.g. when there is only data sources but not resource)

Copy link
Member Author

Choose a reason for hiding this comment

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

similar comment to above. if we have links to specific parts of the code/test i think it's easy that they get outdated. or maybe I could just reference the file not specific lines

Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe you can use permalink, e.g.

-- this link will always refer to the same line, even when the file evolves because it points to a specific commit

Copy link
Member Author

@lantoli lantoli Apr 11, 2024

Choose a reason for hiding this comment

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

yes, but that would be a link to a previous version of the file that might differ significantly from the current file. Maybe the specific line(s) are ok but the rest of the file might have content that is outdated and got improvements in the latest version. user might be confused to think that the whole file (not only the highlighted lines) has the latest best-practices. file might not even exist anymore

Copy link
Member Author

Choose a reason for hiding this comment

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

adding examples

contributing/testing-best-practices.md Outdated Show resolved Hide resolved
contributing/testing-best-practices.md Outdated Show resolved Hide resolved
contributing/testing-best-practices.md Outdated Show resolved Hide resolved
contributing/testing-best-practices.md Outdated Show resolved Hide resolved
contributing/testing-best-practices.md Outdated Show resolved Hide resolved
contributing/testing-best-practices.md Outdated Show resolved Hide resolved
contributing/testing-best-practices.md Outdated Show resolved Hide resolved
contributing/testing-best-practices.md Outdated Show resolved Hide resolved
contributing/testing-best-practices.md Outdated Show resolved Hide resolved
contributing/testing-best-practices.md Show resolved Hide resolved
contributing/testing-best-practices.md Outdated Show resolved Hide resolved

- There must be at least one `basic acceptance test` for each resource.
- `Basic import tests` are done as the last step in the `basic acceptance tests`, not as a different test. Exceptions apply for more specific import tests, e.g. testing with incorrect IDs. [Import tests](https://developer.hashicorp.com/terraform/plugin/sdkv2/resources/import#resource-acceptance-testing-implementation) verify that the [Terraform Import](https://developer.hashicorp.com/terraform/cli/import) functionality is working fine.
- Data sources are tested in the same tests as the resources. There are no separate files or tests for data sources as a resource must typically be created. (There are very few exceptions to this, e.g. when there is only data sources but not resource)
Copy link
Collaborator

Choose a reason for hiding this comment

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

this seems to belong to test organization

Copy link
Member Author

Choose a reason for hiding this comment

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

also atlas_user for example doesn't have resource

contributing/testing-best-practices.md Outdated Show resolved Hide resolved

Acceptance and migration tests can reuse projects and clusters in order to be more efficient in resource utilization.

- A project can be reused using `ProjectIDExecution`. It returns the ID of a project that is created for the current execution of tests for a resource.
Copy link
Collaborator

Choose a reason for hiding this comment

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

reading usage seems to be

Suggested change
- A project can be reused using `ProjectIDExecution`. It returns the ID of a project that is created for the current execution of tests for a resource.
- A project can be reused using `acc.ProjectIDExecution(t)`. It returns the ID of a project that is created for the current execution of tests for a resource.

But I would suggest this may be better explained with a code block that includes the imports and comments on all the bits needed,

Copy link
Member Author

Choose a reason for hiding this comment

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

adding example

Copy link
Collaborator

@marcosuma marcosuma left a comment

Choose a reason for hiding this comment

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

LGTM! I think it's also a type of documentation that is live and will always be improved. Make sure to wait also for Gus'👍

contributing/testing-best-practices.md Outdated Show resolved Hide resolved
- Migration (mig) tests: These tests are designed to ensure that after an upgrade to a new Atlas provider version, user configs do not result in unexpected plan changes, more info [here](https://developer.hashicorp.com/terraform/plugin/framework/migrating/testing). Migration tests are a subset of Acceptance tests.

## File structure
- A resource and associated data sources are implemented in a folder that is also a Go package, e.g. `advancedcluster` implementation is in [`internal/service/advancedcluster`](https://github.com/mongodb/terraform-provider-mongodbatlas/tree/master/internal/service/advancedcluster)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
- A resource and associated data sources are implemented in a folder that is also a Go package, e.g. `advancedcluster` implementation is in [`internal/service/advancedcluster`](https://github.com/mongodb/terraform-provider-mongodbatlas/tree/master/internal/service/advancedcluster)
- A resource and associated data sources are implemented in a folder that is also a Go package, e.g. `advancedcluster` implementation is in [`internal/service/advancedcluster`](https://github.com/mongodb/terraform-provider-mongodbatlas/tree/f3ff5bb678c1b07c16cc467471f483e483565427/internal/service/advancedcluster)

Copy link
Collaborator

Choose a reason for hiding this comment

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

feel free to discard if there was a rationale for non using permalink, I think it's better though

Copy link
Member Author

@lantoli lantoli Apr 12, 2024

Choose a reason for hiding this comment

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

not a strong opinion, for links that are that not probably going to change like this one (resource folder) i might use master, and from that link you can navigate through the latest advanced_cluster code

Copy link
Member Author

Choose a reason for hiding this comment

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

similar for main_test.go, if the link to that file gets broken it's really because we've changed the convention and we should have updated the doc

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks @gssbzn for all your comments. as discussed offline i'll merge the PR

Copy link
Collaborator

@EspenAlbert EspenAlbert left a comment

Choose a reason for hiding this comment

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

Great job 👏

@lantoli lantoli merged commit 5204df2 into master Apr 12, 2024
47 checks passed
@lantoli lantoli deleted the CLOUDP-242165_doc_testing branch April 12, 2024 16:14
lantoli added a commit that referenced this pull request Apr 15, 2024
* master:
  fix: Removes default comment when creating resource `mongodbatlas_privatelink_endpoint_serverless` and adds update support to `mongodbatlas_privatelink_endpoint_service_serverless` (#2133)
  doc: Documents testing best practices (#2132)
  chore: Uses correct format when setting remote (#2147)
  chore: Configures git correctly for automatic commit (#2146)
  chore: Uses PAT of bot to commit changelog updates (#2144)
  doc: Adjust RELEASING.md documentation with new process (#2142)
  fix: Fixes nil pointer dereference if `advanced_configuration` update fails in `mongodbatlas_cluster` (#2139)
  chore: Adds a  new step in release process that marks Jira version as released (#2136)
  chore: Sends Slack notification when changelog update fails (#2140)
  chore: Adds new step in release process for updating header of changelog (#2134)
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.

6 participants