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

start cleaning up tests

-Don't use @login_uri, make it a function
-get_versions against a real api
-login vs a real api
This commit is contained in:
freeformz 2010-07-23 11:54:16 +08:00 committed by Wesley Beary
parent 21550d683b
commit 00956256f4
5 changed files with 77 additions and 21 deletions

View file

@ -171,10 +171,13 @@ module Fog
"Basic #{Base64.encode64("#{@username}:#{@password}").chomp!}"
end
def login_uri
@login_uri ||= get_login_uri
end
# login handles the auth, but we just need the Set-Cookie
# header from that call.
def do_login
@login_uri ||= get_login_uri
@login_results = login
@cookie = @login_results.headers['Set-Cookie']
end

View file

@ -12,7 +12,7 @@ module Fog
},
:method => 'POST',
:parse => true,
:uri => @login_uri
:uri => login_uri
})
end

View file

@ -1,28 +1,54 @@
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
if Fog.mocking?
describe Fog::Vcloud, :type => :mock_vcloud_request do
subject { @vcloud }
shared_examples_for "real or mock get_versions requests" do
it { should respond_to :get_versions }
subject { @vcloud }
describe "#get_versions" do
before { @versions = @vcloud.get_versions( @vcloud.versions_uri ) }
subject { @versions }
it { should respond_to :get_versions }
it_should_behave_like "all responses"
describe "#get_versions" do
subject { @vcloud.get_versions( @vcloud.versions_uri ) }
describe "body" do
subject { @versions.body }
it_should_behave_like "all responses"
it { should have(4).keys }
it_should_behave_like "it has the standard xmlns attributes" # 2 keys
describe "body" do
subject { @vcloud.get_versions( @vcloud.versions_uri ).body }
its(:xmlns) { should == "http://www.vmware.com/vcloud/versions" }
its(:VersionInfo) { should == { :LoginUrl => @mock_version[:login_url] , :Version => @mock_version[:version] } }
it { should have(4).keys }
it_should_behave_like "it has the standard xmlns attributes" # 2 keys
its(:xmlns) { should == "http://www.vmware.com/vcloud/versions" }
its(:VersionInfo) { should be_either_a_hash_or_array }
describe ":VersionInfo" do
subject { arrayify(@vcloud.get_versions( @vcloud.versions_uri ).body[:VersionInfo]) }
specify {
subject.each do |version_info|
version_info.should include(:LoginUrl)
version_info[:LoginUrl].should be_a_url
version_info.should include(:Version)
version_info[:Version].should be_an_instance_of String
end
}
end
end
end
else
end
if Fog.mocking?
describe Fog::Vcloud, :type => :mock_vcloud_request do
it_should_behave_like "real or mock get_versions requests"
describe "body" do
subject { @vcloud.get_versions( @vcloud.versions_uri ).body }
its(:VersionInfo) { should == { :LoginUrl => @mock_version[:login_url] , :Version => @mock_version[:version] } }
end
end
else
describe Fog::Vcloud, :type => :vcloud_request do
it_should_behave_like "real or mock get_versions requests"
end
end

View file

@ -1,11 +1,17 @@
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
shared_examples_for "real or mock login requests" do
subject { @vcloud }
it_should_behave_like "all login requests"
end
if Fog.mocking?
describe Fog::Vcloud, :type => :mock_vcloud_request do
subject { @vcloud }
it_should_behave_like "all login requests"
it_should_behave_like "real or mock login requests"
end
else
describe Fog::Vcloud, :type => :vcloud_request do
it_should_behave_like "real or mock login requests"
end
end

View file

@ -27,6 +27,10 @@ Fog.mock! if ENV['FOG_MOCK']
require "#{current_directory}/../../lib/fog/vcloud/bin"
def arrayify(item)
item.is_a?(Array) ? item : [ item ]
end
shared_examples_for "all responses" do
it { should be_an_instance_of Excon::Response }
it { should respond_to :body }
@ -218,7 +222,12 @@ Spec::Runner.configure do |config|
config.after(:all) do
Fog::Vcloud::Mock.data_reset
end
config.before(:each, :type => :mock_vcloud_model) do
config.before(:each, :type => :vcloud_request) do
@vcloud = Fog.services.detect { |service| service == Vcloud }[:vcloud]
end
config.before(:all, :type => :mock_vcloud_model) do
@vcloud = Fog::Vcloud.new(:username => "foo", :password => "bar", :versions_uri => "http://fakey.com/api/versions")
end
config.before(:all, :type => :mock_vcloud_model) do
@ -332,3 +341,15 @@ Spec::Matchers.define :have_all_attributes_be_nil do
actual.class.attributes.all? { |attribute| actual.send(attribute.to_sym) == nil }
end
end
Spec::Matchers.define :be_a_url do
match do |actual|
actual.match(/^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$/ix)
end
end
Spec::Matchers.define :be_either_a_hash_or_array do
match do |actual|
actual.is_a?(Hash) || actual.is_a?(Array)
end
end