Skip to content

Commit

Permalink
[xenserver] StorageRepository.save should use sane defaults
Browse files Browse the repository at this point in the history
- Added required tests
- Minor StorageRepository tests refactoring
  • Loading branch information
rubiojr committed Jan 6, 2013
1 parent 9db7f34 commit 5b6ca0b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 20 deletions.
10 changes: 5 additions & 5 deletions lib/fog/xenserver/models/compute/storage_repository.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ def save
connection.create_sr( host.reference, connection.create_sr( host.reference,
name, name,
type, type,
description, description || '',
device_config, device_config || {},
physical_size, physical_size || '0',
content_type, content_type || 'user',
shared || false, shared || false,
sm_config), sm_config || {}),
'SR' 'SR'
) )
merge_attributes attr merge_attributes attr
Expand Down
57 changes: 42 additions & 15 deletions tests/xenserver/models/compute/storage_repository_tests.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


storage_repositories = Fog::Compute[:xenserver].storage_repositories storage_repositories = Fog::Compute[:xenserver].storage_repositories
storage_repository = storage_repositories.first storage_repository = storage_repositories.first
conn = Fog::Compute[:xenserver]


tests('The StorageRepository model should') do tests('The StorageRepository model should') do
tests('have the action') do tests('have the action') do
Expand Down Expand Up @@ -65,23 +66,49 @@
end end
end end


test('#save') do tests('#save should') do
conn = Fog::Compute[:xenserver] sr = nil
sr = conn.storage_repositories.create :name => 'FOG TEST SR', test('save with required attributes') do
:host => conn.hosts.first, sr = conn.storage_repositories.create :name => 'FOG TEST SR',
:type => 'ext', :host => conn.hosts.first,
:content_type => 'local SR', :type => 'ext',
:device_config => { :device => '/dev/sdb' }, :device_config => { :device => '/dev/sdb' }
:shared => false !(conn.storage_repositories.find { |sr| sr.name == 'FOG TEST SR' }).nil?
!(conn.storage_repositories.find { |sr| sr.name == 'FOG TEST SR' }).nil? end
end # Cleanup

sr.pbds.each { |pbd| pbd.unplug }
test('#destroy') do sr.destroy
conn = Fog::Compute[:xenserver] test('save with additional attributes') do
sr = (conn.storage_repositories.find { |sr| sr.name == 'FOG TEST SR' }) sr = conn.storage_repositories.create :name => 'FOG TEST SR',
:host => conn.hosts.first,
:type => 'ext',
:content_type => 'user',
:device_config => { :device => '/dev/sdb' },
:shared => false
!(conn.storage_repositories.find { |sr| sr.name == 'FOG TEST SR' }).nil?
end
# Cleanup
sr.pbds.each { |pbd| pbd.unplug } sr.pbds.each { |pbd| pbd.unplug }
sr.destroy sr.destroy
(conn.storage_repositories.find { |sr| sr.name == 'FOG TEST SR' }).nil? test('return sane defaults') do
sr = conn.storage_repositories.create :name => 'FOG TEST SR',
:host => conn.hosts.first,
:type => 'ext',
:device_config => { :device => '/dev/sdb' }
sr.reload
(sr.content_type == 'user') and \
(sr.shared == false) and (sr.sm_config.is_a? Hash) and \
(sr.description == '')
end
end

tests('#destroy should') do
test('destroy existing FOG TEST SR') do
sr = (conn.storage_repositories.find { |sr| sr.name == 'FOG TEST SR' })
sr.pbds.each { |pbd| pbd.unplug }
sr.destroy
(conn.storage_repositories.find { |sr| sr.name == 'FOG TEST SR' }).nil?
end
end end


end end

0 comments on commit 5b6ca0b

Please sign in to comment.