1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Wrote shindo tests for all supported requests. Resulted in a lot of debuggin of

request methods.  As well update zone/record models to work in simple cases.
This commit is contained in:
Joshua Gross 2014-01-23 16:27:04 -05:00
parent 7e61b90d85
commit c7ec9711be
30 changed files with 255 additions and 344 deletions

View file

@ -16,59 +16,23 @@ module Fog
request_path 'fog/rage4/requests/dns'
request :list_domains
request :get_domain
request :get_domain_by_name
request :create_domain
request :create_domain_vanity
request :create_reverse_domain_4
request :create_reverse_domain_6
request :get_domain
request :get_domain_by_name
request :update_domain
request :delete_domain
request :import_domain
request :sync_domain
request :export_zone_file
request :show_current_usage
request :show_global_usage
request :list_record_types
request :list_geo_regions
request :list_records
request :create_record
request :update_record
request :list_records
request :delete_record
request :set_record_failover
class Mock
def self.data
@data ||= Hash.new do |hash, key|
hash[key] = {
:domains => [],
:records => {}
}
end
end
def self.reset
@data = nil
end
def initialize(options={})
@rage4_email = options[:rage4_email]
@rage4_password = options[:rage4_api_key]
end
def data
self.class.data[@rage4_email]
end
def reset_data
self.class.data.delete(@rage4_email)
end
end
class Real
def initialize(options={})

View file

@ -5,17 +5,13 @@ module Fog
class Rage4
class Record < Fog::Model
extend Fog::Deprecation
deprecate :ip, :value
deprecate :ip=, :value=
identity :id
attribute :name
attribute :value, :aliases => "content"
attribute :ttl
attribute :created_at
attribute :updated_at
attribute :zone_id, :aliases => "domain_id"
attribute :type, :aliases => "record_type"
attribute :priority, :aliases => "prio"
@ -25,7 +21,7 @@ module Fog
end
def destroy
service.delete_record(zone.id, identity)
service.delete_record(identity)
true
end
@ -41,15 +37,13 @@ module Fog
# decide whether its a new record or update of an existing
if id.nil?
data = service.create_record(zone.id, name, type, value, options)
data = service.create_record(zone.id, name, value, type, options)
else
options[:name] = name if name
options[:content] = value if value
options[:type] = type if type
data = service.update_record(zone.id, id, options)
data = service.update_record(id, name, value, type, options)
end
merge_attributes(data.body["record"])
merge_attributes(options)
merge_atributes(name: name, value: value, type: type)
true
end

View file

@ -14,14 +14,18 @@ module Fog
def all
requires :zone
clear
data = service.list_records(zone.id).body.map {|record| record['record']}
data = service.list_records(zone.id).body
load(data)
end
def get(record_id)
requires :zone
data = service.get_record(zone.id, record_id).body["record"]
new(data)
data = service.list_records(zone.id).select {|record| record['id'] == record_id }
if !data.empty?
new(data.first)
else
new()
end
rescue Excon::Errors::NotFound
nil
end

View file

@ -10,8 +10,6 @@ module Fog
identity :id
attribute :domain, :aliases => 'name'
attribute :created_at
attribute :updated_at
def destroy
service.delete_domain(identity)
@ -21,7 +19,7 @@ module Fog
def records
@records ||= begin
Fog::DNS::Rage4::Records.new(
:zone => self,
:zone => self,
:service => service
)
end
@ -36,7 +34,7 @@ module Fog
def save
requires :domain
data = service.create_domain(domain).body["domain"]
data = service.create_domain(domain).body["id"]
merge_attributes(data)
true
end

View file

@ -11,12 +11,12 @@ module Fog
def all
clear
data = service.list_domains.body.map {|zone| zone['domain']}
data = service.list_domains.body
load(data)
end
def get(zone_id)
data = service.get_domain(zone_id).body['domain']
def get(zone_name)
data = service.get_domain_by_name(zone_name).body
new(data)
rescue Excon::Errors::NotFound
nil

View file

