From 754947b98fc0ed51e358065d2063b759e6c51e0f Mon Sep 17 00:00:00 2001 From: Brian Hartsock Date: Sun, 28 Aug 2011 10:53:43 -0400 Subject: [PATCH] [rackspace|dns] records requests --- lib/fog/dns/models/rackspace/zone.rb | 4 +- lib/fog/dns/rackspace.rb | 18 ++- lib/fog/dns/requests/rackspace/add_records.rb | 34 ++++ lib/fog/dns/requests/rackspace/callback.rb | 3 + .../requests/rackspace/list_domain_details.rb | 2 + .../requests/rackspace/list_record_details.rb | 21 +++ .../dns/requests/rackspace/list_records.rb | 23 +++ .../dns/requests/rackspace/list_subdomains.rb | 2 + .../dns/requests/rackspace/modify_domain.rb | 2 + .../dns/requests/rackspace/modify_record.rb | 37 +++++ .../{delete_domain.rb => remove_domain.rb} | 4 +- .../{delete_domains.rb => remove_domains.rb} | 2 +- .../dns/requests/rackspace/remove_record.rb | 21 +++ .../dns/requests/rackspace/remove_records.rb | 20 +++ tests/dns/requests/rackspace/dns_tests.rb | 151 ++---------------- tests/dns/requests/rackspace/helper.rb | 132 +++++++++++++++ tests/dns/requests/rackspace/records_tests.rb | 81 ++++++++++ 17 files changed, 409 insertions(+), 148 deletions(-) create mode 100644 lib/fog/dns/requests/rackspace/add_records.rb create mode 100644 lib/fog/dns/requests/rackspace/list_record_details.rb create mode 100644 lib/fog/dns/requests/rackspace/list_records.rb create mode 100644 lib/fog/dns/requests/rackspace/modify_record.rb rename lib/fog/dns/requests/rackspace/{delete_domain.rb => remove_domain.rb} (84%) rename lib/fog/dns/requests/rackspace/{delete_domains.rb => remove_domains.rb} (92%) create mode 100644 lib/fog/dns/requests/rackspace/remove_record.rb create mode 100644 lib/fog/dns/requests/rackspace/remove_records.rb create mode 100644 tests/dns/requests/rackspace/helper.rb create mode 100644 tests/dns/requests/rackspace/records_tests.rb diff --git a/lib/fog/dns/models/rackspace/zone.rb b/lib/fog/dns/models/rackspace/zone.rb index e2f76a2e9..8dc235f39 100644 --- a/lib/fog/dns/models/rackspace/zone.rb +++ b/lib/fog/dns/models/rackspace/zone.rb @@ -19,7 +19,7 @@ module Fog attribute :comment def destroy - response = connection.delete_domain(identity) + response = connection.remove_domain(identity) wait_for_job response.body['jobId'], Fog.timeout true end @@ -53,7 +53,7 @@ module Fog end def create - requires :domain + requires :domain, :email data = { :name => domain, :email => email } response = connection.create_domains([data]) diff --git a/lib/fog/dns/rackspace.rb b/lib/fog/dns/rackspace.rb index 39c8ed4ee..1402f711c 100644 --- a/lib/fog/dns/rackspace.rb +++ b/lib/fog/dns/rackspace.rb @@ -16,15 +16,21 @@ module Fog collection :zones request_path 'fog/dns/requests/rackspace' - #TODO - Import/Export, modify multiple domains + #TODO - Import/Export, modify multiple domains, modify multiple records request :callback request :list_domains request :list_domain_details request :modify_domain request :create_domains - request :delete_domain - request :delete_domains + request :remove_domain + request :remove_domains request :list_subdomains + request :list_records + request :list_record_details + request :modify_record + request :remove_record + request :remove_records + request :add_records class Mock end @@ -82,6 +88,12 @@ module Fog def array_to_query_string(arr) arr.collect {|k,v| "#{k}=#{v}" }.join('&') end + + def validate_path_fragment(name, fragment) + if fragment.nil? or fragment.to_s.empty? + raise ArgumentError.new ("#{name} cannot be null or empty") + end + end end end end diff --git a/lib/fog/dns/requests/rackspace/add_records.rb b/lib/fog/dns/requests/rackspace/add_records.rb new file mode 100644 index 000000000..0100600af --- /dev/null +++ b/lib/fog/dns/requests/rackspace/add_records.rb @@ -0,0 +1,34 @@ +module Fog + module DNS + class Rackspace + class Real + def add_records(domain_id, records) + + validate_path_fragment :domain_id, domain_id + + data = { + 'records' => records.collect do |record| + record_data = { + 'name' => record[:name], + 'type' => record[:type], + 'data' => record[:data] + } + + if record.has_key? :priority + record_data['priority'] = record[:priority] + end + record_data + end + } + + request( + :expects => 202, + :method => 'POST', + :path => "domains/#{domain_id}/records", + :body => MultiJson.encode(data) + ) + end + end + end + end +end diff --git a/lib/fog/dns/requests/rackspace/callback.rb b/lib/fog/dns/requests/rackspace/callback.rb index 42e62218a..7abf4f493 100644 --- a/lib/fog/dns/requests/rackspace/callback.rb +++ b/lib/fog/dns/requests/rackspace/callback.rb @@ -3,6 +3,9 @@ module Fog class Rackspace class Real def callback(job_id) + + validate_path_fragment :job_id, job_id + request( :expects => [200, 202, 204], :method => 'GET', diff --git a/lib/fog/dns/requests/rackspace/list_domain_details.rb b/lib/fog/dns/requests/rackspace/list_domain_details.rb index a9c073beb..ccf665261 100644 --- a/lib/fog/dns/requests/rackspace/list_domain_details.rb +++ b/lib/fog/dns/requests/rackspace/list_domain_details.rb @@ -4,6 +4,8 @@ module Fog class Real def list_domain_details(domain_id, options={}) + validate_path_fragment :domain_id, domain_id + path = "domains/#{domain_id}" query_data = {} diff --git a/lib/fog/dns/requests/rackspace/list_record_details.rb b/lib/fog/dns/requests/rackspace/list_record_details.rb new file mode 100644 index 000000000..c4eb169e6 --- /dev/null +++ b/lib/fog/dns/requests/rackspace/list_record_details.rb @@ -0,0 +1,21 @@ +module Fog + module DNS + class Rackspace + class Real + def list_record_details(domain_id, record_id) + + validate_path_fragment :domain_id, domain_id + validate_path_fragment :record_id, record_id + + path = "domains/#{domain_id}/records/#{record_id}" + + request( + :expects => 200, + :method => 'GET', + :path => path + ) + end + end + end + end +end diff --git a/lib/fog/dns/requests/rackspace/list_records.rb b/lib/fog/dns/requests/rackspace/list_records.rb new file mode 100644 index 000000000..62083d20d --- /dev/null +++ b/lib/fog/dns/requests/rackspace/list_records.rb @@ -0,0 +1,23 @@ +module Fog + module DNS + class Rackspace + class Real + def list_records(domain_id, options={}) + + validate_path_fragment :domain_id, domain_id + + path = "domains/#{domain_id}/records" + if !options.empty? + path = path + '?' + array_to_query_string(options) + end + + request( + :expects => 200, + :method => 'GET', + :path => path + ) + end + end + end + end +end diff --git a/lib/fog/dns/requests/rackspace/list_subdomains.rb b/lib/fog/dns/requests/rackspace/list_subdomains.rb index dd669ccfb..3371ee167 100644 --- a/lib/fog/dns/requests/rackspace/list_subdomains.rb +++ b/lib/fog/dns/requests/rackspace/list_subdomains.rb @@ -4,6 +4,8 @@ module Fog class Real def list_subdomains(domain_id, options={}) + validate_path_fragment :domain_id, domain_id + path = "domains/#{domain_id}/subdomains" if !options.empty? path = path + '?' + array_to_query_string(options) diff --git a/lib/fog/dns/requests/rackspace/modify_domain.rb b/lib/fog/dns/requests/rackspace/modify_domain.rb index 26ea6d767..91966c7fb 100644 --- a/lib/fog/dns/requests/rackspace/modify_domain.rb +++ b/lib/fog/dns/requests/rackspace/modify_domain.rb @@ -4,6 +4,8 @@ module Fog class Real def modify_domain(domain_id, options={}) + validate_path_fragment :domain_id, domain_id + path = "domains/#{domain_id}" data = {} diff --git a/lib/fog/dns/requests/rackspace/modify_record.rb b/lib/fog/dns/requests/rackspace/modify_record.rb new file mode 100644 index 000000000..e0e613e29 --- /dev/null +++ b/lib/fog/dns/requests/rackspace/modify_record.rb @@ -0,0 +1,37 @@ +module Fog + module DNS + class Rackspace + class Real + def modify_record(domain_id, record_id, options={}) + + validate_path_fragment :domain_id, domain_id + validate_path_fragment :record_id, record_id + + path = "domains/#{domain_id}/records/#{record_id}" + data = {} + + if options.has_key? :ttl + data['ttl'] = options[:ttl] + end + if options.has_key? :name + data['name'] = options[:name] + end + if options.has_key? :data + data['data'] = options[:data] + end + + if data.empty? + return + end + + request( + :expects => [202, 204], + :method => 'PUT', + :path => path, + :body => MultiJson.encode(data) + ) + end + end + end + end +end diff --git a/lib/fog/dns/requests/rackspace/delete_domain.rb b/lib/fog/dns/requests/rackspace/remove_domain.rb similarity index 84% rename from lib/fog/dns/requests/rackspace/delete_domain.rb rename to lib/fog/dns/requests/rackspace/remove_domain.rb index e31ad5a1e..5484c84a2 100644 --- a/lib/fog/dns/requests/rackspace/delete_domain.rb +++ b/lib/fog/dns/requests/rackspace/remove_domain.rb @@ -2,7 +2,9 @@ module Fog module DNS class Rackspace class Real - def delete_domain(domain_id, options={}) + def remove_domain(domain_id, options={}) + + validate_path_fragment :domain_id, domain_id path = "domains/#{domain_id}" query_data = {} diff --git a/lib/fog/dns/requests/rackspace/delete_domains.rb b/lib/fog/dns/requests/rackspace/remove_domains.rb similarity index 92% rename from lib/fog/dns/requests/rackspace/delete_domains.rb rename to lib/fog/dns/requests/rackspace/remove_domains.rb index aed6cbc3c..35e43ee2e 100644 --- a/lib/fog/dns/requests/rackspace/delete_domains.rb +++ b/lib/fog/dns/requests/rackspace/remove_domains.rb @@ -2,7 +2,7 @@ module Fog module DNS class Rackspace class Real - def delete_domains(domain_ids, options={}) + def remove_domains(domain_ids, options={}) path = "domains?" + domain_ids.collect { |domain_id| "id=#{domain_id}" }.join('&') query_data = {} diff --git a/lib/fog/dns/requests/rackspace/remove_record.rb b/lib/fog/dns/requests/rackspace/remove_record.rb new file mode 100644 index 000000000..42c3df8bc --- /dev/null +++ b/lib/fog/dns/requests/rackspace/remove_record.rb @@ -0,0 +1,21 @@ +module Fog + module DNS + class Rackspace + class Real + def remove_record(domain_id, record_id) + + validate_path_fragment :domain_id, domain_id + validate_path_fragment :record_id, record_id + + path = "domains/#{domain_id}/records/#{record_id}" + + request( + :expects => [202, 204], + :method => 'DELETE', + :path => path + ) + end + end + end + end +end diff --git a/lib/fog/dns/requests/rackspace/remove_records.rb b/lib/fog/dns/requests/rackspace/remove_records.rb new file mode 100644 index 000000000..f1126f894 --- /dev/null +++ b/lib/fog/dns/requests/rackspace/remove_records.rb @@ -0,0 +1,20 @@ +module Fog + module DNS + class Rackspace + class Real + def remove_records(domain_id, record_ids) + + validate_path_fragment :domain_id, domain_id + + path = "domains/#{domain_id}/records?" + record_ids.collect { |record_id| "id=#{record_id}" }.join('&') + + request( + :expects => [202, 204], + :method => 'DELETE', + :path => path + ) + end + end + end + end +end diff --git a/tests/dns/requests/rackspace/dns_tests.rb b/tests/dns/requests/rackspace/dns_tests.rb index db7ad2a91..ce72c98ca 100644 --- a/tests/dns/requests/rackspace/dns_tests.rb +++ b/tests/dns/requests/rackspace/dns_tests.rb @@ -2,139 +2,8 @@ Shindo.tests('Fog::DNS[:rackspace] | DNS requests', ['rackspace', 'dns']) do @service = Fog::DNS[:rackspace] - SUBDOMAIN_FORMAT = { - 'name' => String, - 'id' => Integer, - 'created' => String, - 'updated' => String - } - - LIST_SUBDOMAINS_FORMAT = { - 'domains' => [SUBDOMAIN_FORMAT], - 'totalEntries' => Integer - } - - LIST_DOMAIN_FORMAT = { - 'domains' => [ - { - 'name' => String, - 'id' => Integer, - 'accountId' => Integer, - 'updated' => String, - 'created' => String - } - ], - 'totalEntries' => Integer, - 'links' => [ - { - 'rel' => String, - 'href' => String - } - ] - } - - RECORD_LIST_FORMAT = { - 'records' => [ - { - 'name' => String, - 'id' => String, - 'type' => String, - 'data' => String, - 'updated' => String, - 'created' => String, - 'ttl' => Integer, - 'priority' => Fog::Nullable::Integer - } - ], - #In some cases this is returned (domain details) and in some cases it isn't (create domain). Marking as nullable. - 'totalEntries' => Fog::Nullable::Integer - } - - NAME_SERVERS_FORMAT = [{ - 'name' => String - }] - - BASIC_DOMAIN_DETAIL_FORMAT = { - 'name' => String, - 'id' => Integer, - 'accountId' => Integer, - 'updated' => String, - 'created' =>String, - 'ttl' => Integer, - 'emailAddress' => String, - 'nameservers' => NAME_SERVERS_FORMAT - } - - LIST_DOMAIN_DETAILS_WITH_RECORDS = BASIC_DOMAIN_DETAIL_FORMAT.merge({ - 'recordsList' => RECORD_LIST_FORMAT - }) - - LIST_DOMAIN_DETAILS_WITH_RECORDS_AND_SUBDOMAINS_FORMAT = BASIC_DOMAIN_DETAIL_FORMAT.merge({ - 'recordsList' => RECORD_LIST_FORMAT, - 'subdomains' => [SUBDOMAIN_FORMAT] - }) - - LIST_DOMAIN_DETAILS_WITHOUT_RECORDS_AND_SUBDOMAINS_FORMAT = BASIC_DOMAIN_DETAIL_FORMAT - - CREATE_DOMAINS_FORMAT = { - 'domains' => [ - BASIC_DOMAIN_DETAIL_FORMAT.merge({ - 'recordsList' => RECORD_LIST_FORMAT - }) - ] - } - - def wait_for(response) - job_id = response.body['jobId'] - while true - response = @service.callback(job_id) - return response if response.status != 202 - sleep 5 - end - end - - def domain_tests(domain_attributes) - tests("create_domains([#{domain_attributes}])").formats(CREATE_DOMAINS_FORMAT) do - response = wait_for @service.create_domains([domain_attributes]) - @domain_details = response.body['domains'] - @domain_id = @domain_details[0]['id'] - response.body - end - - begin - if block_given? - yield - end - ensure - tests("delete_domain('#{@domain_id}')").succeeds do - wait_for @service.delete_domain @domain_id - end - end - end - - def domains_tests(domains_attributes, custom_delete = false) - tests("create_domains(#{domains_attributes})").formats(CREATE_DOMAINS_FORMAT) do - response = wait_for @service.create_domains(domains_attributes) - @domain_details = response.body['domains'] - @domain_ids = @domain_details.collect { |domain| domain['id'] } - response.body - end - - begin - if block_given? - yield - end - ensure - if !custom_delete - tests("deletes_domains(#{@domain_ids})").succeeds do - wait_for @service.delete_domains @domain_ids - end - end - end - end - tests('success on simple domain') do - domain_tests({:name => 'basictestdomain.com', :email => 'hostmaster@basictestdomain.com', :records => [{:ttl => 300, :name => 'basictestdomain.com', :type => 'A', :data => '192.168.1.1'}]}) do + domain_tests(@service, {:name => 'basictestdomain.com', :email => 'hostmaster@basictestdomain.com', :records => [{:ttl => 300, :name => 'basictestdomain.com', :type => 'A', :data => '192.168.1.1'}]}) do tests('list_domains').formats(LIST_DOMAIN_FORMAT) do @service.list_domains.body @@ -150,13 +19,13 @@ Shindo.tests('Fog::DNS[:rackspace] | DNS requests', ['rackspace', 'dns']) do tests("modify_domain('#{@domain_id}', :ttl => 500, :comment => 'woot', :email => 'randomemail@randomhost.com')").succeeds do response = @service.modify_domain @domain_id, :ttl => 500, :comment => 'woot', :email => 'randomemail@randomhost.com' - wait_for response + wait_for @service, response end end end tests('success for domain with multiple records') do - domain_tests( + domain_tests(@service, { :name => 'testdomainwithmultiplerecords.com', :email => 'hostmaster@testdomainwithmultiplerecords.com', @@ -180,7 +49,7 @@ Shindo.tests('Fog::DNS[:rackspace] | DNS requests', ['rackspace', 'dns']) do end tests('success for multiple domains') do - domains_tests( + domains_tests(@service, [ {:name => 'basictestdomain1.com', :email => 'hostmaster@basictestdomain1.com', :records => [{:ttl => 300, :name =>'basictestdomain1.com', :type => 'A', :data => '192.168.1.1'}]}, {:name => 'basictestdomain2.com', :email => 'hostmaster@basictestdomain2.com', :records => [{:ttl => 300, :name =>'basictestdomain2.com', :type => 'A', :data => '192.168.1.1'}]} @@ -188,7 +57,7 @@ Shindo.tests('Fog::DNS[:rackspace] | DNS requests', ['rackspace', 'dns']) do end tests('success for domain with subdomain') do - domains_tests( + domains_tests(@service, [ {:name => 'basictestdomain.com', :email => 'hostmaster@basictestdomain.com', :records => [{:ttl => 300, :name =>'basictestdomain.com', :type => 'A', :data => '192.168.1.1'}]}, {:name => 'subdomain.basictestdomain.com', :email => 'hostmaster@subdomain.basictestdomain.com', :records => [{:ttl => 300, :name =>'subdomain.basictestdomain.com', :type => 'A', :data => '192.168.1.1'}]} @@ -216,8 +85,8 @@ Shindo.tests('Fog::DNS[:rackspace] | DNS requests', ['rackspace', 'dns']) do @service.list_subdomains(@root_domain_id).body end - tests("delete_domain('#{@root_domain_id}', :delete_subdomains => true)") do - wait_for @service.delete_domain(@root_domain_id, :delete_subdomains => true) + tests("remove_domain('#{@root_domain_id}', :delete_subdomains => true)") do + wait_for @service, @service.remove_domain(@root_domain_id, :delete_subdomains => true) test('domain and subdomains were really deleted') do (@service.list_domains.body['domains'].collect { |domain| domain['name'] } & ['basictestdomain.com', 'subdomain.basictestdomain.com']).empty? @@ -229,7 +98,7 @@ Shindo.tests('Fog::DNS[:rackspace] | DNS requests', ['rackspace', 'dns']) do tests( 'failure') do tests('create_domain(invalid)').raises(Fog::Rackspace::Errors::BadRequest) do - wait_for @service.create_domains [{:name => 'badtestdomain.com', :email => '', :records => [{:ttl => 300, :name => 'badtestdomain.com', :type => 'A', :data => '192.168.1.1'}]}] + wait_for @service, @service.create_domains([{:name => 'badtestdomain.com', :email => '', :records => [{:ttl => 300, :name => 'badtestdomain.com', :type => 'A', :data => '192.168.1.1'}]}]) end tests('list_domains :limit => 5, :offset => 8').raises(Fog::Rackspace::Errors::BadRequest) do @@ -243,8 +112,8 @@ Shindo.tests('Fog::DNS[:rackspace] | DNS requests', ['rackspace', 'dns']) do #tests('create_domains(#{domains})').raises(Fog::Rackspace::Errors::Conflict) do # wait_for @service.create_domains(domains) #end - #tests('delete_domain(34343435)').raises(Fog::DNS::Rackspace::DeleteFault) do - # @service.delete_domain 34343435 + #tests('remove_domain(34343435)').raises(Fog::DNS::Rackspace::DeleteFault) do + # @service.remove_domain 34343435 #end end end diff --git a/tests/dns/requests/rackspace/helper.rb b/tests/dns/requests/rackspace/helper.rb new file mode 100644 index 000000000..2de0a6802 --- /dev/null +++ b/tests/dns/requests/rackspace/helper.rb @@ -0,0 +1,132 @@ +SUBDOMAIN_FORMAT = { + 'name' => String, + 'id' => Integer, + 'created' => String, + 'updated' => String +} + +LIST_SUBDOMAINS_FORMAT = { + 'domains' => [SUBDOMAIN_FORMAT], + 'totalEntries' => Integer +} + +LIST_DOMAIN_FORMAT = { + 'domains' => [ + { + 'name' => String, + 'id' => Integer, + 'accountId' => Integer, + 'updated' => String, + 'created' => String + } + ], + 'totalEntries' => Integer, + 'links' => [ + { + 'rel' => String, + 'href' => String + } + ] +} + +RECORD_FORMAT = { + 'name' => String, + 'id' => String, + 'type' => String, + 'data' => String, + 'updated' => String, + 'created' => String, + 'ttl' => Integer, + 'priority' => Fog::Nullable::Integer +} + +RECORD_LIST_FORMAT = { + 'records' => [RECORD_FORMAT], + #In some cases this is returned (domain details) and in some cases it isn't (create domain). Marking as nullable. + 'totalEntries' => Fog::Nullable::Integer +} + +NAME_SERVERS_FORMAT = [{ + 'name' => String +}] + +BASIC_DOMAIN_DETAIL_FORMAT = { + 'name' => String, + 'id' => Integer, + 'accountId' => Integer, + 'updated' => String, + 'created' =>String, + 'ttl' => Integer, + 'emailAddress' => String, + 'nameservers' => NAME_SERVERS_FORMAT +} + +LIST_DOMAIN_DETAILS_WITH_RECORDS = BASIC_DOMAIN_DETAIL_FORMAT.merge({ + 'recordsList' => RECORD_LIST_FORMAT +}) + +LIST_DOMAIN_DETAILS_WITH_RECORDS_AND_SUBDOMAINS_FORMAT = BASIC_DOMAIN_DETAIL_FORMAT.merge({ + 'recordsList' => RECORD_LIST_FORMAT, + 'subdomains' => [SUBDOMAIN_FORMAT] +}) + +LIST_DOMAIN_DETAILS_WITHOUT_RECORDS_AND_SUBDOMAINS_FORMAT = BASIC_DOMAIN_DETAIL_FORMAT + +CREATE_DOMAINS_FORMAT = { + 'domains' => [ + BASIC_DOMAIN_DETAIL_FORMAT.merge({ + 'recordsList' => RECORD_LIST_FORMAT + }) + ] +} + +def wait_for(service, response) + job_id = response.body['jobId'] + while true + response = service.callback(job_id) + return response if response.status != 202 + sleep 5 + end +end + +def domain_tests(service, domain_attributes) + tests("create_domains([#{domain_attributes}])").formats(CREATE_DOMAINS_FORMAT) do + response = wait_for service, service.create_domains([domain_attributes]) + @domain_details = response.body['domains'] + @domain_id = @domain_details[0]['id'] + response.body + end + + begin + if block_given? + yield + end + ensure + tests("remove_domain('#{@domain_id}')").succeeds do + wait_for service, service.remove_domain(@domain_id) + end + end +end + +def domains_tests(service, domains_attributes, custom_delete = false) + tests("create_domains(#{domains_attributes})").formats(CREATE_DOMAINS_FORMAT) do + response = wait_for service, service.create_domains(domains_attributes) + @domain_details = response.body['domains'] + @domain_ids = @domain_details.collect { |domain| domain['id'] } + response.body + end + + begin + if block_given? + yield + end + ensure + if !custom_delete + tests("remove_domains(#{@domain_ids})").succeeds do + wait_for service, service.remove_domains(@domain_ids) + end + end + end +end + + diff --git a/tests/dns/requests/rackspace/records_tests.rb b/tests/dns/requests/rackspace/records_tests.rb new file mode 100644 index 000000000..373584ae6 --- /dev/null +++ b/tests/dns/requests/rackspace/records_tests.rb @@ -0,0 +1,81 @@ +Shindo.tests('Fog::DNS[:rackspace] | dns records requests', ['rackspace', 'dns']) do + + @service = Fog::DNS[:rackspace] + + domain_tests(@service, {:name => 'basictestdomain.com', :email => 'hostmaster@basictestdomain.com', :records => [{:ttl => 300, :name => 'basictestdomain.com', :type => 'A', :data => '192.168.1.1'}]}) do + + tests('success on single record') do + + tests("list_records(#{@domain_id})").formats(RECORD_LIST_FORMAT) do + @service.list_records(@domain_id).body + end + + tests("add_records(#{@domain_id}, [{ :name => 'test1.basictestdomain.com', :type => 'A', :data => '192.168.2.1'}])").formats(RECORD_LIST_FORMAT) do + response = wait_for @service, @service.add_records(@domain_id, [{ :name => 'test1.basictestdomain.com', :type => 'A', :data => '192.168.2.1'}]) + @record_id = response.body['records'].first['id'] + response.body + end + + tests("list_record_details(#{@domain_id}, #{@record_id})").formats(RECORD_FORMAT) do + @service.list_record_details(@domain_id, @record_id).body + end + + tests("modify_record(#{@domain_id}, #{@record_id}, { :ttl => 500, :name => 'test2.basictestdomain.com', :data => '192.168.3.1' })").succeeds do + wait_for @service, @service.modify_record(@domain_id, @record_id, { :ttl => 500, :name => 'test2.basictestdomain.com', :data => '192.168.3.1' }) + end + + tests("remove_record(#{@domain_id}, #{@record_id})").succeeds do + wait_for @service, @service.remove_record(@domain_id, @record_id) + end + end + + tests('success on multiple records') do + + records_attributes = + [ + { :name => 'test1.basictestdomain.com', :type => 'A', :data => '192.168.2.1'}, + { :name => 'basictestdomain.com', :type => 'MX', :priority => 10, :data => 'mx.basictestdomain.com'} + ] + + tests("add_records(#{@domain_id}, #{records_attributes})").formats(RECORD_LIST_FORMAT) do + response = wait_for @service, @service.add_records(@domain_id, records_attributes) + @record_ids = response.body['records'].collect { |record| record['id'] } + response.body + end + + tests("remove_records(#{@domain_id}, #{@record_ids})").succeeds do + wait_for @service, @service.remove_records(@domain_id, @record_ids) + end + end + + tests( 'failure') do + tests("list_records('')").raises(ArgumentError) do + @service.list_records('') + end + + tests("list_records('abc')").raises(Fog::Rackspace::Errors::NotFound) do + @service.list_records('abc') + end + + tests("list_record_details(#{@domain_id}, '')").raises(ArgumentError) do + @service.list_record_details(@domain_id, '') + end + + tests("list_record_details(#{@domain_id}, 'abc')").raises(Fog::Rackspace::Errors::NotFound) do + @service.list_record_details(@domain_id, 'abc') + end + + tests("remove_record(#{@domain_id}, '')").raises(ArgumentError) do + @service.remove_record(@domain_id, '') + end + + tests("remove_record(#{@domain_id}, 'abc')").raises(Fog::Rackspace::Errors::NotFound) do + @service.remove_record(@domain_id, 'abc') + end + + tests("add_record(#{@domain_id}, [{ :name => '', :type => '', :data => ''}])").raises(Fog::Rackspace::Errors::BadRequest) do + @service.add_records(@domain_id, [{ :name => '', :type => '', :data => ''}]) + end + end + end +end