-
Notifications
You must be signed in to change notification settings - Fork 261
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
✨ Add mock client and 2 tests for networking package #935
✨ Add mock client and 2 tests for networking package #935
Conversation
Hi @macaptain. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/ok-to-test |
1d35770
to
ca8ccdb
Compare
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 looks great!
ca8ccdb
to
e10d1bf
Compare
This PR is two commits to make it a bit easier to review. After rebasing for the metrics changes in #932, I decided to move other metrics into the Client implementation as well for consistency in a second commit. I can squash the commits before merging if desired. |
/lgtm I think it's great PR , @hidekazuna can you take a look so that we can merge it soon (to avoid various conflict) |
return ports.Create(c.serviceClient, opts).Extract() | ||
} | ||
|
||
func (c networkClient) DeletePort(id string) 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.
I'd suggest we consider add metrics for those kind of API call as well , but no need to be in this PR as this is a pure refactory
5ca1033
to
300cf9c
Compare
/lgtm |
Can we update like following? networking/ Because CAPZ is the following. subnets/ |
Refactors the Service in the networking package to use a client with CRUD functions for manipulating OpenStack resources. This interface is combined with mockgen code generation to make the package unit testable. Two tests are added to illustrate how writing tests for the package will work. Metrics recording is also refactored to Client. It makes sense to take the metrics at the site where the OpenStack call is made, and also tidies up the 'business logic' functions when metrics recording is the responsibility of the network client implementation.
300cf9c
to
efe8353
Compare
Yes, of course. I've updated the folder structure and filenames to match. The mock package is called mock_networking and the generated file is client_mock.go, and mock_client and mock_client.go have been removed. |
/lgtm |
@macaptain Thanks updating. /approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: hidekazuna, lentzi90, macaptain The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/hold cancel |
Refactors the Service in the networking package to use a client with CRUD functions for manipulating OpenStack resources. This interface is combined with mockgen code generation to make the package unit testable.
Two tests are added to illustrate how writing tests for the package will work. The list / filter networks and subnets functions are also slightly simplified.
What this PR does / why we need it:
A refactor of the code to allow unit tests to be written for code that uses gophercloud to interface with OpenStack.
Which issue(s) this PR fixes:
Goes some way to fixing #843.
Special notes for your reviewer:
If you like this change, my plan is to move some of the 'ports' logic to the networking package and write unit tests for it, and then apply the same changes, adding mock clients for the Service in the compute package.
I tried a few things out for making the code unit testable, including using gomega's ghttp server for mocking (too much JSON), or trying to write smaller interfaces (ended up being a lot of boiler plate and manual writing of mocks), and ended up settling on this. It's a similar pattern to what's used in cluster-api-provider-aws (see instance_test.go and the generated mocks: https://github.com/kubernetes-sigs/cluster-api-provider-aws/tree/main/pkg/cloud/services/ec2), as well as using the gomega library for matching (as recommended in the Cluster API book section on Testing.)
TODOs:
/hold