vm_shepherd 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,104 +0,0 @@
1
- require 'vm_shepherd/vapp_manager/destroyer'
2
-
3
- module VmShepherd
4
- module VappManager
5
- RSpec.describe Destroyer do
6
- let(:login_info) do
7
- {
8
- url: 'FAKE_URL',
9
- organization: 'FAKE_ORGANIZATION',
10
- user: 'FAKE_USER',
11
- password: 'FAKE_PASSWORD',
12
- }
13
- end
14
- let(:location) do
15
- {
16
- catalog: 'FAKE_CATALOG',
17
- vdc: 'FAKE_VDC',
18
- }
19
- end
20
- let(:logger) { instance_double(Logger).as_null_object }
21
-
22
- let(:destroyer) { Destroyer.new(login_info, location, logger) }
23
-
24
- describe '#destroy' do
25
- let(:client) { instance_double(VCloudSdk::Client) }
26
- let(:vdc) { instance_double(VCloudSdk::VDC) }
27
- let(:vapp) { instance_double(VCloudSdk::VApp) }
28
- let(:vapp_name) { 'FAKE_VAPP_NAME' }
29
-
30
- context 'when the catalog exists' do
31
- before do
32
- allow(client).to receive(:catalog_exists?).with(location.fetch(:catalog)).and_return(true)
33
- end
34
-
35
- it 'uses VCloudSdk::Client to delete the vApp' do
36
- expect(client).to receive(:find_vdc_by_name).with(location.fetch(:vdc)).and_return(vdc)
37
- expect(vdc).to receive(:find_vapp_by_name).with(vapp_name).and_return(vapp)
38
- expect(vapp).to receive(:power_off)
39
- expect(vapp).to receive(:delete)
40
- expect(client).to receive(:delete_catalog_by_name).with(location.fetch(:catalog))
41
-
42
- expect(VCloudSdk::Client).to receive(:new).with(
43
- login_info.fetch(:url),
44
- [login_info.fetch(:user), login_info.fetch(:organization)].join('@'),
45
- login_info.fetch(:password),
46
- {},
47
- logger,
48
- ).and_return(client)
49
-
50
- destroyer.destroy(vapp_name)
51
- end
52
-
53
- context 'when an VCloudSdk::ObjectNotFoundError is thrown' do
54
- before do
55
- allow(VCloudSdk::Client).to receive(:new).and_return(client)
56
- allow(client).to receive(:find_vdc_by_name).and_return(vdc)
57
- allow(vdc).to receive(:find_vapp_by_name).and_return(vapp)
58
- allow(vapp).to receive(:power_off)
59
- allow(vapp).to receive(:delete)
60
-
61
- allow(client).to receive(:delete_catalog_by_name)
62
- end
63
-
64
- it 'catches the error' do
65
- allow(client).to receive(:find_vdc_by_name).and_raise(VCloudSdk::ObjectNotFoundError)
66
-
67
- expect { destroyer.destroy(vapp_name) }.not_to raise_error
68
- end
69
-
70
- it 'deletes to catalog' do
71
- expect(client).to receive(:delete_catalog_by_name).with(location.fetch(:catalog))
72
-
73
- destroyer.destroy(vapp_name)
74
- end
75
- end
76
- end
77
-
78
- context 'when the catalog does not exist' do
79
- before do
80
- allow(client).to receive(:catalog_exists?).with(location.fetch(:catalog)).and_return(false)
81
- end
82
-
83
- it 'uses VCloudSdk::Client to delete the vApp' do
84
- expect(client).to receive(:find_vdc_by_name).with(location.fetch(:vdc)).and_return(vdc)
85
- expect(vdc).to receive(:find_vapp_by_name).with(vapp_name).and_return(vapp)
86
- expect(vapp).to receive(:power_off)
87
- expect(vapp).to receive(:delete)
88
- expect(client).not_to receive(:delete_catalog_by_name).with(location.fetch(:catalog))
89
-
90
- expect(VCloudSdk::Client).to receive(:new).with(
91
- login_info.fetch(:url),
92
- [login_info.fetch(:user), login_info.fetch(:organization)].join('@'),
93
- login_info.fetch(:password),
94
- {},
95
- logger,
96
- ).and_return(client)
97
-
98
- destroyer.destroy(vapp_name)
99
- end
100
- end
101
- end
102
- end
103
- end
104
- end