-
Notifications
You must be signed in to change notification settings - Fork 421
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
Create unit tests for azuremanagedcontrolplane_reconciler.go
#4290
Comments
/triage accepted |
/assign @troy0820 |
This is going to look interesting for the following reasons.
Plan:
So overall this PR may be larger than just the test file and the adjustments to allow this to be testable. type SubnetsClient interface {
Get(ctx context.Context, resourceGroupName string, virtualNetworkName string, subnetName string, options *armnetwork.SubnetsClientGetOptions) (armnetwork.SubnetsClientGetResponse, error)
BeginCreateOrUpdate(ctx context.Context, resourceGroupName string, virtualNetworkName string, subnetName string, subnetParameters armnetwork.Subnet, options *armnetwork.SubnetsClientBeginCreateOrUpdateOptions) (*runtime.Poller[arm network.SubnetsClientCreateOrUpdateResponse], error)
BeginDelete(ctx context.Context, resourceGroupName string, virtualNetworkName string, subnetName string, options *armnetwork.SubnetsClientBeginDeleteOptions) (*runtime.Poller[armnetwork.SubnetsClientDeleteResponse], error)
}
type AzureClient struct {
subnets SubnetsClient
}
// edited
// still do the same New function to get an AzureClient Will update comment with workaround. Possible workaround //patch this method
newAzureManagedControlPlaneReconciler(scope *scope.ManagedControlPlaneScope) (*azureManagedControlPlaneService, error)
/* Patching this to return the svc that I need:
1. PrivateEndpoints (which the underlying type will be mocked)
2. ResourceHealth (which the underlying type will be mocked)
3. ....
*/
// to allow the return value in testing to coincide with the mock values Edited: Because the mocks exists, we can perform the testing without having to do this, however the next comment expresses why this is still a good idea. |
Mocks exists for (However this is not a bad idea as to get more granular with testing and push the abstraction to the clients who need to do the calls and not the mocks from the interfaces wrapped in values only known to the caller at runtime) |
/kind cleanup
azuremanagedcontrolplane_reconciler.go
This issue is part of a larger issue #3649 to help with coverage and ensure confidence
The text was updated successfully, but these errors were encountered: