1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/tests/vcloud_director/requests/compute/query_tests.rb
Paul Thornthwaite ec8b940b2c Standardise on collection methods
Done with `rubocop --auto-correct --only CollectionMethods`
2014-05-26 16:22:07 +01:00

99 lines
4.1 KiB
Ruby

Shindo.tests('Compute::VcloudDirector | query requests', ['vclouddirector']) do
@service = Fog::Compute::VcloudDirector.new
tests('retrieve a summary list of all typed queries types') do
tests('#get_execute_query') do
@query_list = @service.get_execute_query.body
tests(':type').returns('application/vnd.vmware.vcloud.query.queryList+xml') do
@query_list[:type]
end
end
end
# for each queriable type, query and check that each available format
# returns a result that matches the base schema
#
@query_list[:Link].select do |link|
link[:rel] == 'down'
end.sort_by do |link|
[link[:name], link[:href]]
end.each do |link|
href = Nokogiri::XML.fragment(link[:href])
query = CGI.parse(URI.parse(href.text).query)
type = query['type'].first
format = query['format'].first
next if %w[right role strandedUser].include?(type)
tests("type => #{type}, format => #{format}") do
pending if Fog.mocking? && (format != 'records' || type != 'orgVdcNetwork')
tests("#get_execute_query").data_matches_schema(VcloudDirector::Compute::Schema::CONTAINER_TYPE) do
@body = @service.get_execute_query(type, :format => format).body
end
tests("resource type").returns(link[:type]) { @body[:type] }
unless ( type == 'event' || type == 'edgeGateway' )
records_key = @body.keys.find {|key| key.to_s =~ /Record|Reference$/}
if records = @body[records_key]
records.first do |record|
case format
when 'records'
tests("record is correct schema").data_matches_schema(VcloudDirector::Compute::Schema::REFERENCE_TYPE) do
record
end
end
end
end
end
end
end
if Fog.mocking?
tests('ensure Mock logic is sound') do
tests('#get_execute_query') do
tests('orgVdcNetwork') do
output = @service.get_execute_query('orgVdcNetwork').body
tests('all records').returns(@service.data[:networks].size) do
output[:OrgVdcNetworkRecords].size
end
output = @service.get_execute_query('orgVdcNetwork', :filter => 'name==vDC1 backend network').body
tests(':filter by name').returns(1) do
output[:OrgVdcNetworkRecords].size
end
tests(':page option is ok if :page == 1').returns(@service.data[:networks].size) do
output = @service.get_execute_query('orgVdcNetwork', :page => '1').body
output[:OrgVdcNetworkRecords].size
end
tests('AND expression in :filter raises MockNotImplemented').raises(Fog::Errors::MockNotImplemented) do
@service.get_execute_query('orgVdcNetwork', :filter => 'name==Default Network;thing==wibble')
end
tests('OR expression in :filter raises MockNotImplemented').raises(Fog::Errors::MockNotImplemented) do
@service.get_execute_query('orgVdcNetwork', :filter => 'name==Default Network,thing==wibble')
end
tests('sortAsc option raises MockNotImplemented').raises(Fog::Errors::MockNotImplemented) do
@service.get_execute_query('orgVdcNetwork', :sortAsc => 'name')
end
tests('sortDesc option raises MockNotImplemented').raises(Fog::Errors::MockNotImplemented) do
@service.get_execute_query('orgVdcNetwork', :sortDesc => 'name')
end
tests('page option raises MockNotImplemented').raises(Fog::Errors::MockNotImplemented) do
@service.get_execute_query('orgVdcNetwork', :page => '2')
end
tests('pageSize option raises MockNotImplemented').raises(Fog::Errors::MockNotImplemented) do
@service.get_execute_query('orgVdcNetwork', :pageSize => '50')
end
tests('offset option raises MockNotImplemented').raises(Fog::Errors::MockNotImplemented) do
@service.get_execute_query('orgVdcNetwork', :offset => '5')
end
tests('fields option raises MockNotImplemented').raises(Fog::Errors::MockNotImplemented) do
@service.get_execute_query('orgVdcNetwork', :fields => 'name,thing')
end
end
end
end
end
end