Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vishesh92 committed May 24, 2024
1 parent f8e540a commit 4d6f23b
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions pkg/cloud/instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,21 @@ var _ = Describe("Instance", func() {
unknownError := errors.New(unknownErrorMessage)

var (
mockCtrl *gomock.Controller
mockClient *cloudstack.CloudStackClient
vms *cloudstack.MockVirtualMachineServiceIface
sos *cloudstack.MockServiceOfferingServiceIface
dos *cloudstack.MockDiskOfferingServiceIface
ts *cloudstack.MockTemplateServiceIface
vs *cloudstack.MockVolumeServiceIface
client cloud.Client
mockCtrl *gomock.Controller
mockClient *cloudstack.CloudStackClient
configuration *cloudstack.MockConfigurationServiceIface
vms *cloudstack.MockVirtualMachineServiceIface
sos *cloudstack.MockServiceOfferingServiceIface
dos *cloudstack.MockDiskOfferingServiceIface
ts *cloudstack.MockTemplateServiceIface
vs *cloudstack.MockVolumeServiceIface
client cloud.Client
)

BeforeEach(func() {
mockCtrl = gomock.NewController(GinkgoT())
mockClient = cloudstack.NewMockClient(mockCtrl)
configuration = mockClient.Configuration.(*cloudstack.MockConfigurationServiceIface)
vms = mockClient.VirtualMachine.(*cloudstack.MockVirtualMachineServiceIface)
sos = mockClient.ServiceOffering.(*cloudstack.MockServiceOfferingServiceIface)
dos = mockClient.DiskOffering.(*cloudstack.MockDiskOfferingServiceIface)
Expand Down Expand Up @@ -734,8 +736,12 @@ var _ = Describe("Instance", func() {
})

Context("when destroying a VM instance", func() {
listCapabilitiesParams := &cloudstack.ListCapabilitiesParams{}
expungeDestroyParams := &cloudstack.DestroyVirtualMachineParams{}
expungeDestroyParams.SetExpunge(true)
listCapabilitiesResponse := &cloudstack.ListCapabilitiesResponse{
Capabilities: &cloudstack.Capability{Allowuserexpungerecovervm: true},
}
listVolumesParams := &cloudstack.ListVolumesParams{}
listVolumesResponse := &cloudstack.ListVolumesResponse{
Volumes: []*cloudstack.Volume{
Expand All @@ -748,6 +754,11 @@ var _ = Describe("Instance", func() {
},
}

BeforeEach(func() {
configuration.EXPECT().NewListCapabilitiesParams().Return(listCapabilitiesParams)
configuration.EXPECT().ListCapabilities(listCapabilitiesParams).Return(listCapabilitiesResponse, nil)
})

It("calls destroy and finds VM doesn't exist, then returns nil", func() {
listVolumesParams.SetVirtualmachineid(*dummies.CSMachine1.Spec.InstanceID)
listVolumesParams.SetType("DATADISK")
Expand Down

0 comments on commit 4d6f23b

Please sign in to comment.