Skip to content
Browse files

[xenserver] StorageRepository.save should use sane defaults

- Added required tests
- Minor StorageRepository tests refactoring
  • Loading branch information...
1 parent 9db7f34 commit 5b6ca0b98bd2a98ed7aceb04f28ac8f0c5ba2029 @rubiojr committed Jan 6, 2013
View
10 lib/fog/xenserver/models/compute/storage_repository.rb
@@ -63,12 +63,12 @@ def save
connection.create_sr( host.reference,
name,
type,
- description,
- device_config,
- physical_size,
- content_type,
+ description || '',
+ device_config || {},
+ physical_size || '0',
+ content_type || 'user',
shared || false,
- sm_config),
+ sm_config || {}),
'SR'
)
merge_attributes attr
View
57 tests/xenserver/models/compute/storage_repository_tests.rb
@@ -2,6 +2,7 @@
storage_repositories = Fog::Compute[:xenserver].storage_repositories
storage_repository = storage_repositories.first
+ conn = Fog::Compute[:xenserver]
tests('The StorageRepository model should') do
tests('have the action') do
@@ -65,23 +66,49 @@
end
end
- test('#save') do
- conn = Fog::Compute[:xenserver]
- sr = conn.storage_repositories.create :name => 'FOG TEST SR',
- :host => conn.hosts.first,
- :type => 'ext',
- :content_type => 'local SR',
- :device_config => { :device => '/dev/sdb' },
- :shared => false
- !(conn.storage_repositories.find { |sr| sr.name == 'FOG TEST SR' }).nil?
- end
-
- test('#destroy') do
- conn = Fog::Compute[:xenserver]
- sr = (conn.storage_repositories.find { |sr| sr.name == 'FOG TEST SR' })
+ tests('#save should') do
+ sr = nil
+ test('save with required attributes') do
+ sr = conn.storage_repositories.create :name => 'FOG TEST SR',
+ :host => conn.hosts.first,
+ :type => 'ext',
+ :device_config => { :device => '/dev/sdb' }
+ !(conn.storage_repositories.find { |sr| sr.name == 'FOG TEST SR' }).nil?
+ end
+ # Cleanup
+ sr.pbds.each { |pbd| pbd.unplug }
+ sr.destroy
+ test('save with additional attributes') do
+ 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.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

0 comments on commit 5b6ca0b

Please sign in to comment.
Something went wrong with that request. Please try again.