-
Notifications
You must be signed in to change notification settings - Fork 84
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
UT for ReconcileCOSInstance functionality #2035
UT for ReconcileCOSInstance functionality #2035
Conversation
Hi @carmal891. 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-sigs/prow repository. |
✅ Deploy Preview for kubernetes-sigs-cluster-api-ibmcloud ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Discussed and confirmed with @Karthik-K-N to omit portions that cover control flow over checkCOSBucket and createCOSBucket within the TestReconcileCOSInstance function. Instead it can be addressed as part of #2034 |
/ok-to-test |
cloud/scope/powervs_cluster_test.go
Outdated
}, | ||
} | ||
|
||
mockResourceController.EXPECT().GetInstanceByName(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, fmt.Errorf("Fetch failed")) |
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.
In general we follow lowercase for error statements, Though it might not matter here better to follow and also elaborate a bit like
error getting instance by name
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.
sry missed out. Done
cloud/scope/powervs_cluster_test.go
Outdated
|
||
mockResourceController.EXPECT().GetInstanceByName(gomock.Any(), gomock.Any(), gomock.Any()).Return(&resourcecontrollerv2.ResourceInstance{ | ||
Name: ptr.To("test-cos-resource-name"), | ||
State: ptr.To("active"), |
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 blocking one but we can use like this as well ,( Here and at all other relevant places).
ptr.To(string(infrav1beta2.ServiceInstanceStateActive))
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.
Done
}, | ||
} | ||
|
||
mockResourceController.EXPECT().GetInstanceByName(gomock.Any(), gomock.Any(), gomock.Any()).Return(&resourcecontrollerv2.ResourceInstance{ |
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.
Can we also handle the case where cos instance does not exist and GetInstanceByName
returns nil? so we endup creating cos instance?
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.
Done
}, nil) | ||
|
||
err := clusterScope.ReconcileCOSInstance() | ||
g.Expect(err).ToNot(BeNil()) |
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.
If possible if we can check status as well https://github.com/Karthik-K-N/cluster-api-provider-ibmcloud/blob/987191d98e364d4bbfc39423d433b791dbb6b102/cloud/scope/powervs_cluster.go#L2171, that will be good.
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.
Done
cloud/scope/powervs_cluster_test.go
Outdated
g.Expect(err).ToNot(BeNil()) | ||
}) | ||
|
||
t.Run("When successfully creates resource instance", func(t *testing.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.
t.Run("When successfully creates resource instance", func(t *testing.T) { | |
t.Run("When create resource instance is successfull", func(t *testing.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.
Fixed
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.
One qq, Otherwise LGTM, Thanks
cloud/scope/powervs_cluster_test.go
Outdated
g.Expect(cosResourceInstance).To(BeNil()) | ||
g.Expect(err).To(BeNil()) | ||
}) | ||
t.Run("When cos service instance state is not active", func(t *testing.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.
whats the difference between this and next test
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 redundant test. Removed
g.Expect(clusterScope.IBMPowerVSCluster.Status.COSInstance).To(BeNil()) | ||
}) | ||
|
||
t.Run("When COS service instance is not found in IBM Cloud and hence creates COS instance in cloud", func(t *testing.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.
How about the case where a COS service instance with a given name exists in cloud and controllerCreated
is set to false
?
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.
Added
cloud/scope/powervs_cluster_test.go
Outdated
g.Expect(clusterScope.IBMPowerVSCluster.Status.COSInstance.ControllerCreated).To(Equal(ptr.To(bool(true)))) | ||
}) | ||
|
||
t.Run("When check on whether bucket exist in service instance fails", func(t *testing.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.
can you share what scenario this is covering? I'm not quite clear here
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 covers the scenario where checkCOSBucket function returns unexpected aws error (aws error apart from s3.ErrCodeNoSuchBucket, "Forbidden" & "NotFound")
Although there is the highlighted cos client issue #2034 we can still add coverage over lines mentioned below. Hence added this test case covering flow over checkCOSBucket
cluster-api-provider-ibmcloud/cloud/scope/powervs_cluster.go
Lines 2221 to 2224 in b4a2ff4
} else if err != nil { | |
s.Error(err, "failed to check COS bucket") | |
return err | |
} |
I will update the description to
When checkCOSBucket fails to determine whether bucket exist in cloud due to an unexpected error
to make it more meaningful
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.
got it, Thanks for clarifying!
cloud/scope/powervs_cluster_test.go
Outdated
mockCtrl.Finish() | ||
} | ||
|
||
t.Run("When creating cos resource instance fails due to no resource group id", func(t *testing.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.
t.Run("When creating cos resource instance fails due to no resource group id", func(t *testing.T) { | |
t.Run("When creating cos resource instance fails due to missing resource group id", func(t *testing.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.
Done
cloud/scope/powervs_cluster_test.go
Outdated
testScenarios := []struct { | ||
name string | ||
mockError error | ||
expectedExists bool |
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.
expectedExists bool | |
bucketExists bool |
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.
Done
cloud/scope/powervs_cluster_test.go
Outdated
g.Expect(err).ToNot(BeNil()) | ||
}) | ||
|
||
t.Run("When create resource instance is successful", func(t *testing.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.
t.Run("When create resource instance is successful", func(t *testing.T) { | |
t.Run("When COS resource instance creation is successful", func(t *testing.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.
Done
cloud/scope/powervs_cluster_test.go
Outdated
teardown := func() { | ||
mockCtrl.Finish() | ||
} | ||
t.Run("When checking COS bucket existence", func(t *testing.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.
t.Run("When checking COS bucket existence", func(t *testing.T) { | |
t.Run("When checking if COS bucket exists in cloud", func(t *testing.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.
Done
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
assign @mkumatag |
@carmal891 , please squash the commits |
76ca1ba
to
a990e3e
Compare
Done |
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
/hold |
@carmal891 could you please rebase the PR. |
a990e3e
to
52de141
Compare
52de141
to
0ab00b7
Compare
Done |
/hold cancel |
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
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: Amulyam24, carmal891, Prajyot-Parab 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 |
What this PR does / why we need it:
UT for ReconcileCOSInstance functionality
Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when PR gets merged):Fixes # Part of #1818
Special notes for your reviewer:
/area provider/ibmcloud
Release note: