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
feat: Adds test mock support with Mockery #287
Conversation
@@ -41,3 +41,9 @@ new-release: | |||
update-version: | |||
## When manually updating major version | |||
./releaser/scripts/update-version.sh | |||
|
|||
.PHONY: generate_mocks | |||
generate_mocks: |
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.
We need to add mocking to contributing guide
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.
Let's make follow up PR. This is large PR anyway
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.
ok
|
||
.PHONY: generate_mocks | ||
generate_mocks: | ||
go install github.com/vektra/mockery/v2@v2.42.1 |
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.
Antipattern. If we need mockery installed let's keep it at dependency level so we can get it automatically updated etc.
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.
Let's make follow up PR.
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.
ok
|
||
func TestListClusters(t *testing.T) { | ||
// Create mock API. | ||
clusterAPI := mockadmin.NewClustersApi(t) |
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 think this is very good example on how to use mockery but does not fit to example of SDK mocking.
Mocking example should use "go.mongodb.org/atlas-sdk/v20231115008/admin" interface that is replaced by mocked implementation.
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.
Let's make follow up PR.
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 sure I understand, we have import "go.mongodb.org/atlas-sdk/v20231115008/admin" and the admin interface is being used in the tests:
func MyFunctionCallingListClusters(clusterAPI admin.ClustersApi) (int, error)
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.
Apologies. I got confused by the name: MyFunctionCallingListClusters
. LGTM
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
All comments can be follow ups.
Do we know how much build time will increase with mocking step? |
SGTM! Thank you
Let's not do it. If we see it taking longer after merge and take action if needed. For the future reference - it is best to push generated changes + tests in separate PR. We used that pattern for SDK automation so every automation PR can be easily reviewed and referenced. No need to change this PR |
Co-authored-by: Wojciech Trocki <w.trocki@mongodb.com>
Description
We are adding Testify mocks generated by Mockery to make it easier to test use of SDK from your packages.
Example of use in Terraform Atlas Provider repo: mongodb/terraform-provider-mongodbatlas#2069
Review
Files in mockadmin folder are auto-generated.
Type of change:
Required Checklist:
make fmt
and formatted my codeFurther comments