Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add all_specs tag for VM-s #42

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions app/calculation/generate_tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def result
when Network
network_result
when VirtualMachine
virtual_machine_result || []
virtual_machine_result
when CustomizationSpec
spec_result
when Capability
Expand Down Expand Up @@ -112,13 +112,26 @@ def network_result
end

def virtual_machine_result
return unless subject.numbered_actor && !subject.numbered_actor.subtree.include?(subject.actor)
[{
id: ActorAPIName.result_for(subject.actor, numbered_by: subject.numbered_actor),
name: ActorAPIName.result_for(subject.actor, numbered_by: subject.numbered_actor),
config_map: {},
children: []
}]
[].tap do |results|
if subject.numbered_actor && !subject.numbered_actor.subtree.include?(subject.actor)
results << {
id: ActorAPIName.result_for(subject.actor, numbered_by: subject.numbered_actor),
name: ActorAPIName.result_for(subject.actor, numbered_by: subject.numbered_actor),
config_map: {},
children: []
}
end

if subject.customization_specs.size > 1
results << {
id: "#{subject.name}_all_specs",
name: "All specs for #{subject.name}",
config_map: {},
children: [],
priority: 95
}
end
end
end

def spec_result
Expand Down
22 changes: 21 additions & 1 deletion spec/calculations/generate_tags_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,27 @@
it { is_expected.to eq([default_result]) }
end

context 'for VM' do
let(:source_objects) { [virtual_machine] }
let(:virtual_machine) { build(:virtual_machine) }

context 'which has multiple specs' do
let!(:customization_spec) { virtual_machine.customization_specs << build(:customization_spec, virtual_machine:) }
let!(:container_customization_spec) { virtual_machine.customization_specs << build(:customization_spec, virtual_machine:, mode: :container) }
let(:result) {
{
id: "#{virtual_machine.name}_all_specs",
name: "All specs for #{virtual_machine.name}",
config_map: {},
children: [],
priority: 95
}
}

it { is_expected.to include(result) }
end
end

context 'for customization specs' do
let(:source_objects) { [customization_spec] }
let(:customization_spec) { build(:customization_spec) }
Expand All @@ -93,7 +114,6 @@
it { is_expected.to eq(result) }
end


context 'overarching group of all instances (sequential)' do
let(:customization_spec) { create(:customization_spec, virtual_machine:) }
let(:virtual_machine) { create(:virtual_machine, custom_instance_count: 10) }
Expand Down
6 changes: 3 additions & 3 deletions spec/presenters/customization_spec_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

RSpec.describe API::V3::CustomizationSpecPresenter do
subject { described_class.new(spec).as_json }
let(:spec) { create(:customization_spec) }
let(:virtual_machine) { create(:virtual_machine) }
let(:spec) { virtual_machine.host_spec }

context 'tags' do
it 'should contain OS and actor tags' do
Expand All @@ -15,10 +16,9 @@
end

context 'with nested os and actor' do
let(:virtual_machine) { create(:virtual_machine, operating_system:, actor:) }
let(:actor) { create(:actor, parent: create(:actor)) }
let(:operating_system) { create(:operating_system, parent: create(:operating_system)) }
let(:virtual_machine) { create(:virtual_machine, operating_system:, actor:) }
let(:spec) { create(:customization_spec, virtual_machine:) }

it 'should contain entire paths for both' do
expect(subject[:tags]).to eq([
Expand Down
Loading