Skip to content
This repository was archived by the owner on Jun 2, 2021. It is now read-only.

Commit 630a159

Browse files
selzocreidmit
andcommitted
Fix 500 when diffing manifests with metadata
[#174432303] Co-authored-by: Chris Selzo <cselzo@pivotal.io> Co-authored-by: Reid Mitchell <rmitchell@pivotal.io>
1 parent cfd2262 commit 630a159

2 files changed

Lines changed: 22 additions & 7 deletions

File tree

app/actions/space_diff_manifest.rb

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,13 @@ def self.filter_manifest_app_hash(manifest_app_hash)
4343
end
4444

4545
if manifest_app_hash.key? 'metadata'
46-
manifest_app_hash['metadata'] = manifest_app_hash['metadata'].map do |hash|
47-
hash.slice(
48-
'labels',
49-
'annotations'
50-
)
51-
end
52-
manifest_app_hash = manifest_app_hash.except('metadata') if manifest_app_hash['metadata'] == [{}]
46+
manifest_app_hash['metadata'] = manifest_app_hash['metadata'].slice(
47+
'labels',
48+
'annotations'
49+
)
50+
manifest_app_hash = manifest_app_hash.except('metadata') if manifest_app_hash['metadata'] == {}
5351
end
52+
5453
manifest_app_hash
5554
end
5655

spec/unit/actions/space_diff_manifest_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,22 @@ module VCAP::CloudController
7373
end
7474
end
7575

76+
context 'metadata is added' do
77+
before do
78+
default_manifest['applications'][0]['metadata'] = {
79+
'labels' => { 'foo' => 'bar' },
80+
'annotations' => { 'baz' => 'qux' }
81+
}
82+
end
83+
84+
it 'returns the correct diff' do
85+
expect(subject).to eq([
86+
{ 'op' => 'add', 'path' => '/applications/0/metadata/labels/foo', 'value' => 'bar' },
87+
{ 'op' => 'add', 'path' => '/applications/0/metadata/annotations/baz', 'value' => 'qux' },
88+
])
89+
end
90+
end
91+
7692
context 'when there is a change inside of a nested hash' do
7793
before do
7894
default_manifest['applications'][0]['processes'][0].delete('memory')

0 commit comments

Comments
 (0)