mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Add options for listing hosts
Options include - Per_page - Page - FQDN Added test
This commit is contained in:
parent
e1daf5c923
commit
fc5c23a917
2 changed files with 37 additions and 5 deletions
|
@ -40,16 +40,27 @@ module Fog
|
|||
end
|
||||
|
||||
class Mock # :nodoc:all
|
||||
def list_hosts(zone_id)
|
||||
def list_hosts(zone_id, options={})
|
||||
zone = find_by_zone_id(zone_id)
|
||||
|
||||
response = Excon::Response.new
|
||||
|
||||
if zone
|
||||
response.status = 200
|
||||
response.body = {
|
||||
'hosts' => zone['hosts']
|
||||
}
|
||||
if options.empty?
|
||||
response.status = 200
|
||||
response.body = {
|
||||
'hosts' => zone['hosts']
|
||||
}
|
||||
else
|
||||
hosts = zone['hosts']
|
||||
hosts.select! {|h| h['fqdn'] == options['fqdn']} if options['fqdn']
|
||||
hosts = options['per_page'] ? hosts.each_slice(options['per_page'] - 1).to_a : hosts.each_slice(100).to_a
|
||||
hosts = options['page'] ? hosts[options['page']] : hosts[0]
|
||||
response.status = 200
|
||||
response.body = {
|
||||
'hosts' => hosts
|
||||
}
|
||||
end
|
||||
else
|
||||
response.status = 404
|
||||
end
|
||||
|
|
|
@ -348,6 +348,27 @@ Shindo.tests('Fog::DNS[:zerigo] | DNS requests', ['zerigo', 'dns']) do
|
|||
result
|
||||
end
|
||||
|
||||
test('list host records with options') do
|
||||
pending if Fog.mocking?
|
||||
|
||||
result = false
|
||||
|
||||
response = Fog::DNS[:zerigo].list_hosts(@zone_id, {:per_page=>2, :page=>1})
|
||||
if response.status == 200
|
||||
hosts = response.body['hosts']
|
||||
if (hosts.count == 2)
|
||||
hosts.each { |host|
|
||||
if (host['id'] > 0) and (host['fqdn'].length > 0) and (host['host-type'].length > 0) and
|
||||
(host['created-at'].length > 0) and (host['updated-at'].length > 0)
|
||||
result = true
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
result
|
||||
end
|
||||
|
||||
test("find host: mail.#{@domain}") do
|
||||
pending if Fog.mocking?
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue