Skip to content
This repository has been archived by the owner on Oct 22, 2021. It is now read-only.

Commit

Permalink
Merge pull request #95 from cloudfoundry-incubator/aduffeck/fix_memoi…
Browse files Browse the repository at this point in the history
…zing_properties

Fix memoizing instance group properties
  • Loading branch information
Mario Manno committed Nov 6, 2018
2 parents 942d54b + d28ed47 commit 1e58e74
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/bosh_deployment_manifest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def initialize(path)
end

def properties_for_instance_group(instance_group_name)
return @properties[instance_group] if @properties && @properties[instance_group]
return @properties[instance_group_name] if @properties && @properties[instance_group_name]

instance_group = @manifest['instance_groups'].find { |group| group['name'] == instance_group_name }
return [] unless instance_group
Expand All @@ -22,7 +22,7 @@ def properties_for_instance_group(instance_group_name)
end

@properties ||= {}
@properties[instance_group] = properties
@properties[instance_group_name] = properties
end

private
Expand Down
9 changes: 9 additions & 0 deletions spec/lib/bosh_deployment_manifest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,13 @@

expect(manifest.properties_for_instance_group('server')).to eq(expected_properties)
end

it 'memoizes instance group properties' do
manifest = described_class.new(File.expand_path('fixtures/bosh-deployment-manifest.yml', __dir__))
properties = manifest.properties_for_instance_group('server')

expect(manifest).to_not receive(:inject_properties)
memoized_properties = manifest.properties_for_instance_group('server')
expect(memoized_properties).to eq(properties)
end
end

0 comments on commit 1e58e74

Please sign in to comment.