mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[Vcloud] Clean up some more specs around internet services.
-Add specs for delete_internet_service
This commit is contained in:
parent
8429f6bbfa
commit
e070c13772
7 changed files with 56 additions and 52 deletions
|
@ -353,11 +353,15 @@ module Fog
|
|||
response = Excon::Response.new
|
||||
|
||||
#Parse the response body into a hash
|
||||
if mock_data.empty?
|
||||
response.body = mock_data
|
||||
else
|
||||
document = Fog::ToHashDocument.new
|
||||
parser = Nokogiri::XML::SAX::PushParser.new(document)
|
||||
parser << mock_data
|
||||
parser.finish
|
||||
response.body = document.body
|
||||
end
|
||||
|
||||
response.status = status
|
||||
response.headers = mock_headers
|
||||
|
|
|
@ -149,6 +149,10 @@ module Fog
|
|||
{ :xmlns => "urn:tmrk:eCloudExtensions-2.3", :"xmlns:i" => "http://www.w3.org/2001/XMLSchema-instance" }
|
||||
end
|
||||
|
||||
def mock_ip_from_service_url(uri)
|
||||
mock_data[:organizations].map { |org| org[:vdcs] }.flatten.map { |vdc| vdc[:public_ips] }.flatten.compact.detect { |pip| pip[:services].detect { |service| service[:href] == uri } }
|
||||
end
|
||||
|
||||
def mock_data
|
||||
Fog::Vcloud::Terremark::Ecloud::Mock.data
|
||||
end
|
||||
|
|
|
@ -66,25 +66,9 @@ module Fog
|
|||
internet_services_uri = ensure_unparsed(internet_services_uri)
|
||||
|
||||
if ip = ip_from_uri(internet_services_uri)
|
||||
new_service = service_data.merge!( { :id => rand(1000), :timeout => 2 } )
|
||||
new_service = service_data.merge!( { :href => Fog::Vcloud::Terremark::Ecloud::Mock.internet_service_href( { :id => rand(1000) } ), :timeout => 2 } )
|
||||
ip[:services] << new_service
|
||||
builder = Builder::XmlMarkup.new
|
||||
xml = builder.InternetService(:xmlns => "urn:tmrk:eCloudExtensions-2.0",
|
||||
:"xmlns:i" => "http://www.w3.org/2001/XMLSchema-instance") {
|
||||
builder.Id(new_service[:id])
|
||||
builder.Href(Fog::Vcloud::Terremark::Ecloud::Mock.internet_service_href(new_service))
|
||||
builder.Name(new_service[:name])
|
||||
builder.PublicIpAddress {
|
||||
builder.Id(ip[:id])
|
||||
builder.Href(Fog::Vcloud::Terremark::Ecloud::Mock.public_ip_href(ip))
|
||||
builder.Name(ip[:name])
|
||||
}
|
||||
builder.Protocol(new_service[:protocol])
|
||||
builder.Port(new_service[:port])
|
||||
builder.Enabled(new_service[:enabled])
|
||||
builder.Description(new_service[:description])
|
||||
builder.Timeout(new_service[:timeout])
|
||||
}
|
||||
xml = generate_internet_service_response( service_data, ip )
|
||||
|
||||
mock_it 200, xml, {'Content-Type' => 'application/vnd.tmrk.ecloud.internetService+xml'}
|
||||
else
|
||||
|
|
|
@ -4,7 +4,7 @@ module Fog
|
|||
module Ecloud
|
||||
module Real
|
||||
|
||||
def generate_configure_internet_service_response(service_data,ip_address_data)
|
||||
def generate_internet_service_response(service_data,ip_address_data)
|
||||
builder = Builder::XmlMarkup.new
|
||||
builder.InternetService(:"xmlns:i" => "http://www.w3.org/2001/XMLSchema-instance",
|
||||
:xmlns => "urn:tmrk:eCloudExtensions-2.3") {
|
||||
|
@ -38,7 +38,7 @@ module Fog
|
|||
validate_public_ip_address_data(ip_address_data)
|
||||
|
||||
request(
|
||||
:body => generate_configure_internet_service_response(service_data, ip_address_data),
|
||||
:body => generate_internet_service_response(service_data, ip_address_data),
|
||||
:expects => 200,
|
||||
:headers => {'Content-Type' => 'application/vnd.tmrk.ecloud.internetService+xml'},
|
||||
:method => 'PUT',
|
||||
|
@ -67,7 +67,7 @@ module Fog
|
|||
if ip = ip_from_uri(ip_address_data[:href])
|
||||
if service = ip[:services].detect { |service| service[:id] == internet_service_uri.split('/')[-1] }
|
||||
ip[:services][ip[:services].index(service)] = service_data
|
||||
xml = generate_configure_internet_service_response(service_data, ip)
|
||||
xml = generate_internet_service_response(service_data, ip)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -10,7 +10,20 @@ module Fog
|
|||
module Mock
|
||||
|
||||
def delete_internet_service(service_uri)
|
||||
Fog::Mock.not_implemented
|
||||
|
||||
deleted = false
|
||||
if ip = mock_ip_from_service_url(service_uri)
|
||||
if service = ip[:services].detect { |service| service[:href] == service_uri }
|
||||
ip[:services].delete(service)
|
||||
deleted = true
|
||||
end
|
||||
end
|
||||
|
||||
if deleted
|
||||
mock_it 200, '', { }
|
||||
else
|
||||
mock_error 200, "401 Unauthorized"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -36,10 +36,12 @@ if Fog.mocking?
|
|||
|
||||
its(:body) { should be_an_instance_of Hash }
|
||||
specify { body[:Href].should == Fog::Vcloud::Terremark::Ecloud::Mock.internet_service_href( { :id => 372 } ) }
|
||||
specify { body[:Name].should == "Test Service" }
|
||||
specify { body[:Protocol].should == "HTTP" }
|
||||
specify { body[:Enabled].should == "true" }
|
||||
specify { body[:Description].should == "this is a test" }
|
||||
specify { body[:Name].should == @new_service_data[:name] }
|
||||
specify { body[:Protocol].should == @new_service_data[:protocol] }
|
||||
specify { body[:Enabled].should == @new_service_data[:enabled] }
|
||||
specify { body[:Description].should == @new_service_data[:description] }
|
||||
specify { body[:RedirectURL].should == @new_service_data[:redirect_url] }
|
||||
specify { body[:Monitor].should == nil }
|
||||
|
||||
let(:public_ip) { subject.body[:PublicIpAddress] }
|
||||
specify { public_ip.should be_an_instance_of Hash }
|
||||
|
|
|
@ -1,36 +1,33 @@
|
|||
require File.join(File.dirname(__FILE__), '..', '..', '..', 'spec_helper')
|
||||
|
||||
#FIXME: Make this more sane with rspec2
|
||||
if Fog.mocking?
|
||||
describe "Fog::Vcloud, initialized w/ the TMRK Ecloud module", :type => :mock_tmrk_ecloud_request do
|
||||
subject { @vcloud }
|
||||
|
||||
#it { should respond_to :delete_internet_service }
|
||||
it { should respond_to :delete_internet_service }
|
||||
|
||||
#describe "#delete_internet_service" do
|
||||
# before do
|
||||
# @public_ip = @vcloud.vdcs[0].public_ips[0]
|
||||
# @before_services = @vcloud.get_internet_services(@public_ip.href)
|
||||
# end
|
||||
describe "#delete_internet_service" do
|
||||
let(:public_ip) { @vcloud.vdcs[0].public_ips[0] }
|
||||
let(:before_services) { @vcloud.get_internet_services(public_ip.href) }
|
||||
let(:internet_service) { before_services.body[:InternetService].first }
|
||||
|
||||
# context "with a valid internet service uri" do
|
||||
# subject { @vcloud.delete_internet_service(@before_services.body.tap{|o| pp o}.links[0].href) }
|
||||
#
|
||||
# specify { @before_services.body.links.should have(2).links }
|
||||
context "with a valid internet service uri" do
|
||||
subject { @vcloud.delete_internet_service( internet_service[:Href] ) }
|
||||
|
||||
# it "has the right number of Internet Services after" do
|
||||
# subject
|
||||
# after_services = @vcloud.get_internet_services(@public_ip.href)
|
||||
# after_services.body.links.should have(1).link
|
||||
# end
|
||||
it "should have the right count" do
|
||||
before_services.body[:InternetService].count.should == 2
|
||||
end
|
||||
|
||||
# end
|
||||
# This actually calls it
|
||||
it { should be_an_instance_of Excon::Response }
|
||||
|
||||
# context "with a public_ips_uri that doesn't exist" do
|
||||
# subject { lambda { @vcloud.delete_internet_service(URI.parse('https://www.fakey.c/piv8vc99')) } }
|
||||
it "should remove the service" do
|
||||
before_services.body[:InternetService].count.should == 11 #it's now a hash, with 11 keys
|
||||
end
|
||||
end
|
||||
|
||||
# it_should_behave_like "a request for a resource that doesn't exist"
|
||||
# end
|
||||
#end
|
||||
end
|
||||
end
|
||||
else
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue