Skip to content

Commit

Permalink
Cleanup client usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Jont828 committed Dec 14, 2021
1 parent 6a5db52 commit 581dce5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
6 changes: 3 additions & 3 deletions azure/services/availabilitysets/availabilitysets.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ type Service struct {

// New creates a new availability sets service.
func New(scope AvailabilitySetScope, skuCache *resourceskus.Cache) *Service {
Client := NewClient(scope)
client := NewClient(scope)
return &Service{
Scope: scope,
Client: Client,
Client: client,
resourceSKUCache: skuCache,
Reconciler: async.New(scope, Client, Client),
Reconciler: async.New(scope, client, client),
}
}

Expand Down
14 changes: 6 additions & 8 deletions azure/services/availabilitysets/availabilitysets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ func TestReconcileAvailabilitySets(t *testing.T) {
testcases := []struct {
name string
expectedError string
expect func(s *mock_availabilitysets.MockAvailabilitySetScopeMockRecorder, m *mock_availabilitysets.MockClientMockRecorder, r *mock_async.MockReconcilerMockRecorder)
expect func(s *mock_availabilitysets.MockAvailabilitySetScopeMockRecorder, r *mock_async.MockReconcilerMockRecorder)
}{
{
name: "create or update availability set",
expectedError: "",
expect: func(s *mock_availabilitysets.MockAvailabilitySetScopeMockRecorder, m *mock_availabilitysets.MockClientMockRecorder, r *mock_async.MockReconcilerMockRecorder) {
expect: func(s *mock_availabilitysets.MockAvailabilitySetScopeMockRecorder, r *mock_async.MockReconcilerMockRecorder) {
s.AvailabilitySetSpec().Return(&fakeSetSpec)
r.CreateResource(gomockinternal.AContext(), &fakeSetSpec, serviceName).Return(nil, nil)
s.UpdatePutStatus(infrav1.AvailabilitySetReadyCondition, serviceName, nil)
Expand All @@ -92,15 +92,15 @@ func TestReconcileAvailabilitySets(t *testing.T) {
{
name: "noop if no availability set spec is found",
expectedError: "",
expect: func(s *mock_availabilitysets.MockAvailabilitySetScopeMockRecorder, m *mock_availabilitysets.MockClientMockRecorder, r *mock_async.MockReconcilerMockRecorder) {
expect: func(s *mock_availabilitysets.MockAvailabilitySetScopeMockRecorder, r *mock_async.MockReconcilerMockRecorder) {
s.AvailabilitySetSpec().Return(nil)
s.UpdatePutStatus(infrav1.AvailabilitySetReadyCondition, serviceName, nil)
},
},
{
name: "missing required value in availability set spec",
expectedError: "some error with parameters",
expect: func(s *mock_availabilitysets.MockAvailabilitySetScopeMockRecorder, m *mock_availabilitysets.MockClientMockRecorder, r *mock_async.MockReconcilerMockRecorder) {
expect: func(s *mock_availabilitysets.MockAvailabilitySetScopeMockRecorder, r *mock_async.MockReconcilerMockRecorder) {
s.AvailabilitySetSpec().Return(&fakeSetSpecMissing)
r.CreateResource(gomockinternal.AContext(), &fakeSetSpecMissing, serviceName).Return(nil, parameterError)
s.UpdatePutStatus(infrav1.AvailabilitySetReadyCondition, serviceName, parameterError)
Expand All @@ -109,7 +109,7 @@ func TestReconcileAvailabilitySets(t *testing.T) {
{
name: "error in creating availability set",
expectedError: "#: Internal Server Error: StatusCode=500",
expect: func(s *mock_availabilitysets.MockAvailabilitySetScopeMockRecorder, m *mock_availabilitysets.MockClientMockRecorder, r *mock_async.MockReconcilerMockRecorder) {
expect: func(s *mock_availabilitysets.MockAvailabilitySetScopeMockRecorder, r *mock_async.MockReconcilerMockRecorder) {
s.AvailabilitySetSpec().Return(&fakeSetSpec)
r.CreateResource(gomockinternal.AContext(), &fakeSetSpec, serviceName).Return(nil, internalError)
s.UpdatePutStatus(infrav1.AvailabilitySetReadyCondition, serviceName, internalError)
Expand All @@ -125,14 +125,12 @@ func TestReconcileAvailabilitySets(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
scopeMock := mock_availabilitysets.NewMockAvailabilitySetScope(mockCtrl)
clientMock := mock_availabilitysets.NewMockClient(mockCtrl)
asyncMock := mock_async.NewMockReconciler(mockCtrl)

tc.expect(scopeMock.EXPECT(), clientMock.EXPECT(), asyncMock.EXPECT())
tc.expect(scopeMock.EXPECT(), asyncMock.EXPECT())

s := &Service{
Scope: scopeMock,
Client: clientMock,
Reconciler: asyncMock,
}

Expand Down

0 comments on commit 581dce5

Please sign in to comment.