From 86b3e8f94effbed8163605b9fbc8dfae57879b0d Mon Sep 17 00:00:00 2001 From: Manjunath A Kumatagi Date: Wed, 16 Feb 2022 13:34:18 +0530 Subject: [PATCH] Enhance client by adding missing mock --- .../powervs/mock/powervs_generated.go | 103 ++++++++++++++++++ pkg/cloud/services/powervs/powervs.go | 7 ++ pkg/cloud/services/powervs/service.go | 38 +++---- 3 files changed, 129 insertions(+), 19 deletions(-) diff --git a/pkg/cloud/services/powervs/mock/powervs_generated.go b/pkg/cloud/services/powervs/mock/powervs_generated.go index b5d89240e..dfcbc3c09 100644 --- a/pkg/cloud/services/powervs/mock/powervs_generated.go +++ b/pkg/cloud/services/powervs/mock/powervs_generated.go @@ -49,6 +49,21 @@ func (m *MockPowerVS) EXPECT() *MockPowerVSMockRecorder { return m.recorder } +// CreateCosImage mocks base method. +func (m *MockPowerVS) CreateCosImage(body *models.CreateCosImageImportJob) (*models.JobReference, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CreateCosImage", body) + ret0, _ := ret[0].(*models.JobReference) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// CreateCosImage indicates an expected call of CreateCosImage. +func (mr *MockPowerVSMockRecorder) CreateCosImage(body interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateCosImage", reflect.TypeOf((*MockPowerVS)(nil).CreateCosImage), body) +} + // CreateInstance mocks base method. func (m *MockPowerVS) CreateInstance(body *models.PVMInstanceCreate) (*models.PVMInstanceList, error) { m.ctrl.T.Helper() @@ -64,6 +79,20 @@ func (mr *MockPowerVSMockRecorder) CreateInstance(body interface{}) *gomock.Call return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateInstance", reflect.TypeOf((*MockPowerVS)(nil).CreateInstance), body) } +// DeleteImage mocks base method. +func (m *MockPowerVS) DeleteImage(id string) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DeleteImage", id) + ret0, _ := ret[0].(error) + return ret0 +} + +// DeleteImage indicates an expected call of DeleteImage. +func (mr *MockPowerVSMockRecorder) DeleteImage(id interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteImage", reflect.TypeOf((*MockPowerVS)(nil).DeleteImage), id) +} + // DeleteInstance mocks base method. func (m *MockPowerVS) DeleteInstance(id string) error { m.ctrl.T.Helper() @@ -78,6 +107,20 @@ func (mr *MockPowerVSMockRecorder) DeleteInstance(id interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteInstance", reflect.TypeOf((*MockPowerVS)(nil).DeleteInstance), id) } +// DeleteJob mocks base method. +func (m *MockPowerVS) DeleteJob(id string) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DeleteJob", id) + ret0, _ := ret[0].(error) + return ret0 +} + +// DeleteJob indicates an expected call of DeleteJob. +func (mr *MockPowerVSMockRecorder) DeleteJob(id interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteJob", reflect.TypeOf((*MockPowerVS)(nil).DeleteJob), id) +} + // GetAllImage mocks base method. func (m *MockPowerVS) GetAllImage() (*models.Images, error) { m.ctrl.T.Helper() @@ -122,3 +165,63 @@ func (mr *MockPowerVSMockRecorder) GetAllNetwork() *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAllNetwork", reflect.TypeOf((*MockPowerVS)(nil).GetAllNetwork)) } + +// GetCosImages mocks base method. +func (m *MockPowerVS) GetCosImages(id string) (*models.Job, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetCosImages", id) + ret0, _ := ret[0].(*models.Job) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetCosImages indicates an expected call of GetCosImages. +func (mr *MockPowerVSMockRecorder) GetCosImages(id interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetCosImages", reflect.TypeOf((*MockPowerVS)(nil).GetCosImages), id) +} + +// GetImage mocks base method. +func (m *MockPowerVS) GetImage(id string) (*models.Image, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetImage", id) + ret0, _ := ret[0].(*models.Image) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetImage indicates an expected call of GetImage. +func (mr *MockPowerVSMockRecorder) GetImage(id interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetImage", reflect.TypeOf((*MockPowerVS)(nil).GetImage), id) +} + +// GetInstance mocks base method. +func (m *MockPowerVS) GetInstance(id string) (*models.PVMInstance, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetInstance", id) + ret0, _ := ret[0].(*models.PVMInstance) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetInstance indicates an expected call of GetInstance. +func (mr *MockPowerVSMockRecorder) GetInstance(id interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetInstance", reflect.TypeOf((*MockPowerVS)(nil).GetInstance), id) +} + +// GetJob mocks base method. +func (m *MockPowerVS) GetJob(id string) (*models.Job, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetJob", id) + ret0, _ := ret[0].(*models.Job) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetJob indicates an expected call of GetJob. +func (mr *MockPowerVSMockRecorder) GetJob(id interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetJob", reflect.TypeOf((*MockPowerVS)(nil).GetJob), id) +} diff --git a/pkg/cloud/services/powervs/powervs.go b/pkg/cloud/services/powervs/powervs.go index 1318455ec..616dcda04 100644 --- a/pkg/cloud/services/powervs/powervs.go +++ b/pkg/cloud/services/powervs/powervs.go @@ -29,4 +29,11 @@ type PowerVS interface { GetAllInstance() (*models.PVMInstances, error) GetAllImage() (*models.Images, error) GetAllNetwork() (*models.Networks, error) + GetInstance(id string) (*models.PVMInstance, error) + GetImage(id string) (*models.Image, error) + DeleteImage(id string) error + CreateCosImage(body *models.CreateCosImageImportJob) (*models.JobReference, error) + GetCosImages(id string) (*models.Job, error) + GetJob(id string) (*models.Job, error) + DeleteJob(id string) error } diff --git a/pkg/cloud/services/powervs/service.go b/pkg/cloud/services/powervs/service.go index 9535f5151..95355aa5c 100644 --- a/pkg/cloud/services/powervs/service.go +++ b/pkg/cloud/services/powervs/service.go @@ -32,10 +32,10 @@ var _ PowerVS = &Service{} // Service holds the PowerVS Service specific information type Service struct { session *ibmpisession.IBMPISession - InstanceClient *instance.IBMPIInstanceClient - NetworkClient *instance.IBMPINetworkClient - ImageClient *instance.IBMPIImageClient - JobClient *instance.IBMPIJobClient + instanceClient *instance.IBMPIInstanceClient + networkClient *instance.IBMPINetworkClient + imageClient *instance.IBMPIImageClient + jobClient *instance.IBMPIJobClient } type ServiceOptions struct { @@ -46,42 +46,42 @@ type ServiceOptions struct { // CreateInstance creates the virtual machine in the Power VS service instance. func (s *Service) CreateInstance(body *models.PVMInstanceCreate) (*models.PVMInstanceList, error) { - return s.InstanceClient.Create(body) + return s.instanceClient.Create(body) } // DeleteInstance deletes the virtual machine in the Power VS service instance. func (s *Service) DeleteInstance(id string) error { - return s.InstanceClient.Delete(id) + return s.instanceClient.Delete(id) } // GetAllInstance returns all the virtual machine in the Power VS service instance. func (s *Service) GetAllInstance() (*models.PVMInstances, error) { - return s.InstanceClient.GetAll() + return s.instanceClient.GetAll() } // GetInstance returns the virtual machine in the Power VS service instance. func (s *Service) GetInstance(id string) (*models.PVMInstance, error) { - return s.InstanceClient.Get(id) + return s.instanceClient.Get(id) } // GetImage returns the image in the Power VS service instance. func (s *Service) GetImage(id string) (*models.Image, error) { - return s.ImageClient.Get(id) + return s.imageClient.Get(id) } // GetAllImage returns all the images in the Power VS service instance. func (s *Service) GetAllImage() (*models.Images, error) { - return s.ImageClient.GetAll() + return s.imageClient.GetAll() } // DeleteImage deletes the image in the Power VS service instance. func (s *Service) DeleteImage(id string) error { - return s.ImageClient.Delete(id) + return s.imageClient.Delete(id) } // CreateCosImage creates a import job to import the image in the Power VS service instance. func (s *Service) CreateCosImage(body *models.CreateCosImageImportJob) (*models.JobReference, error) { - return s.ImageClient.CreateCosImage(body) + return s.imageClient.CreateCosImage(body) } // GetCosImages returns the last import job in the Power VS service instance. @@ -96,17 +96,17 @@ func (s *Service) GetCosImages(id string) (*models.Job, error) { // GetJob returns the import job to in the Power VS service instance. func (s *Service) GetJob(id string) (*models.Job, error) { - return s.JobClient.Get(id) + return s.jobClient.Get(id) } // DeleteJob deletes the image import job in the Power VS service instance. func (s *Service) DeleteJob(id string) error { - return s.JobClient.Delete(id) + return s.jobClient.Delete(id) } // GetAllNetwork returns all the networks in the Power VS service instance. func (s *Service) GetAllNetwork() (*models.Networks, error) { - return s.NetworkClient.GetAll() + return s.networkClient.GetAll() } // NewService returns a new service for the Power VS api client. @@ -125,9 +125,9 @@ func NewService(options ServiceOptions) (*Service, error) { return &Service{ session: session, - InstanceClient: instance.NewIBMPIInstanceClient(ctx, session, options.CloudInstanceID), - NetworkClient: instance.NewIBMPINetworkClient(ctx, session, options.CloudInstanceID), - ImageClient: instance.NewIBMPIImageClient(ctx, session, options.CloudInstanceID), - JobClient: instance.NewIBMPIJobClient(ctx, session, options.CloudInstanceID), + instanceClient: instance.NewIBMPIInstanceClient(ctx, session, options.CloudInstanceID), + networkClient: instance.NewIBMPINetworkClient(ctx, session, options.CloudInstanceID), + imageClient: instance.NewIBMPIImageClient(ctx, session, options.CloudInstanceID), + jobClient: instance.NewIBMPIJobClient(ctx, session, options.CloudInstanceID), }, nil }