mirror of
				https://github.com/fog/fog.git
				synced 2022-11-09 13:51:43 -05:00 
			
		
		
		
	tweaks for tests
This commit is contained in:
		
							parent
							
								
									2cba552d1b
								
							
						
					
					
						commit
						5d1b2333d4
					
				
					 11 changed files with 45 additions and 31 deletions
				
			
		| 
						 | 
				
			
			@ -1,8 +1,8 @@
 | 
			
		|||
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'fog'))
 | 
			
		||||
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'fog', 'bin'))
 | 
			
		||||
 | 
			
		||||
# TODO: Currently is true even if some of the keys in format do not appear in 
 | 
			
		||||
def validate_data_format(original_data, format)
 | 
			
		||||
# TODO: Currently is true even if some of the keys in format do not appear
 | 
			
		||||
def validate_format(original_data, format)
 | 
			
		||||
  valid = true
 | 
			
		||||
  data = original_data.dup
 | 
			
		||||
  for key, value in format
 | 
			
		||||
| 
						 | 
				
			
			@ -14,22 +14,23 @@ def validate_data_format(original_data, format)
 | 
			
		|||
      for element in datum
 | 
			
		||||
        type = value.first
 | 
			
		||||
        if type.is_a?(Hash)
 | 
			
		||||
          valid &&= validate_data_format({:element => element}, {:element => type})
 | 
			
		||||
          valid &&= validate_format({:element => element}, {:element => type})
 | 
			
		||||
        else
 | 
			
		||||
          valid &&= element.is_a?(type)
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
    when Hash
 | 
			
		||||
      valid &&= datum.is_a?(Hash)
 | 
			
		||||
      valid &&= validate_data_format(datum, value)
 | 
			
		||||
      valid &&= validate_format(datum, value)
 | 
			
		||||
    else
 | 
			
		||||
      valid &&= datum.is_a?(value)
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
  unless data.empty?
 | 
			
		||||
    p "validate_data_format did not validate [#{data.inspect}]"
 | 
			
		||||
  end
 | 
			
		||||
  valid &&= data.empty?
 | 
			
		||||
  unless valid
 | 
			
		||||
    @formatador.display_line("[red]#{original_data.inspect} does not match #{format.inspect}[/]")
 | 
			
		||||
  end
 | 
			
		||||
  valid
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
def wait_for(timeout = 600, &block)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,20 +1,18 @@
 | 
			
		|||
require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
 | 
			
		||||
 | 
			
		||||
Shindo.tests('test_helper') do
 | 
			
		||||
Shindo.tests('test_helper', 'meta') do
 | 
			
		||||
  tests('#validate_data_format') do
 | 
			
		||||
 | 
			
		||||
    tests('returns true') do
 | 
			
		||||
 | 
			
		||||
      test('when format of value matches') do
 | 
			
		||||
        validate_data_format({:a => :b}, {:a => Symbol})
 | 
			
		||||
        validate_format({:a => :b}, {:a => Symbol})
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      test('when format of nested array elements matches') do
 | 
			
		||||
        validate_data_format({:a => [:b, :c]}, {:a => [Symbol]})
 | 
			
		||||
        validate_format({:a => [:b, :c]}, {:a => [Symbol]})
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      test('when format of nested hash matches') do
 | 
			
		||||
        validate_data_format({:a => {:b => :c}}, {:a => {:b => Symbol}})
 | 
			
		||||
        validate_format({:a => {:b => :c}}, {:a => {:b => Symbol}})
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
    end
 | 
			
		||||
| 
						 | 
				
			
			@ -22,15 +20,15 @@ Shindo.tests('test_helper') do
 | 
			
		|||
    tests('returns false') do
 | 
			
		||||
 | 
			
		||||
      test('when format of value does not match') do
 | 
			
		||||
        !validate_data_format({:a => :b}, {:a => String})
 | 
			
		||||
        !validate_format({:a => :b}, {:a => String})
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      test('when not all keys are checked') do
 | 
			
		||||
        !validate_data_format({:a => :b}, {})
 | 
			
		||||
        !validate_format({:a => :b}, {})
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      test('when some keys do not appear') do
 | 
			
		||||
        !validate_data_format({}, {:a => String})
 | 
			
		||||
        !validate_format({}, {:a => String})
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
    end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -12,7 +12,7 @@ Shindo.tests('Slicehost#create_slice', 'slicehost') do
 | 
			
		|||
    end
 | 
			
		||||
 | 
			
		||||
    test('has proper output format') do
 | 
			
		||||
      validate_data_format(@data, Slicehost::Formats::SLICE.merge('root-password' => String))
 | 
			
		||||
      validate_format(@data, Slicehost::Formats::SLICE.merge('root-password' => String))
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
  end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,7 +7,7 @@ Shindo.tests('Slicehost#get_backups', 'slicehost') do
 | 
			
		|||
 | 
			
		||||
    # TODO: ensure this still works with a non-empty list
 | 
			
		||||
    test('has proper output format') do
 | 
			
		||||
      validate_data_format(@data, { 'backups' => [Slicehost::Formats::BACKUP] })
 | 
			
		||||
      validate_format(@data, { 'backups' => [Slicehost::Formats::BACKUP] })
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
  end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,9 +1,12 @@
 | 
			
		|||
