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

internet service model returns backup service href

This commit is contained in:
Dan Peterson 2010-11-22 10:15:23 -04:00
parent 19d1177333
commit 98a2f257aa
5 changed files with 67 additions and 22 deletions

View file

@ -714,6 +714,10 @@ module Fog
def monitor def monitor
nil nil
end end
def backup_service
self[:backup_service]
end
end end
class MockPublicIpInternetServiceNodes < Base class MockPublicIpInternetServiceNodes < Base

View file

@ -18,6 +18,7 @@ module Fog
attribute :timeout, :aliases => :Timeout attribute :timeout, :aliases => :Timeout
attribute :redirect_url, :aliases => :RedirectURL attribute :redirect_url, :aliases => :RedirectURL
attribute :monitor, :aliases => :Monitor attribute :monitor, :aliases => :Monitor
attribute :backup_service_data, :aliases => :BackupService
def delete def delete
requires :href requires :href
@ -58,6 +59,12 @@ module Fog
@nodes ||= Fog::Vcloud::Terremark::Ecloud::Nodes.new( :connection => connection, :href => href + "/nodeServices" ) @nodes ||= Fog::Vcloud::Terremark::Ecloud::Nodes.new( :connection => connection, :href => href + "/nodeServices" )
end end
def backup_service_href
if backup_service_data
backup_service_data[:Href]
end
end
private private
def _compose_service_data def _compose_service_data

View file

@ -61,7 +61,13 @@ module Fog
xml.RedirectURL service.redirect_url xml.RedirectURL service.redirect_url
xml.Monitor xml.Monitor
xml.IsBackupService MockDataClasses::MockBackupInternetService === service xml.IsBackupService MockDataClasses::MockBackupInternetService === service
xml.BackupService "i:nil" => true if MockDataClasses::MockPublicIpInternetService === service && service.backup_service
xml.BackupService do
xml.Href service.backup_service.href
end
else
xml.BackupService "i:nil" => true
end
xml.BackupOf xml.BackupOf
} }
end end

View file

@ -8,7 +8,7 @@ if Fog.mocking?
subject { Fog::Vcloud::Terremark::Ecloud::InternetService } subject { Fog::Vcloud::Terremark::Ecloud::InternetService }
it { should have_identity :href } it { should have_identity :href }
it { should have_only_these_attributes [:href, :name, :id, :protocol, :port, :enabled, :description, :public_ip, :timeout, :redirect_url, :monitor] } it { should have_only_these_attributes [:href, :name, :id, :protocol, :port, :enabled, :description, :public_ip, :timeout, :redirect_url, :monitor, :backup_service_data] }
end end
context "with no uri" do context "with no uri" do
@ -31,18 +31,19 @@ if Fog.mocking?
it { should be_an_instance_of Fog::Vcloud::Terremark::Ecloud::InternetService } it { should be_an_instance_of Fog::Vcloud::Terremark::Ecloud::InternetService }
its(:href) { should == @mock_service.href } its(:href) { should == @mock_service.href }
its(:identity) { should == @mock_service.href } its(:identity) { should == @mock_service.href }
its(:name) { should == @mock_service.name } its(:name) { should == @mock_service.name }
its(:id) { should == @mock_service.object_id.to_s } its(:id) { should == @mock_service.object_id.to_s }
its(:protocol) { should == @mock_service.protocol } its(:protocol) { should == @mock_service.protocol }
its(:port) { should == @mock_service.port.to_s } its(:port) { should == @mock_service.port.to_s }
its(:enabled) { should == @mock_service.enabled.to_s } its(:enabled) { should == @mock_service.enabled.to_s }
its(:description) { should == @mock_service.description } its(:description) { should == @mock_service.description }
its(:public_ip) { should == public_ip } its(:public_ip) { should == public_ip }
its(:timeout) { should == @mock_service.timeout.to_s } its(:timeout) { should == @mock_service.timeout.to_s }
its(:redirect_url) { should == @mock_service.redirect_url } its(:redirect_url) { should == @mock_service.redirect_url }
its(:monitor) { should == nil } its(:monitor) { should == nil }
its(:backup_service_href) { should be_nil }
specify { composed_public_ip_data[:href].should == public_ip[:Href].to_s } specify { composed_public_ip_data[:href].should == public_ip[:Href].to_s }
specify { composed_public_ip_data[:name].should == public_ip[:Name] } specify { composed_public_ip_data[:name].should == public_ip[:Name] }
@ -56,6 +57,12 @@ if Fog.mocking?
specify { composed_service_data[:enabled].should == subject.enabled.to_s } specify { composed_service_data[:enabled].should == subject.enabled.to_s }
specify { composed_service_data[:description].should == subject.description } specify { composed_service_data[:description].should == subject.description }
specify { composed_service_data[:timeout].should == subject.timeout.to_s } specify { composed_service_data[:timeout].should == subject.timeout.to_s }
context "with a backup internet service" do
before { @mock_service[:backup_service] = @mock_backup_service }
its(:backup_service_href) { should == @mock_backup_service.href }
end
end end
end end
else else

