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

[brightbox] moving specs to tests

This commit is contained in:
geemus 2010-11-16 13:24:43 -08:00
parent dc5abb7d3d
commit 26c1e239d5
13 changed files with 30 additions and 178 deletions

View file

@ -62,6 +62,11 @@ module Fog
class Mock
def initialize(options)
@brightbox_client_id = options[:brightbox_client_id] || Fog.credentials[:brightbox_client_id]
@brightbox_secret = options[:brightbox_secret] || Fog.credentials[:brightbox_secret]
end
def request(options)
raise "Not implemented"
end
@ -74,8 +79,8 @@ module Fog
# Currently authentication and api endpoints are the same but may change
@auth_url = options[:brightbox_auth_url] || Fog.credentials[:brightbox_auth_url] || API_URL
@api_url = options[:brightbox_api_url] || Fog.credentials[:brightbox_api_url] || API_URL
@brightbox_client_id = options[:brightbox_client_id] || Fog.credentials[:brightbox_client_id] || nil
@brightbox_secret = options[:brightbox_secret] || Fog.credentials[:brightbox_secret] || nil
@brightbox_client_id = options[:brightbox_client_id] || Fog.credentials[:brightbox_client_id]
@brightbox_secret = options[:brightbox_secret] || Fog.credentials[:brightbox_secret]
@connection = Fog::Connection.new(@api_url)
end

View file

@ -3,8 +3,6 @@ require File.dirname(__FILE__) + '/../../../shared_examples/server_examples'
describe 'Fog::AWS::Compute::Server' do
it_should_behave_like "Server"
subject { @server = @servers.new(:image_id => GENTOO_AMI) }
before(:each) do

View file

@ -1,18 +0,0 @@
require File.dirname(__FILE__) + '/../../spec_helper'
require File.dirname(__FILE__) + '/../../shared_examples/flavors_examples'
describe 'Fog::Brightbox::Compute::Flavors' do
if Fog.mocking?
it "needs to have mocks implemented"
else
it_should_behave_like "Flavors"
end
subject { @flavor = @flavors.all.first }
before(:each) do
@flavors = Brightbox[:compute].flavors
end
end

View file

@ -1,28 +0,0 @@
require File.dirname(__FILE__) + '/../../spec_helper'
require File.dirname(__FILE__) + '/../../shared_examples/server_examples'
describe 'Fog::Brightbox::Compute::Server' do
if Fog.mocking?
it "needs to have mocks implemented"
else
it_should_behave_like "Server"
end
subject {
@image_id = "img-t4p09" # Ubuntu Maverick 10.10 server
@server = @servers.new(:image_id => @image_id)
}
before(:each) do
@servers = Brightbox[:compute].servers
end
after(:each) do
if @server && !@server.new_record?
@server.wait_for { ready? }
@server.destroy.should be_true
end
end
end

View file

@ -1,29 +0,0 @@
require File.dirname(__FILE__) + '/../../spec_helper'
require File.dirname(__FILE__) + '/../../shared_examples/servers_examples'
describe 'Fog::Brightbox::Compute::Servers' do
if Fog.mocking?
it "needs to have mocks implemented"
else
it_should_behave_like "Servers"
end
subject {
@image_id = "img-t4p09" # Ubuntu Maverick 10.10 server
@server = @servers.new(:image_id => @image_id)
@server
}
before(:each) do
@servers = Brightbox[:compute].servers
end
after(:each) do
if @server && !@server.new_record?
@server.wait_for { ready? }
@server.destroy.should be_true
end
end
end

View file

@ -1,16 +0,0 @@
shared_examples_for "Flavors" do
describe "#get" do
it "should return a matching flavor if one exists" do
get = @flavors.get(subject.id)
subject.attributes.should == get.attributes
end
it "should return nil if no matching server exists" do
@flavors.get('0').should be_nil
end
end
end

View file

@ -1,43 +0,0 @@
shared_examples_for "Server" do
describe "#reboot" do
it "should succeed" do
subject.save
subject.wait_for { ready? }
subject.reboot.should be_true
end
end
describe "#reload" do
it "should reset attributes to remote state" do
subject.save
subject.wait_for { ready? }
@reloaded = subject.reload
subject.attributes.should == @reloaded.attributes
end
end
describe "#save" do
it "should return true when it succeeds" do
subject.save.should be_true
end
it "should not exist remotely before save" do
@servers.get(subject.id).should be_nil
end
it "should exist remotely after save" do
subject.save
subject.wait_for { ready? }
@servers.get(subject.id).should_not be_nil
end
end
end

View file

@ -1,38 +0,0 @@
shared_examples_for "Servers" do
describe "#all" do
it "should include persisted servers" do
subject.save
@servers.all.map {|server| server.id}.should include(subject.id)
end
end
describe "#get" do
it "should return a matching server if one exists" do
subject.save
subject.wait_for { ready? }
get = @servers.get(subject.id)
subject.attributes.should == get.attributes
end
it "should return nil if no matching server exists" do
@servers.get('i-00000000').should be_nil
end
end
describe "#reload" do
it "should reset attributes to remote state" do
subject.save
servers = @servers.all
reloaded = servers.reload
servers.attributes.should == reloaded.attributes
end
end
end

View file

View file

@ -0,0 +1,5 @@
Shindo.tests('Brightbox::Compute | flavors collection', ['brightbox']) do
flavors_tests(Brightbox[:compute], {}, false)
end

View file

@ -0,0 +1,6 @@
Shindo.tests('Brightbox::Compute | server model', ['brightbox']) do
# image img-t4p09 = Ubuntu Maverick 10.10 server
server_tests(Brightbox[:compute], {:image_id => 'img-t4p09'}, false)
end

View file

@ -0,0 +1,6 @@
Shindo.tests('Brightbox::Compute | servers collection', ['brightbox']) do
# image img-t4p09 = Ubuntu Maverick 10.10 server
servers_tests(Brightbox[:compute], {:image_id => 'img-t4p09'}, false)
end

View file

@ -17,7 +17,9 @@ def collection_tests(collection, params, mocks_implemented = true)
collection.all
end
@identity = @instance.identity
if !Fog.mocking? || mocks_implemented
@identity = @instance.identity
end
tests("#get(#{@identity})").succeeds do
pending if Fog.mocking? && !mocks_implemented
@ -35,7 +37,9 @@ def collection_tests(collection, params, mocks_implemented = true)
tests('failure') do
@identity = @identity.gsub(/\w/, '0')
if !Fog.mocking? || mocks_implemented
@identity = @identity.gsub(/\w/, '0')
end
tests("#get('#{@identity}')").returns(nil) do
pending if Fog.mocking? && !mocks_implemented