@ -6,6 +6,7 @@ module Fog
# Create a domain.
# ==== Parameters
# * name<~String> - domain name
# * email<~String> - email of owner of domain, defaults to email of credentials
#
# ==== Returns
# * response<~Excon::Response>:
@ -13,6 +14,8 @@ module Fog
# * 'status'<~Boolean>
# * 'id'<~Integer>
# * 'error'<~String>
#
def create_domain(name, options = {})
email = options[:email] || @rage4_email
request(

View file

@ -7,6 +7,7 @@ module Fog
# ==== Parameters
# * name<~String> - domain name
# * nsname<~String> - vanity ns domain name
# * nsprefix<~String> - prefix for the domain name, defaults to 'ns'
#
# ==== Returns
# * response<~Excon::Response>:
@ -20,7 +21,7 @@ module Fog
request(
:expects => 200,
:method => 'GET',
:path => "/rapi/createregulardomain/?name=#{name}&email=#{email}" +
:path => "/rapi/createregulardomainext/?name=#{name}&email=#{email}" +
"&nsname=#{nsname}&nsprefix=#{nsprefix}"
)
end

View file

@ -32,23 +32,23 @@ module Fog
def create_record(domain_id, name, content, type, options = {})
path = "/rapi/createregulardomain/#{domain_id}?"
path = "/rapi/createrecord/#{domain_id}"
path << "?name=#{name}&content=#{content}&type=#{type}"
path << "&priority=#{options[:priority]}" if options[:priority]
failovercontent = options[:failover] || false
path << "&failover=#{options[:failover]}"
failover = options[:failover] || 'false'
path << "&failover=#{failover}"
path << "&failovercontent=#{failovercontent}" if options[:failovercontent]
path << "&failovercontent=#{options[:failovercontent]}" if options[:failovercontent]
ttl = options[:ttl] || 3600
path << "&ttl=#{ttl}"
path << "&geozone=#{options[:geozone]}" if options[:geozone]
path << "&geozone=#{options[:geolock]}" if options[:geolock]
path << "&geozone=#{options[:geolat]}" if options[:geolat]
path << "&geozone=#{options[:geolong]}" if options[:geolong]
path << "&geolock=#{options[:geolock]}" if options[:geolock]
path << "&geolat=#{options[:geolat]}" if options[:geolat]
path << "&geolong=#{options[:geolong]}" if options[:geolong]
request(
:expects => 200,

View file

@ -3,10 +3,10 @@ module Fog
class Rage4
class Real
# Create a domain.
# Create a reverse domain for an ipv4 address .
# ==== Parameters
# * name<~String> - domain name
# * subnet<~Integer> - subnet integer
# * name<~String> - expects an ipv5 address
# * subnet<~Integer> - subnet ie: 9 for /9, range is /8 to /30
#
# ==== Returns
# * response<~Excon::Response>:

View file

@ -1,32 +0,0 @@
module Fog
module DNS
class Rage4
class Real
# Create a domain.
# ==== Parameters
# * name<~String> - domain name
# * subnet<~Integer> - subnet integer
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'status'<~Boolean>
# * 'id'<~Integer>
# * 'error'<~String>
def create_reverse_domain_6(name, subnet, options = {})
email = options[:email] || @rage4_email
request(
:expects => 200,
:method => 'GET',
:path => "/rapi/createreversedomain4/?name=#{name}&email=#{email}" +
"&subnet=#{subnet}"
)
end
end
end
end
end

View file

@ -3,7 +3,7 @@ module Fog
class Rage4
class Real
# Delete a specific omain
# Delete a specific domain
# ==== Parameters
# * id<~Integer> - numeric ID
#

View file

@ -3,9 +3,9 @@ module Fog
class Rage4
class Real
# Delete a specific omrecordain
# Delete a specific record
# ==== Parameters
# * id<~Integer> - numeric ID
# * id<~Integer> - numeric record ID
#
# ==== Returns
# * response<~Excon::Response>:

View file

@ -1,28 +0,0 @@
module Fog
module DNS
class Rage4
class Real
# Delete a specific omain
# ==== Parameters
# * id<~Integer> - numeric ID
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'status'<~Boolean>
# * 'id'<~Integer>
# * 'error'<~String>
def export_zone_file(id)
request(
:expects => 200,
:method => 'GET',
:path => "/rapi/exportzonefile/#{id}" )
end
end
end
end
end

View file

@ -3,7 +3,7 @@ module Fog
class Rage4
class Real
# Get the details for a specific domain in your account. .
# Get the details for a specific domain in your account.
# ==== Parameters
# * id<~Integer> - numeric ID
#
@ -25,20 +25,6 @@ module Fog
end
class Mock
def get_domain(id)
domain = self.data[:domains].detect do |domain|
domain["domain"]["id"] == id
end
response = Excon::Response.new
response.status = 200
response.body = domain
response
end
end
end
end
end

View file

@ -5,7 +5,7 @@ module Fog
# Get the details for a specific domain in your account.
# ==== Parameters
# * id<~String> - name of domain
# * name<~String> - name of domain
#
# ==== Returns
# * response<~Excon::Response>:
@ -25,20 +25,6 @@ module Fog
end
class Mock
def get_domain_by_name(name)
domain = self.data[:domains].detect do |domain|
domain["domain"]["name"] == id
end
response = Excon::Response.new
response.status = 200
response.body = domain
response
end
end
end
end
end

View file

@ -1,29 +0,0 @@
module Fog
module DNS
class Rage4
class Real
# Import a domain. You need to allow AXFR transfers.
# Only regular domains are supported.
# ==== Parameters
# * name<~String> - name of the domain
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'status'<~Boolean>
# * 'id'<~Integer>
# * 'error'<~String>
def import_domain(name)
request(
:expects => 200,
:method => 'GET',
:path => "/rapi/importdomain/#{name}" )
end
end
end
end
end

View file

@ -3,13 +3,15 @@ module Fog
class Rage4
class Real
# List all the record types available
# List all the geo regions available
# ==== Parameters
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Array>:
# * 'domains'<~Hash>
# * 'record types'<~Hash>
# *'name' <~String> geo record name
# *'value' <~Integer> Integer value of the type
def list_geo_regions
request(

View file

@ -9,8 +9,9 @@ module Fog
# ==== Returns
# * response<~Excon::Response>:
# * body<~Array>:
# * 'domains'<~Hash>
# * 'record types'<~Hash>
# *'name' <~String> record type name
# *'value' <~Integer> Integer value of the type
def list_record_types
request(
:expects => 200,

View file

@ -19,7 +19,7 @@ module Fog
# * id<~Integer>
# * content<~String>
# * record_type<~String>
# * prio<~Integer>
# * priority<~Integer>
def list_records(id)
request( :expects => 200,
:method => "GET",
@ -28,17 +28,6 @@ module Fog
end
class Mock
def list_records(domain)
response = Excon::Response.new
response.status = 200
response.body = self.data[:records][domain] || []
response
end
end
end
end
end

View file

@ -3,16 +3,13 @@ module Fog
class Rage4
class Real
# Delete a specific omain
# Shows current usage for a single domain
# ==== Parameters
# * id<~Integer> - numeric ID
# * id<~Integer> - domain name numeric ID
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'status'<~Boolean>
# * 'id'<~Integer>
# * 'error'<~String>
# * body<~Array>
def show_current_usage(id)
request(
:expects => 200,

View file

@ -3,16 +3,18 @@ module Fog
class Rage4
class Real
# Delete a specific omain
# Shows global usage for all domains
# ==== Parameters
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Array>
def show_global_usage
request(
:expects => 200,
:method => 'GET',
:path => "/rapi/showcurrentglobalusage/#{id}" )
:path => "/rapi/showcurrentglobalusage/" )
end

View file

@ -1,29 +0,0 @@
module Fog
module DNS
class Rage4
class Real
# Sync to external server ("Shadow Master")
# You need to allow AXFR transfers
# Only regular domains are supported
# ==== Parameters
# * name<~String> - domain name
# * ip<~String> - Ip address of remote server
# ==== Returns
#
#
def sync_domain(name, ip)
request(
:expects => 200,
:method => 'GET',
:path => "/rapi/syncdomain/?name=#{name}&server=#{ip}"
)
end
end
end
end
end

View file

@ -5,7 +5,7 @@ module Fog
# Update an existing domain
# ==== Parameters
# * domain<~Integer> - domain integer value
# * id<~Integer> - domain integer value
# * email <~String> - email of domain owner
# * nsprefix<~String> - vanity ns prefix (nullable)
# * nsname<~String> - vanity ns domain name (nullable)
@ -18,10 +18,10 @@ module Fog
# * 'status'<~Boolean>
# * 'id'<~Integer>
# * 'error'<~String>
def update_domain(name, options = {})
def update_domain(id, options = {})
email = options[:email] || @rage4_email
path = "/rapi/updatedomain/?name=#{name}&email=#{email}"
path = "/rapi/updatedomain/#{id}?email=#{email}"
path << "&nsname=#{options[:nsname]}" if options[:nsname]
path << "&nsprefix=#{options[:nsprefix]}" if options[:nsprefix]

View file

@ -3,7 +3,7 @@ module Fog
class Rage4
class Real
# Create a record
# Updates an existing record
# ==== Parameters
# * record_id <~Integer> The id of the record you wish to update
# * name <~String> Name of record, include domain name
@ -31,23 +31,23 @@ module Fog
def update_record(record_id, name, content, type, options = {})
path = "/rapi/updaterecord/#{record_id}?"
path = "/rapi/updaterecord/#{record_id}"
path << "?name=#{name}&content=#{content}&type=#{type}"
path << "&priority=#{options[:priority]}" if options[:priority]
failovercontent = options[:failover] || false
path << "&failover=#{options[:failover]}"
failover = options[:failover] || 'false'
path << "&failover=#{failover}"
path << "&failovercontent=#{failovercontent}" if options[:failovercontent]
path << "&failovercontent=#{options[:failovercontent]}" if options[:failovercontent]
ttl = options[:ttl] || 3600
path << "&ttl=#{ttl}"
path << "&geozone=#{options[:geozone]}" if options[:geozone]
path << "&geozone=#{options[:geolock]}" if options[:geolock]
path << "&geozone=#{options[:geolat]}" if options[:geolat]
path << "&geozone=#{options[:geolong]}" if options[:geolong]
path << "&geolock=#{options[:geolock]}" if options[:geolock]
path << "&geolat=#{options[:geolat]}" if options[:geolat]
path << "&geolong=#{options[:geolong]}" if options[:geolong]
request(
:expects => 200,

View file

@ -37,7 +37,7 @@ def dns_providers
}
},
:rage4 => {
:mocked => false,
:mocked => false
}
}
end

View file

@ -1,7 +1,7 @@
for provider, config in dns_providers
# FIXME: delay/timing breaks things :(
next if [:dnsmadeeasy].include?(provider)
next if [:dnsmadeeasy, :rage4].include?(provider)
domain_name = uniq_id + '.com'

View file

@ -1,7 +1,7 @@
for provider, config in dns_providers
# FIXME: delay/timing breaks things :(
next if [:dnsmadeeasy].include?(provider)
next if [:dnsmadeeasy, :rage4].include?(provider)
domain_name = uniq_id + '.com'

View file

@ -1,7 +1,7 @@
for provider, config in dns_providers
# FIXME: delay/timing breaks things :(
next if [:dnsmadeeasy].include?(provider)
next if [:dnsmadeeasy, :rage4].include?(provider)
domain_name = uniq_id + '.com'

View file

@ -1,7 +1,7 @@
for provider, config in dns_providers
# FIXME: delay/timing breaks things :(
next if [:dnsmadeeasy].include?(provider)
next if [:dnsmadeeasy, :rage4].include?(provider)
domain_name = uniq_id + '.com'

View file

@ -1,133 +1,235 @@
Shindo.tests('Fog::DNS[:rage4] | DNS requests', ['rage4', 'dns']) do
@domain = ''
@domain_id = nil
@record_id = nil
@domain_count = 0
@created_domain_list = []
tests("success") do
test("get current domain count") do
pending if Fog.mocking?
response = Fog::DNS[:rage4].list_domains()
debugger
if response.status == 200
@domain_count = response.body['list'].size
@domain_count = response.body.size
end
if response.status == 200
response.body = []
end
response.status == 200
end
test("create domain") do
pending if Fog.mocking?
domain = generate_unique_domain
response = Fog::DNS[:rage4].create_domain(domain)
if response.status == 201
@domain = response.body
if response.status == 200
@domain_id = response.body['id']
@domain = domain
end
response.status == 201
if response.status == 200 && response.body['id'] != 0
@created_domain_list << response.body['id']
end
response.status == 200 && response.body['error'] == "" &&
response.body['status'] && !@domain_id.nil?
end
test("get domain by name") do
test("create_domain_vanity") do
pending if Fog.mocking?
response = Fog::DNS[:rage4].get_domain(@domain["name"])
response.status == 200
domain = generate_unique_domain
response = Fog::DNS[:rage4].create_domain_vanity(domain, 'foo.com')
if response.status == 200 && response.body['id'] != 0
@created_domain_list << response.body['id']
end
response.status == 200 && response.body['error'] == "" &&
response.body['status']
end
test("create an A resource record") do
test("create_reverse_domain_4") do
pending if Fog.mocking?
domain = @domain["name"]
name = "www"
type = "A"
response = Fog::DNS[:rage4].create_reverse_domain_4('192.168.1.1', 29)
if response.status == 200 && response.body['id'] != 0
@created_domain_list << response.body['id']
end
response.status == 200 && response.body['error'] == "" &&
response.body['status']
end
test("get_domain") do
pending if Fog.mocking?
response = Fog::DNS[:rage4].get_domain(@domain_id)
returns(200) {response.status}
returns(@domain_id) {response.body['id']}
returns(@domain) {response.body['name']}
returns(Fog.credentials[:rage4_email]) {response.body['owner_email']}
returns(0) {response.body['type']}
returns(0) {response.body['subnet_mask']}
end
test("get_domain_by_name") do
pending if Fog.mocking?
response = Fog::DNS[:rage4].get_domain_by_name(@domain)
returns(200) {response.status}
returns(@domain_id) {response.body['id']}
returns(@domain) {response.body['name']}
returns(Fog.credentials[:rage4_email]) {response.body['owner_email']}
returns(0) {response.body['type']}
returns(0) {response.body['subnet_mask']}
end
test("update_domain") do
pending if Fog.mocking?
response = Fog::DNS[:rage4].update_domain(@domain_id, {email: 'test@test.com'})
returns(200) { response.status }
returns(true) {response.body['status']}
returns(@domain_id) {response.body['id']}
returns("") {response.body['error'] }
end
test("show_current_usage") do
pending if Fog.mocking?
response = Fog::DNS[:rage4].show_current_usage(@domain_id)
returns(200) { response.status }
returns([]) { response.body }
end
test("show_global_usage") do
pending if Fog.mocking?
response = Fog::DNS[:rage4].show_global_usage()
returns(200) { response.status }
returns([]) { response.body }
end
test("list_record_types") do
pending if Fog.mocking?
response = Fog::DNS[:rage4].list_record_types()
response.body.each do |record_type|
returns(true) { !record_type['name'].nil? }
returns(true) { !record_type['value'].nil? }
end
returns(200) { response.status }
returns(Array) { response.body.class }
end
test("list_geo_regions") do
pending if Fog.mocking?
response = Fog::DNS[:rage4].list_geo_regions()
response.body.each do |record_type|
returns(true) { !record_type['name'].nil? }
returns(true) { !record_type['value'].nil? }
end
returns(200) { response.status }
returns(Array) { response.body.class }
end
test("create_record") do
pending if Fog.mocking?
name = "www." + @domain
type = 2 #"A"
data = "1.2.3.4"
response = Fog::DNS[:rage4].create_record(domain, name, type, data)
if response.status == 201
@record = response.body
end
response.status == 201
end
test("create a MX record") do
pending if Fog.mocking?
domain = @domain["name"]
name = ""
type = "MX"
data = "10 mail.#{domain}"
options = { :ttl => 60 }
response = Fog::DNS[:rage4].create_record(domain, name, type, data, options)
response.status == 201
end
test("update a record") do
pending if Fog.mocking?
domain = @domain["name"]
record_id = @record["id"]
options = {:name => '', :type => 'A', :data => "2.3.4.5", :ttl => 600}
response = Fog::DNS[:rage4].update_record(domain, record_id, options)
response.status == 200
end
test("get record - check ip/ttl") do
pending if Fog.mocking?
response = Fog::DNS[:rage4].get_record(@domain["name"], @record['id'])
record = response.body
result = false
if response.status == 200 && record['data'] == '2.3.4.5' && record['ttl'] == 600
result = true
end
result
end
test("list records") do
pending if Fog.mocking?
response = Fog::DNS[:rage4].list_records(@domain["name"])
response = Fog::DNS[:rage4].create_record(@domain_id, name , data, type)
if response.status == 200
@records = response.body
@record_id = response.body['id']
end
(response.status == 200) and (response.body.size == 2)
response.status == 200 && response.body['error'] == "" &&
response.body['status'] && !@record_id.nil?
end
test("delete records") do
test("update_record") do
pending if Fog.mocking?
domain = @domain["name"]
result = true
@records.each do |record|
response = Fog::DNS[:rage4].delete_record(domain, record["id"])
if(response.status != 200)
result = false
break
name = "www." + @domain
type = 2 #"A"
data = "4.3.2.1"
response = Fog::DNS[:rage4].update_record(@record_id, name, data, type)
returns(@record_id) { response.body['id'] }
response.status == 200 && response.body['error'] == "" &&
response.body['status']
end
test("list_records") do
pending if Fog.mocking?
response = Fog::DNS[:rage4].list_records(@domain_id)
# returns nameserver records as well, will only verify
# the record we have tracked
response.body.each do |record|
if record['id'] == @record_id
returns(@record_id) { record['id'] }
returns("www." + @domain) { record['name'] }
returns("A") { record['type'] }
returns(3600) { record['ttl'] }
returns(nil) { record['priority'] }
returns(@domain_id) { record['domain_id'] }
returns(0) { record['geo_region_id'] }
returns(false) { record['failover_enabled'] }
returns(nil) { record['failover_content'] }
returns(true) { record['is_active'] }
returns(false) { record['geo_lock'] }
end
end
result
response.status == 200
end
test("delete domain") do
test("delete_record") do
pending if Fog.mocking?
#puts "Rage4 - Sleeping for 10 seconds, otherwise test fails because DNS Made Easy queues requests, it still might fail if DNS Made Easy is busy! MOCK IT!"
#puts "THIS MOST LIKELY WILL FAIL ON LIVE because it can take while for DNS Made Easy to create a domain/zone, changing the host to api.sandbox.rage4.com should make it work"
#sleep 10
response = Fog::DNS[:rage4].delete_record(@record_id)
returns(@record_id) { response.body['id'] }
response.status == 200 && response.body['error'] == "" &&
response.body['status']
end
test("delete_domain") do
pending if Fog.mocking?
response = nil
@created_domain_list.each do |domain_id|
response = Fog::DNS[:rage4].delete_domain(domain_id)
returns(true) {response.body['status']}
returns(domain_id) {response.body['id']}
returns("") {response.body['error'] }
end
response = Fog::DNS[:rage4].delete_domain(@domain["name"])
response.status == 200
end