View file

@ -1,7 +1,7 @@
require File.join(File.dirname(__FILE__), '..', '..', '..', 'spec_helper') require File.join(File.dirname(__FILE__), '..', '..', '..', 'spec_helper')
if Fog.mocking? if Fog.mocking?
shared_examples_for "the expected internet service item" do shared_examples_for "a basic internet service" do
specify { service.should be_an_instance_of Hash } specify { service.should be_an_instance_of Hash }
specify { service.should have(14).attributes } specify { service.should have(14).attributes }
specify { service[:Name].should == mock_service.name } specify { service[:Name].should == mock_service.name }
@ -22,11 +22,20 @@ if Fog.mocking?
specify { service[:RedirectURL].should == (mock_service.redirect_url || "") } specify { service[:RedirectURL].should == (mock_service.redirect_url || "") }
specify { service[:Monitor].should == "" } specify { service[:Monitor].should == "" }
specify { service[:IsBackupService].should == "false" } specify { service[:IsBackupService].should == "false" }
specify { service[:BackupService].should be_nil }
specify { service[:BackupOf].should == "" } specify { service[:BackupOf].should == "" }
end end
shared_examples_for "the expected backup internet service item" do shared_examples_for "an internet service without a backup internet service set" do
specify { service[:BackupService].should be_nil }
end
shared_examples_for "an internet service with a backup internet service set" do
specify { service[:BackupService].should be_an_instance_of Hash }
specify { service[:BackupService].should include :Href }
specify { service[:BackupService][:Href].should == @mock_backup_service.href }
end
shared_examples_for "a backup internet service" do
specify { service.should be_an_instance_of Hash } specify { service.should be_an_instance_of Hash }
specify { service.should have(14).attributes } specify { service.should have(14).attributes }
specify { service[:Name].should == mock_service.name } specify { service[:Name].should == mock_service.name }
@ -54,7 +63,11 @@ if Fog.mocking?
describe "#get_internet_services" do describe "#get_internet_services" do
context "with a valid VDC internet_services_uri" do context "with a valid VDC internet_services_uri" do
before { @services = @vcloud.get_internet_services(@mock_vdc_service_collection.href) } before do
@mock_vdc.internet_service_collection.items[3][:backup_service] = @mock_backup_service
@services = @vcloud.get_internet_services(@mock_vdc_service_collection.href)
end
subject { @services } subject { @services }
it_should_behave_like "all responses" it_should_behave_like "all responses"
@ -70,19 +83,27 @@ if Fog.mocking?
it { should have(5).items } it { should have(5).items }
[0,1,2,3].each do |idx| [0,1,2].each do |idx|
let(:service) { subject[idx] } let(:service) { subject[idx] }
let(:mock_service) { @mock_vdc.internet_service_collection.items[idx] } let(:mock_service) { @mock_vdc.internet_service_collection.items[idx] }
let(:mock_ip) { mock_service._parent._parent } let(:mock_ip) { mock_service._parent._parent }
it_should_behave_like "the expected internet service item" it_should_behave_like "an internet service without a backup internet service set"
end
context "for a service with a backup internet service" do
let(:service) { subject[3] }
let(:mock_service) { @mock_vdc.internet_service_collection.items[3] }
let(:mock_ip) { mock_service._parent._parent }
it_should_behave_like "an internet service with a backup internet service set"
end end
context "for a backup internet service" do context "for a backup internet service" do
let(:service) { subject[4] } let(:service) { subject[4] }
let(:mock_service) { @mock_vdc.internet_service_collection.backup_internet_services.first } let(:mock_service) { @mock_vdc.internet_service_collection.backup_internet_services.first }
it_should_behave_like "the expected backup internet service item" it_should_behave_like "a backup internet service"
end end
end end
end end
@ -112,7 +133,7 @@ if Fog.mocking?
let(:mock_service) { @mock_service_collection.items[idx] } let(:mock_service) { @mock_service_collection.items[idx] }
let(:mock_ip) { @mock_public_ip } let(:mock_ip) { @mock_public_ip }
it_should_behave_like "the expected internet service item" it_should_behave_like "an internet service without a backup internet service set"
end end
end end
end end