Skip to content

Commit

Permalink
ResourcePool cloud_properties default to {}
Browse files Browse the repository at this point in the history
Signed-off-by: Maria Shaldibina <[email protected]>
  • Loading branch information
aaronshurley committed May 1, 2015
1 parent 410364e commit bfcca3c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
12 changes: 6 additions & 6 deletions bosh-director/lib/bosh/director/deployment_plan/resource_pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ def initialize(deployment_plan, spec, logger)

@logger = logger

@name = safe_property(spec, "name", :class => String)
@size = safe_property(spec, "size", :class => Integer, :optional => true)
@name = safe_property(spec, "name", class: String)
@size = safe_property(spec, "size", class: Integer, optional: true)

@cloud_properties =
safe_property(spec, "cloud_properties", :class => Hash)
safe_property(spec, "cloud_properties", class: Hash, default: {})

stemcell_spec = safe_property(spec, "stemcell", :class => Hash)
stemcell_spec = safe_property(spec, "stemcell", class: Hash)
@stemcell = Stemcell.new(self, stemcell_spec)

network_name = safe_property(spec, "network", :class => String)
network_name = safe_property(spec, "network", class: String)
@network = @deployment_plan.network(network_name)

if @network.nil?
Expand All @@ -61,7 +61,7 @@ def initialize(deployment_plan, spec, logger)
"an unknown network `#{network_name}'"
end

@env = safe_property(spec, "env", :class => Hash, :default => {})
@env = safe_property(spec, "env", class: Hash, default: {})

@idle_vms = []
@allocated_vms = []
Expand Down
18 changes: 12 additions & 6 deletions bosh-director/spec/unit/deployment_plan/resource_pool_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,19 @@ module Bosh::Director::DeploymentPlan
expect(resource_pool.env).to eq({ 'key' => 'value' })
end

%w(name cloud_properties).each do |key|
context "when #{key} is missing" do
before { valid_spec.delete(key) }
context 'when name is missing' do
before { valid_spec.delete('name') }

it 'raises an error' do
expect { ResourcePool.new(plan, valid_spec, logger) }.to raise_error(BD::ValidationMissingField)
end
it 'raises an error' do
expect { ResourcePool.new(plan, valid_spec, logger) }.to raise_error(BD::ValidationMissingField)
end
end

context 'when cloud_properties is missing' do
before { valid_spec.delete('cloud_properties') }

it 'defaults to empty hash' do
expect(resource_pool.cloud_properties).to eq({})
end
end

Expand Down

0 comments on commit bfcca3c

Please sign in to comment.