Skip to content

Commit

Permalink
Merge pull request #75 from electrofelix/ensure-list-volumes-returns-…
Browse files Browse the repository at this point in the history
…empty-list

Return empty collection if no matching volume found
  • Loading branch information
geemus committed Oct 12, 2020
2 parents d6af037 + 4b3e66e commit f9df2f8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
20 changes: 14 additions & 6 deletions lib/fog/libvirt/requests/compute/list_volumes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def list_volumes(filter = { })
end
end
else
return [get_volume(filter)]
data << get_volume(filter)
end
data.compact
end
Expand Down Expand Up @@ -69,23 +69,31 @@ def get_volume filter = { }, raw = false
return raw ? vol : volume_to_attributes(vol)
end
end
{ }

nil
end
end

class Mock
def list_volumes(filters={ })
vol1 = mock_volume 'vol1'
vol2 = mock_volume 'vol2'
[vol1, vol2]
vols = [vol1, vol2]

if filters.keys.empty?
return vols
end

key = filters.keys.first
vols.select { |v| v[key] == filters[key] }
end

def mock_volume name
{
:pool_name => 'vol.pool.name',
:key => 'vol.key',
:id => 'vol.key',
:path => 'vol.path',
:key => "vol.#{name}", # needs to match id
:id => "vol.#{name}",
:path => "path/to/disk", # used by in mock_files/domain.xml
:name => name,
:format_type => 'raw',
:allocation => 123,
Expand Down
1 change: 1 addition & 0 deletions tests/libvirt/models/compute/volumes_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
tests('should be able to get a model') do
tests('by instance uuid').succeeds { volumes.get volumes.first.id }
end
test('filtered should be empty') { volumes.all(:name => "does-not-exist").empty? }
end

end

0 comments on commit f9df2f8

Please sign in to comment.