forked from ManageIQ/manageiq-ui-classic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtextual_summary_spec.rb
153 lines (124 loc) · 6.49 KB
/
textual_summary_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
describe ServiceHelper::TextualSummary do
describe ".textual_orchestration_stack" do
let(:os_cloud) { FactoryBot.create(:orchestration_stack_cloud, :name => "cloudstack1") }
let(:os_infra) { FactoryBot.create(:orchestration_stack_openstack_infra, :name => "infrastack1") }
before do
login_as FactoryBot.create(:user)
end
subject { textual_orchestration_stack }
it 'contains the link to the associated cloud stack' do
@record = FactoryBot.create(:service)
allow(@record).to receive(:orchestration_stack).and_return(os_cloud)
expect(textual_orchestration_stack).to eq(os_cloud)
end
it 'contains the link to the associated infra stack' do
@record = FactoryBot.create(:service)
allow(@record).to receive(:orchestration_stack).and_return(os_infra)
expect(textual_orchestration_stack).to eq(os_infra)
end
it 'contains no link for an invalid stack' do
os_infra.id = nil
@record = FactoryBot.create(:service)
allow(@record).to receive(:orchestration_stack).and_return(os_infra)
expect(textual_orchestration_stack[:link]).to be_nil
end
end
describe ".textual_agregate_all_vms" do
let(:vm) { FactoryBot.create(:vm_vmwware, :name => "vm1") }
before do
login_as FactoryBot.create(:user)
@record = FactoryBot.create(:service)
end
subject { textual_aggregate_all_vm_cpus }
it 'displays 0 for nil aggregate_all_vm_cpus' do
allow(@record).to receive(:aggregate_all_vm_cpus).and_return(nil)
expect(textual_aggregate_all_vm_cpus).to eq(:label => "CPU", :value => nil)
end
subject { textual_aggregate_all_vm_memory }
it 'displays 0 Bytes for nil aggregate_all_vm_memory' do
allow(@record).to receive(:aggregate_all_vm_memory).and_return(nil)
expect(textual_aggregate_all_vm_memory).to eq(:label => "Memory", :value => "0 Bytes")
end
subject { textual_aggregate_all_vm_disk_count }
it 'displays 0 for nil aggregate_all_vm_disk_count' do
allow(@record).to receive(:aggregate_all_vm_disk_count).and_return(nil)
expect(textual_aggregate_all_vm_disk_count).to eq(:label => "Disk Count", :value => nil)
end
subject { textual_aggregate_all_vm_disk_space_allocated }
it 'displays 0 Bytes for nil aggregate_all_vm_disk_space_allocated' do
allow(@record).to receive(:aggregate_all_vm_disk_space_allocated).and_return(nil)
expect(textual_aggregate_all_vm_disk_space_allocated).to eq(:label => "Disk Space Allocated", :value => "0 Bytes")
end
subject { textual_aggregate_all_vm_disk_space_used }
it 'displays 0 Bytes for nil aggregate_all_vm_disk_space_used' do
allow(@record).to receive(:aggregate_all_vm_disk_space_used).and_return(nil)
expect(textual_aggregate_all_vm_disk_space_used).to eq(:label => "Disk Space Used", :value => "0 Bytes")
end
subject { textual_aggregate_all_vm_memory_on_disk }
it 'displays 0 Bytes for nil aggregate_all_vm_memory_on_disk' do
allow(@record).to receive(:aggregate_all_vm_memory_on_disk).and_return(nil)
expect(textual_aggregate_all_vm_memory_on_disk).to eq(:label => "Memory on Disk", :value => "0 Bytes")
end
end
describe ".textual_cloud_credential" do
subject { textual_cloud_credential }
it 'displays only cloud credentials if available' do
@job = FactoryBot.create(:embedded_ansible_job)
machine_credential = FactoryBot.create(:embedded_ansible_machine_credential)
cloud_credential = FactoryBot.create(:embedded_ansible_amazon_credential)
allow(@job).to receive(:authentications).and_return([cloud_credential, machine_credential])
allow(self).to receive(:url_for_only_path).and_return('link')
expect(textual_cloud_credential).to eq(:label => "Cloud", :value => nil, :title => "Credential (Amazon)", :link => "link")
end
end
describe ".textual_vault_credential" do
subject { textual_vault_credential }
it 'displays only vault credentials if available' do
@job = FactoryBot.create(:embedded_ansible_job)
vault_credential = FactoryBot.create(:embedded_ansible_vault_credential)
allow(@job).to receive(:authentications).and_return(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::VaultCredential.where(:id => vault_credential.id))
allow(self).to receive(:url_for_only_path).and_return('link')
expect(textual_vault_credential).to eq(:label => "Vault", :value => nil, :title => "Credential (Vault)", :link => "link")
end
end
describe '.calculate_elapsed_time' do
subject { helper.send(:calculate_elapsed_time, Time.new(2019, 1, 1, 10, 0, 0, 0), Time.new(2019, 1, 1, 11, 5, 0, 0)) }
it 'calculates elapsed time' do
expect(subject).to eq("01:05:00")
end
end
before do
allow(self).to receive(:provisioning_get_job).and_return(true)
allow(self).to receive(:retirement_get_job).and_return(true)
allow(self).to receive(:textual_miq_custom_attributes).and_return([])
end
include_examples "textual_group", "Properties", %i(name description guid)
include_examples "textual_group", "Results", %i(status start_time finish_time elapsed_time owner), "provisioning_results"
include_examples "textual_group", "Details", %i(playbook repository verbosity hosts), "provisioning_details"
include_examples "textual_group", "Credentials", %i(
machine_credential
vault_credential
network_credential
cloud_credential
), "provisioning_credentials"
include_examples "textual_group", "Results", %i(status start_time finish_time elapsed_time owner), "retirement_results"
include_examples "textual_group", "Details", %i(playbook repository verbosity hosts), "retirement_details"
include_examples "textual_group", "Credentials", %i(
machine_credential
vault_credential
network_credential
cloud_credential
), "retirement_credentials"
include_examples "textual_group", "Totals for Service VMs", %i(
aggregate_all_vm_cpus
aggregate_all_vm_memory
aggregate_all_vm_disk_count
aggregate_all_vm_disk_space_allocated
aggregate_all_vm_disk_space_used
aggregate_all_vm_memory_on_disk
), "vm_totals"
include_examples "textual_group", "Lifecycle", %i(lifecycle_state retirement_date retirement_state owner group created)
include_examples "textual_group", "Relationships", %i(catalog_item parent_service orchestration_stack job custom_button_events)
include_examples "textual_group", "Custom Attributes", [], "miq_custom_attributes"
include_examples "textual_group", "Generic Objects", %i(generic_object_instances), "generic_objects"
end