-
Notifications
You must be signed in to change notification settings - Fork 178
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
Conversation
There was a problem hiding this 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.
@@ -0,0 +1,49 @@ | |||
|
|||
# Testing Best Practices |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add example.
- 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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
terraform-provider-mongodbatlas/internal/service/advancedcluster/model_advanced_cluster_test.go
Line 24 in 66c44e6
type Result struct { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adding examples
Co-authored-by: maastha <[email protected]>
Co-authored-by: maastha <[email protected]>
Co-authored-by: Agustin Bettati <[email protected]>
|
||
- 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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
|
||
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. |
There was a problem hiding this comment.
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
- 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,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adding example
There was a problem hiding this 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'👍
- 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
Co-authored-by: Marco Suma <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job 👏
Co-authored-by: Gustavo Bazan <[email protected]>
* 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)
Description
Documents testing best practices
Link to any related issue(s): CLOUDP-242165
Type of change:
Required Checklist:
Further comments