Shindo.tests('Slicehost#get_flavor', 'slicehost') do
 | 
			
		||||
  tests('success') do
 | 
			
		||||
 | 
			
		||||
    test('has proper output format') do
 | 
			
		||||
    before do
 | 
			
		||||
      @data = Slicehost[:slices].get_flavor(1).body
 | 
			
		||||
      validate_data_format(@data, Slicehost::Formats::FLAVOR)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    test('has proper output format') do
 | 
			
		||||
      validate_format(@data, Slicehost::Formats::FLAVOR)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
  end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,9 +1,12 @@
 | 
			
		|||
Shindo.tests('Slicehost#get_flavors', 'slicehost') do
 | 
			
		||||
  tests('success') do
 | 
			
		||||
 | 
			
		||||
    test('has proper output format') do
 | 
			
		||||
    before do
 | 
			
		||||
      @data = Slicehost[:slices].get_flavors.body
 | 
			
		||||
      validate_data_format(@data, { 'flavors' => [Slicehost::Formats::FLAVOR] })
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    test('has proper output format') do
 | 
			
		||||
      validate_format(@data, { 'flavors' => [Slicehost::Formats::FLAVOR] })
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
  end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,9 +1,12 @@
 | 
			
		|||
Shindo.tests('Slicehost#get_image', 'slicehost') do
 | 
			
		||||
  tests('success') do
 | 
			
		||||
 | 
			
		||||
    test('has proper output format') do
 | 
			
		||||
    before do
 | 
			
		||||
      @data = Slicehost[:slices].get_image(3).body
 | 
			
		||||
      validate_data_format(@data, Slicehost::Formats::IMAGE)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    test('has proper output format') do
 | 
			
		||||
      validate_format(@data, Slicehost::Formats::IMAGE)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
  end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,9 +1,12 @@
 | 
			
		|||
Shindo.tests('Slicehost#get_images', 'slicehost') do
 | 
			
		||||
  tests('success') do
 | 
			
		||||
 | 
			
		||||
    test('has proper output format') do
 | 
			
		||||
    before do
 | 
			
		||||
      @data = Slicehost[:slices].get_images.body
 | 
			
		||||
      validate_data_format(@data, { 'images' => [Slicehost::Formats::IMAGE] })
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    test('has proper output format') do
 | 
			
		||||
      validate_format(@data, { 'images' => [Slicehost::Formats::IMAGE] })
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
  end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,6 +4,7 @@ Shindo.tests('Slicehost#get_slice', 'slicehost') do
 | 
			
		|||
    before do
 | 
			
		||||
      @data = Slicehost[:slices].create_slice(1, 3, 'foggetslice').body
 | 
			
		||||
      @id = @data['id']
 | 
			
		||||
      @data = Slicehost[:slices].get_slice(@id).body
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    after do
 | 
			
		||||
| 
						 | 
				
			
			@ -12,8 +13,7 @@ Shindo.tests('Slicehost#get_slice', 'slicehost') do
 | 
			
		|||
    end
 | 
			
		||||
 | 
			
		||||
    test('has proper output format') do
 | 
			
		||||
      @data = Slicehost[:slices].get_slice(@id).body
 | 
			
		||||
      validate_data_format(@data, Slicehost::Formats::SLICE)
 | 
			
		||||
      validate_format(@data, Slicehost::Formats::SLICE)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
  end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,9 +1,12 @@
 | 
			
		|||
Shindo.tests('Slicehost#get_slices', 'slicehost') do
 | 
			
		||||
  tests('success') do
 | 
			
		||||
 | 
			
		||||
    test('has proper output format') do
 | 
			
		||||
    before do
 | 
			
		||||
      @data = Slicehost[:slices].get_slices.body
 | 
			
		||||
      validate_data_format(@data, { 'slices' => [Slicehost::Formats::SLICE] })
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    test('has proper output format') do
 | 
			
		||||
      validate_format(@data, { 'slices' => [Slicehost::Formats::SLICE] })
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
  end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,7 +14,7 @@ Shindo.tests('Slicehost#reboot_slice', 'slicehost') do
 | 
			
		|||
    end
 | 
			
		||||
 | 
			
		||||
    test('has proper output format') do
 | 
			
		||||
      validate_data_format(@data, Slicehost::Formats::SLICE)
 | 
			
		||||
      validate_format(@data, Slicehost::Formats::SLICE)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
  end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue