Skip to content

Commit

Permalink
Add in-progress case to TestServiceCreateOrUpdateResource
Browse files Browse the repository at this point in the history
  • Loading branch information
mboersma committed Aug 22, 2023
1 parent 6bbc2dc commit da6b84d
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions azure/services/asyncpoller/asyncpoller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestServiceCreateOrUpdateResource(t *testing.T) {
},
},
{
name: "valid future",
name: "future completed",
serviceName: serviceName,
expectedError: "",
expectedResult: fakeResource,
Expand All @@ -69,7 +69,23 @@ func TestServiceCreateOrUpdateResource(t *testing.T) {
s.GetLongRunningOperationState(resourceName, serviceName, infrav1.PutFuture).Return(validPutFuture),
c.Get(gomockinternal.AContext(), gomock.AssignableToTypeOf(azureResourceGetterType)).Return(fakeResource, nil),
r.Parameters(gomockinternal.AContext(), fakeResource).Return(fakeParameters, nil),
c.CreateOrUpdateAsync(gomockinternal.AContext(), gomock.AssignableToTypeOf(azureResourceGetterType), resumeToken, gomock.Any()).Return(fakeResource, fakePoller[MockCreator](), nil),
c.CreateOrUpdateAsync(gomockinternal.AContext(), gomock.AssignableToTypeOf(azureResourceGetterType), resumeToken, gomock.Any()).Return(fakeResource, nil, nil),
s.DeleteLongRunningOperationState(resourceName, serviceName, infrav1.PutFuture),
)
},
},
{
name: "future in progress",
serviceName: serviceName,
expectedError: "",
expect: func(s *mock_asyncpoller.MockFutureScopeMockRecorder, c *mock_asyncpoller.MockCreatorMockRecorder[MockCreator], r *mock_azure.MockResourceSpecGetterMockRecorder) {
gomock.InOrder(
r.ResourceName().Return(resourceName),
r.ResourceGroupName().Return(resourceGroupName),
s.GetLongRunningOperationState(resourceName, serviceName, infrav1.PutFuture).Return(validPutFuture),
c.Get(gomockinternal.AContext(), gomock.AssignableToTypeOf(azureResourceGetterType)).Return(fakeResource, nil),
r.Parameters(gomockinternal.AContext(), fakeResource).Return(fakeParameters, nil),
c.CreateOrUpdateAsync(gomockinternal.AContext(), gomock.AssignableToTypeOf(azureResourceGetterType), resumeToken, gomock.Any()).Return(nil, fakePoller[MockCreator](), nil),
s.DeleteLongRunningOperationState(resourceName, serviceName, infrav1.PutFuture),
)
},
Expand Down Expand Up @@ -97,7 +113,11 @@ func TestServiceCreateOrUpdateResource(t *testing.T) {
g.Expect(err.Error()).To(ContainSubstring(tc.expectedError))
} else {
g.Expect(err).NotTo(HaveOccurred())
g.Expect(result).To(Equal(tc.expectedResult))
if tc.expectedResult != nil {
g.Expect(result).To(Equal(tc.expectedResult))
} else {
g.Expect(result).To(BeNil())
}
}
})
}
Expand Down

0 comments on commit da6b84d

Please sign in to comment.