mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[dreamhost|dns] Emulate zone model and collection, added tests
Dreamhost API has no concept of Zone, but we can emulate it.
This commit is contained in:
parent
4c95f8e209
commit
9dd24ab2bd
8 changed files with 203 additions and 1 deletions
|
@ -10,7 +10,9 @@ module Fog
|
|||
|
||||
model_path 'fog/dreamhost/models/dns'
|
||||
model :record
|
||||
model :zone
|
||||
collection :records
|
||||
collection :zones
|
||||
|
||||
request_path 'fog/dreamhost/requests/dns'
|
||||
request :create_record
|
||||
|
|
|
@ -28,6 +28,11 @@ module Fog
|
|||
|
||||
end
|
||||
|
||||
def new(attributes = {})
|
||||
requires :zone
|
||||
super({ :zone => zone }.merge!(attributes))
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
57
lib/fog/dreamhost/models/dns/zone.rb
Normal file
57
lib/fog/dreamhost/models/dns/zone.rb
Normal file
|
@ -0,0 +1,57 @@
|
|||
require 'fog/core/model'
|
||||
require 'fog/dreamhost/models/dns/records'
|
||||
|
||||
module Fog
|
||||
module DNS
|
||||
class Dreamhost
|
||||
|
||||
#
|
||||
# Dreamhost API has no concept of 'Zone', but we
|
||||
# can emulate it.
|
||||
#
|
||||
# http://wiki.dreamhost.com/API/Dns_commands
|
||||
#
|
||||
class Zone < Fog::Model
|
||||
|
||||
identity :id
|
||||
attribute :domain, :aliases => 'name'
|
||||
|
||||
#
|
||||
# There's no destroy API call
|
||||
#
|
||||
def destroy
|
||||
raise NotImplementedError.new
|
||||
end
|
||||
|
||||
#
|
||||
# Return a list of records for this zone
|
||||
#
|
||||
def records
|
||||
@records ||= begin
|
||||
Fog::DNS::Dreamhost::Records.new( :zone => self, :service => service )
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# Return the Dreamhost nameserver list
|
||||
#
|
||||
def nameservers
|
||||
[
|
||||
"ns1.dreamhost.com",
|
||||
"ns2.dreamhost.com",
|
||||
"ns3.dreamhost.com",
|
||||
]
|
||||
end
|
||||
|
||||
#
|
||||
# There's no zone create API call
|
||||
#
|
||||
def save
|
||||
raise NotImplementedError.new
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
37
lib/fog/dreamhost/models/dns/zones.rb
Normal file
37
lib/fog/dreamhost/models/dns/zones.rb
Normal file
|
@ -0,0 +1,37 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/dreamhost/models/dns/zone'
|
||||
|
||||
module Fog
|
||||
module DNS
|
||||
class Dreamhost
|
||||
|
||||
#
|
||||
# Dreamhost API has no concept of 'Zone', but we
|
||||
# can emulate it.
|
||||
#
|
||||
# http://wiki.dreamhost.com/API/Dns_commands
|
||||
#
|
||||
class Zones < Fog::Collection
|
||||
|
||||
model Fog::DNS::Dreamhost::Zone
|
||||
|
||||
def all
|
||||
clear
|
||||
zones = []
|
||||
service.records.each do |r|
|
||||
zones << { :id => r.zone, :domain => r.zone }
|
||||
end
|
||||
load(zones)
|
||||
end
|
||||
|
||||
def get(zone_id)
|
||||
service.zones.find { |z| z.domain == zone_id }
|
||||
rescue Excon::Errors::NotFound
|
||||
nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -3,7 +3,7 @@ Shindo.tests('Fog::DNS[:dreamhost]', ['dreamhost', 'dns']) do
|
|||
service = Fog::DNS[:dreamhost]
|
||||
|
||||
tests("collections") do
|
||||
%w{ records }.each do |collection|
|
||||
%w{ records zones }.each do |collection|
|
||||
test("it should respond to #{collection}") { service.respond_to? collection }
|
||||
test("it should respond to #{collection}.all") { eval("service.#{collection}").respond_to? 'all' }
|
||||
test("it should respond to #{collection}.get") { eval("service.#{collection}").respond_to? 'get' }
|
||||
|
|
|
@ -53,6 +53,16 @@ Shindo.tests("Fog::DNS[:dreamhost] | record", ['dreamhost', 'dns']) do
|
|||
(service.records.find { |r| r.name == name }).nil?
|
||||
end
|
||||
end
|
||||
tests('#save from zone') do
|
||||
name = "zone-create.#{test_domain}"
|
||||
r = service.zones.first.records.create :name => name,
|
||||
:type => 'A',
|
||||
:value => "8.8.8.8"
|
||||
sleep 10
|
||||
test("listed") do
|
||||
!(service.records.find { |r| r.name == name }).nil?
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
62
tests/dreamhost/models/dns/zone_tests.rb
Normal file
62
tests/dreamhost/models/dns/zone_tests.rb
Normal file
|
@ -0,0 +1,62 @@
|
|||
Shindo.tests("Fog::DNS[:dreamhost] | zone", ['dreamhost', 'dns']) do
|
||||
|
||||
service = Fog::DNS[:dreamhost]
|
||||
zone = service.zones.first
|
||||
|
||||
tests('#attributes') do
|
||||
tests('should have') do
|
||||
model_attribute_hash = zone.attributes
|
||||
attributes = [
|
||||
:domain,
|
||||
:id,
|
||||
]
|
||||
attributes.each do |attribute|
|
||||
test("#{attribute} method") { zone.respond_to? attribute }
|
||||
end
|
||||
attributes.each do |attribute|
|
||||
test("#{attribute} key") { model_attribute_hash.has_key? attribute }
|
||||
end
|
||||
end
|
||||
|
||||
test('be a kind of Fog::DNS::Dreamhost::Zone') do
|
||||
zone.kind_of? Fog::DNS::Dreamhost::Zone
|
||||
end
|
||||
|
||||
tests('Write operations') do
|
||||
name = "#{test_domain}"
|
||||
tests('#save') do
|
||||
# Does not capture the exception for some reason
|
||||
#raises(NotImplementedError, 'raises NotImplementedError') do
|
||||
# service.zones.create :domain => name
|
||||
#end
|
||||
test 'raises NotImplementedError' do
|
||||
begin
|
||||
service.zones.create :domain => name
|
||||
false
|
||||
rescue NotImplementedError => e
|
||||
true
|
||||
end
|
||||
end
|
||||
end
|
||||
tests('#destroy') do
|
||||
test 'raises NotImplementedError' do
|
||||
begin
|
||||
zone.destroy
|
||||
false
|
||||
rescue NotImplementedError => e
|
||||
true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
tests('#records') do
|
||||
zone.records.each do |r|
|
||||
test('list records') { r.is_a? Fog::DNS::Dreamhost::Record }
|
||||
test('zone matches') { r.zone == test_domain }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
29
tests/dreamhost/models/dns/zones_tests.rb
Normal file
29
tests/dreamhost/models/dns/zones_tests.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
Shindo.tests("Fog::DNS[:dreamhost] | Zones Collection", ['dreamhost', 'dns']) do
|
||||
|
||||
service = Fog::DNS[:dreamhost]
|
||||
|
||||
tests('#all') do
|
||||
zones = service.zones
|
||||
|
||||
test('should be an array') { zones.is_a? Array }
|
||||
|
||||
test('should not be empty') { !zones.empty? }
|
||||
|
||||
tests('should list Fog::DNS::Dreamhost::Zone') do
|
||||
zones.each do |r|
|
||||
test("as zone") { r.is_a?(Fog::DNS::Dreamhost::Zone) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
tests('#get') do
|
||||
tests('should fetch a zone') do
|
||||
zone = service.zones.get test_domain
|
||||
test('should be a Fog::DNS::Dreamhost::Zone') do
|
||||
zone.is_a? Fog::DNS::Dreamhost::Zone
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
Add table
Reference in a new issue