From: Michal Fojtik <[email protected]>
Signed-off-by: Michal fojtik <[email protected]> --- client/tests/buckets_test.rb | 104 ++++++++-------- client/tests/client_test.rb | 34 +++--- client/tests/content_negotiation_tests.rb | 57 ++++----- client/tests/errors_test.rb | 17 +-- client/tests/hardware_profiles_test.rb | 36 +++--- client/tests/images_test.rb | 74 ++++++------ client/tests/instance_states_test.rb | 57 ++++----- client/tests/instances_test.rb | 184 ++++++++++++++--------------- client/tests/keys_tests.rb | 44 ++++--- client/tests/realms_test.rb | 53 +++++---- client/tests/storage_snapshot_test.rb | 58 ++++----- client/tests/storage_volume_test.rb | 70 +++++------ client/tests/test_helper.rb | 17 +++ 13 files changed, 400 insertions(+), 405 deletions(-) create mode 100644 client/tests/test_helper.rb diff --git a/client/tests/buckets_test.rb b/client/tests/buckets_test.rb index b897e0c..32037cd 100644 --- a/client/tests/buckets_test.rb +++ b/client/tests/buckets_test.rb @@ -16,22 +16,23 @@ # License for the specific language governing permissions and limitations # under the License. -require 'specs/spec_helper' +require 'rubygems' +require 'require_relative' if RUBY_VERSION =~ /^1\.8/ -describe "buckets" do +require_relative './test_helper.rb' - it_should_behave_like "all resources" +describe "Buckets" do it "should allow retrieval of all buckets" do [API_URL, API_URL_REDIRECT].each do |entry_point| DeltaCloud.new( API_NAME, API_PASSWORD, entry_point ) do |client| buckets = client.buckets - buckets.should_not be_empty + buckets.wont_be_empty buckets.each do |bucket| - bucket.uri.should_not be_nil - bucket.uri.should be_a( String ) - bucket.name.should_not be_nil - bucket.name.should be_a(String) + bucket.uri.wont_be_nil + bucket.uri.must_be_kind_of String + bucket.name.wont_be_nil + bucket.name.must_be_kind_of String end end end @@ -40,13 +41,13 @@ describe "buckets" do it "should allow retrieval of a named bucket" do DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client| bucket = client.bucket("bucket1") - bucket.should_not be_nil - bucket.uri.should eql(API_URL + "/buckets/bucket1") - bucket.size.should eql(3.0) - bucket.name.should_not be_nil - bucket.name.should be_a(String) + bucket.wont_be_nil + bucket.uri.must_equal API_URL + "/buckets/bucket1" + bucket.size.must_equal 3.0 + bucket.name.wont_be_nil + bucket.name.must_be_kind_of String blob_list = bucket.blob_list.split(", ") - blob_list.size.should eql(bucket.size.to_i) + blob_list.size.must_equal bucket.size.to_i end end @@ -57,30 +58,28 @@ describe "Operations on buckets" do it "should allow creation of a new bucket" do DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client| new_bucket = client.create_bucket({'id' => "my_new_bucket"}) - new_bucket.should_not be_nil - new_bucket.uri.should eql(API_URL + "/buckets/my_new_bucket") - new_bucket.name.should_not be_nil - new_bucket.name.should be_a(String) - new_bucket.name.should eql("my_new_bucket") + new_bucket.wont_be_nil + new_bucket.uri.must_equal API_URL + "/buckets/my_new_bucket" + new_bucket.name.wont_be_nil + new_bucket.name.must_be_kind_of String + new_bucket.name.must_equal "my_new_bucket" end end it "should allow deletion of an existing bucket" do DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client| new_bucket = client.bucket("my_new_bucket") - new_bucket.should_not be_nil - new_bucket.name.should eql("my_new_bucket") - lambda{ - client.destroy_bucket({'id' => "my_new_bucket"}) - }.should_not raise_error + new_bucket.wont_be_nil + new_bucket.name.must_equal "my_new_bucket" + client.destroy_bucket('id' => "my_new_bucket").must_be_nil end end it "should throw error if you delete a non existing bucket" do DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client| - lambda{ - client.destroy_bucket({'id' => "i_dont_exist"}) - }.should raise_error + lambda { + client.destroy_bucket({'id' => "i_dont_exist"}).must_be_nil + }.must_raise DeltaCloud::HTTPError::DeltacloudError end end @@ -91,21 +90,20 @@ describe "Blobs" do it "should allow retrieval of a bucket's blobs" do DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client| bucket = client.bucket("bucket1") - bucket.should_not be_nil + bucket.wont_be_nil blob_list = bucket.blob_list.split(", ") - blob_list.size.should eql(bucket.size.to_i) + blob_list.size.must_equal bucket.size.to_i blob_list.each do |b_id| - blob = client.blob({"bucket" => bucket.name, :id => b_id}) - puts blob.inspect - blob.bucket.should_not be_nil - blob.bucket.should be_a(String) - blob.bucket.should eql(bucket.name) - blob.content_length.should_not be_nil - blob.content_length.should be_a(Float) - blob.content_length.should >= 0 - blob_data = client.blob_data({"bucket" => bucket.name, :id => b_id}) - blob_data.size.to_f.should == blob.content_length - blob.last_modified.should_not be_nil + blob = client.blob("bucket" => bucket.name, :id => b_id) + blob.bucket.wont_be_nil + blob.bucket.must_be_kind_of String + blob.bucket.must_equal bucket.name + blob.content_length.wont_be_nil + blob.content_length.must_be_kind_of Float + blob.content_length.must_be :'>=', 0 + blob_data = client.blob_data("bucket" => bucket.name, :id => b_id) + blob_data.size.to_f.must_equal blob.content_length + blob.last_modified.wont_be_nil end end end @@ -117,32 +115,32 @@ describe "Operations on blobs" do it "should successfully create a new blob" do DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client| blob_data = File.new("./blob_data_file", "w+") - blob_data.write("this is some blob data \n") blob_data.rewind - some_new_blob = client.create_blob({:id => "some_new_blob", - 'bucket' => "bucket1", - 'file_path' => blob_data.path}) - some_new_blob.should_not be_nil - some_new_blob.content_length.should_not be_nil - some_new_blob.content_length.should eql(24.0) + some_new_blob = client.create_blob( + :id => "some_new_blob", + 'bucket' => "bucket1", + 'file_path' => blob_data.path + ) + some_new_blob.wont_be_nil + some_new_blob.content_length.wont_be_nil + some_new_blob.content_length.must_equal 24.0 File.delete(blob_data.path) end end it "should allow deletion of an existing blob" do DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client| - lambda{ - client.destroy_blob({:id=>"some_new_blob", 'bucket'=>"bucket1"}) - }.should_not raise_error + client.destroy_blob(:id=>"some_new_blob", 'bucket'=>"bucket1").must_be_nil end end it "should throw error if you delete a non existing blob" do DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client| - lambda{ - client.destroy_blob({:id=>"no_such_blob", 'bucket'=>"bucket1"}) - }.should raise_error + lambda { + client.destroy_blob(:id=>"no_such_blob", 'bucket'=>"bucket1").must_be_nil + }.must_raise DeltaCloud::HTTPError::DeltacloudError end end + end diff --git a/client/tests/client_test.rb b/client/tests/client_test.rb index b4c1a75..29fab42 100644 --- a/client/tests/client_test.rb +++ b/client/tests/client_test.rb @@ -16,48 +16,48 @@ # License for the specific language governing permissions and limitations # under the License. -require 'specs/spec_helper' +require 'rubygems' +require 'require_relative' if RUBY_VERSION =~ /^1\.8/ + +require_relative './test_helper.rb' describe "initializing the client" do it "should parse valid API URIs" do client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) - client.api_host.should eql( API_HOST ) - client.api_port.should eql( API_PORT.to_i ) - client.api_path.should eql( API_PATH ) + client.api_host.must_equal API_HOST + client.api_port.must_equal API_PORT.to_i + client.api_path.must_equal API_PATH end it "should discover entry points upon connection" do [API_URL, API_URL_REDIRECT].each do |entry_point| DeltaCloud.new( "name", "password", entry_point ) do |client| - client.entry_points[:hardware_profiles].should eql( "#{API_URL}/hardware_profiles" ) - client.entry_points[:images].should eql( "#{API_URL}/images" ) - client.entry_points[:instances].should eql( "#{API_URL}/instances" ) - client.entry_points[:storage_volumes].should eql( "#{API_URL}/storage_volumes" ) - client.entry_points[:storage_snapshots].should eql( "#{API_URL}/storage_snapshots" ) - client.entry_points[:buckets].should eql( "#{API_URL}/buckets") - client.entry_points[:keys].should eql( "#{API_URL}/keys") + client.entry_points[:hardware_profiles].must_equal "#{API_URL}/hardware_profiles" + client.entry_points[:images].must_equal "#{API_URL}/images" + client.entry_points[:instances].must_equal "#{API_URL}/instances" + client.entry_points[:storage_volumes].must_equal "#{API_URL}/storage_volumes" + client.entry_points[:storage_snapshots].must_equal "#{API_URL}/storage_snapshots" + client.entry_points[:buckets].must_equal "#{API_URL}/buckets" + client.entry_points[:keys].must_equal "#{API_URL}/keys" end end end it "should provide the current driver name via client" do DeltaCloud.new( "name", "password", API_URL ) do |client| - client.driver_name.should eql( 'mock' ) + client.driver_name.must_equal 'mock' end end it "should provide the current driver name without client" do - DeltaCloud.driver_name( API_URL ).should eql( 'mock' ) + DeltaCloud.driver_name( API_URL ).must_equal 'mock' end describe "without a block" do - before( :each ) do - reload_fixtures - end it "should connect without a block" do client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) - client.images.should_not be_nil + client.images.wont_be_nil end end diff --git a/client/tests/content_negotiation_tests.rb b/client/tests/content_negotiation_tests.rb index ffd222c..d963027 100644 --- a/client/tests/content_negotiation_tests.rb +++ b/client/tests/content_negotiation_tests.rb @@ -16,11 +16,12 @@ # License for the specific language governing permissions and limitations # under the License. -require 'specs/spec_helper' +require 'rubygems' +require 'require_relative' if RUBY_VERSION =~ /^1\.8/ -def client - RestClient::Resource.new(API_URL) -end +require_relative './test_helper.rb' + +def client; RestClient::Resource.new(API_URL); end def headers(header) encoded_credentials = ["#{API_NAME}:#{API_PASSWORD}"].pack("m0").gsub(/\n/,'') @@ -38,8 +39,8 @@ describe "return JSON" do 'Accept' => "application/json" } client.get(header_hash) do |response, request, &block| - response.code.should == 200 - response.headers[:content_type].should =~ /^application\/json/ + response.code.must_equal 200 + response.headers[:content_type].must_match /^application\/json/ end end @@ -48,8 +49,8 @@ describe "return JSON" do 'Accept' => "application/json" } client.get(header_hash) do |response, request, &block| - response.code.should == 200 - response.headers[:content_type].should =~ /^application\/json/ + response.code.must_equal 200 + response.headers[:content_type].must_match /^application\/json/ end end @@ -59,49 +60,41 @@ describe "return HTML in different browsers" do it "wants XML using format parameter" do client.get(:params => { 'format' => 'xml' }, 'Accept' => 'application/xhtml+xml') do |response, request, &block| - response.code.should == 200 - response.headers[:content_type].should =~ /^application\/xml/ + response.code.must_equal 200 + response.headers[:content_type].must_match /^application\/xml/ end end it "raise 406 error on wrong accept" do client['hardware_profiles'].get('Accept' => 'image/png;q=1') do |response, request, &block| - response.code.should == 406 + response.code.must_equal 406 end end it "wants HTML using format parameter and accept set to XML" do client.get(:params => { 'format' => 'html'}, 'Accept' => 'application/xml') do |response, request, &block| - response.code.should == 200 - response.headers[:content_type].should =~ /^text\/html/ + response.code.must_equal 200 + response.headers[:content_type].must_match /^text\/html/ end end -# FIXME: This return 406 for some reason on GIT sinatra -# it "wants a PNG image" do -# client['instance_states'].get('Accept' => 'image/png') do |response, request, &block| -# response.code.should == 200 -# response.headers[:content_type].should =~ /^image\/png/ -# end -# end - it "doesn't have accept header" do client.get('Accept' => '') do |response, request, &block| - response.code.should == 200 - response.headers[:content_type].should =~ /^application\/xml/ + response.code.must_equal 200 + response.headers[:content_type].must_match /^application\/xml/ end end it "can handle unknown formats" do client.get('Accept' => 'format/unknown') do |response, request, &block| - response.code.should == 406 + response.code.must_equal 406 end end it "wants explicitly XML" do client.get('Accept' => 'application/xml') do |response, request, &block| - response.code.should == 200 - response.headers[:content_type].should =~ /^application\/xml/ + response.code.must_equal 200 + response.headers[:content_type].must_match /^application\/xml/ end end @@ -111,15 +104,15 @@ describe "return HTML in different browsers" do 'User-agent' => "Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US)" } client.get(header_hash) do |response, request, &block| - response.code.should == 200 - response.headers[:content_type].should =~ /^text\/html/ + response.code.must_equal 200 + response.headers[:content_type].must_match /^text\/html/ end end it "Mozilla Firefox" do client.get('Accept' => "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8") do |response, request, &block| - response.code.should == 200 - response.headers[:content_type].should =~ /^text\/html/ + response.code.must_equal 200 + response.headers[:content_type].must_match /^text\/html/ end end @@ -129,8 +122,8 @@ describe "return HTML in different browsers" do 'User-agent' => "Opera/9.80 (X11; Linux i686; U; ru) Presto/2.8.131 Version/11.11" } client.get(header_hash) do |response, request, &block| - response.code.should == 200 - response.headers[:content_type].should =~ /^text\/html/ + response.code.must_equal 200 + response.headers[:content_type].must_match /^text\/html/ end end diff --git a/client/tests/errors_test.rb b/client/tests/errors_test.rb index 031e3b7..12c6c21 100644 --- a/client/tests/errors_test.rb +++ b/client/tests/errors_test.rb @@ -16,33 +16,34 @@ # License for the specific language governing permissions and limitations # under the License. -require 'specs/spec_helper' +require 'rubygems' +require 'require_relative' if RUBY_VERSION =~ /^1\.8/ -describe "server error handler" do +require_relative './test_helper.rb' - it_should_behave_like "all resources" +describe "server error handler" do it 'should capture HTTP 500 error as DeltacloudError' do DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client| - expect { client.realm('500') }.should raise_error(DeltaCloud::HTTPError::DeltacloudError) + lambda { client.realm('500') }.must_raise DeltaCloud::HTTPError::DeltacloudError end end it 'should capture HTTP 502 error as ProviderError' do DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client| - expect { client.realm('502') }.should raise_error(DeltaCloud::HTTPError::ProviderError) + lambda { client.realm('502') }.must_raise DeltaCloud::HTTPError::ProviderError end end it 'should capture HTTP 501 error as NotImplemented' do DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client| - expect { client.realm('501') }.should raise_error(DeltaCloud::HTTPError::NotImplemented) + lambda { client.realm('501') }.must_raise DeltaCloud::HTTPError::NotImplemented end end it 'should capture HTTP 504 error as ProviderTimeout' do DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client| - expect { client.realm('504') }.should raise_error(DeltaCloud::HTTPError::ProviderTimeout) + lambda { client.realm('504') }.must_raise DeltaCloud::HTTPError::ProviderTimeout end end @@ -52,7 +53,7 @@ describe "client error handler" do it 'should capture HTTP 404 error as NotFound' do DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client| - expect { client.realm('non-existing-realm') }.should raise_error(DeltaCloud::HTTPError::NotFound) + lambda { client.realm('non-existing-realm') }.must_raise DeltaCloud::HTTPError::NotFound end end diff --git a/client/tests/hardware_profiles_test.rb b/client/tests/hardware_profiles_test.rb index 59bfae0..1201e56 100644 --- a/client/tests/hardware_profiles_test.rb +++ b/client/tests/hardware_profiles_test.rb @@ -16,28 +16,28 @@ # License for the specific language governing permissions and limitations # under the License. +require 'rubygems' +require 'require_relative' if RUBY_VERSION =~ /^1\.8/ -require 'specs/spec_helper' +require_relative './test_helper.rb' def prop_check(prop, value_class) if prop.present? - prop.value.should_not be_nil - prop.value.should be_a(value_class) + prop.value.wont_be_nil + prop.value.must_be_kind_of value_class end end -describe "hardware_profiles" do - - it_should_behave_like "all resources" +describe "Hardware Profiles" do it "should allow retrieval of all hardware profiles" do [API_URL, API_URL_REDIRECT].each do |entry_point| DeltaCloud.new( API_NAME, API_PASSWORD, entry_point ) do |client| hardware_profiles = client.hardware_profiles - hardware_profiles.should_not be_empty + hardware_profiles.wont_be_empty hardware_profiles.each do |hwp| - hwp.uri.should_not be_nil - hwp.uri.should be_a(String) + hwp.uri.wont_be_nil + hwp.uri.must_be_kind_of String prop_check(hwp.architecture, String) unless hwp.name.eql?("opaque") end end @@ -47,17 +47,17 @@ describe "hardware_profiles" do it "should allow filtering of hardware_profiles by architecture" do DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client| hardware_profiles = client.hardware_profiles( :architecture=>'i386' ) - hardware_profiles.should_not be_empty - hardware_profiles.size.should eql( 2 ) - hardware_profiles.first.architecture.value.should eql( 'i386' ) + hardware_profiles.wont_be_empty + hardware_profiles.size.must_equal 2 + hardware_profiles.first.architecture.value.must_equal 'i386' end end it "should allow fetching a hardware_profile by id" do DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client| hwp = client.hardware_profile( 'm1-small' ) - hwp.should_not be_nil - hwp.id.should eql( 'm1-small' ) + hwp.wont_be_nil + hwp.id.must_equal 'm1-small' end end @@ -65,15 +65,15 @@ describe "hardware_profiles" do client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) hwp1 = client.hardware_profile( 'm1-small' ) hwp2 = client.hardware_profile( 'm1-large' ) - hwp1.storage.value.should_not eql(hwp2.storage.value) - hwp1.memory.value.should_not eql(hwp2.memory.value) + hwp1.storage.value.wont_equal hwp2.storage.value + hwp1.memory.value.wont_equal hwp2.memory.value end it "should allow fetching a hardware_profile by URI" do DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client| hwp = client.fetch_hardware_profile( API_URL + '/hardware_profiles/m1-small' ) - hwp.should_not be_nil - hwp.id.should eql( 'm1-small' ) + hwp.wont_be_nil + hwp.id.must_equal 'm1-small' end end diff --git a/client/tests/images_test.rb b/client/tests/images_test.rb index 3b209cd..b9b1492 100644 --- a/client/tests/images_test.rb +++ b/client/tests/images_test.rb @@ -16,28 +16,28 @@ # License for the specific language governing permissions and limitations # under the License. +require 'rubygems' +require 'require_relative' if RUBY_VERSION =~ /^1\.8/ -require 'specs/spec_helper' +require_relative './test_helper.rb' -describe "images" do - - it_should_behave_like "all resources" +describe "Images" do it "should allow retrieval of all images" do [API_URL, API_URL_REDIRECT].each do |entry_point| DeltaCloud.new( API_NAME, API_PASSWORD, entry_point ) do |client| images = client.images - images.should_not be_empty - images.size.should eql( 3 ) + images.wont_be_empty + images.size.must_equal 3 images.each do |image| - image.uri.should_not be_nil - image.uri.should be_a(String) - image.description.should_not be_nil - image.description.should be_a(String) - image.architecture.should_not be_nil - image.architecture.should be_a(String) - image.owner_id.should_not be_nil - image.owner_id.should be_a(String) + image.uri.wont_be_nil + image.uri.must_be_kind_of String + image.description.wont_be_nil + image.description.must_be_kind_of String + image.architecture.wont_be_nil + image.architecture.must_be_kind_of String + image.owner_id.wont_be_nil + image.owner_id.must_be_kind_of String end end end @@ -46,17 +46,17 @@ describe "images" do it "should allow retrieval of my own images" do DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client| images = client.images( :owner_id=>:self ) - images.should_not be_empty - images.size.should eql( 1 ) + images.wont_be_empty + images.size.must_equal 1 images.each do |image| - image.uri.should_not be_nil - image.uri.should be_a(String) - image.description.should_not be_nil - image.description.should be_a(String) - image.architecture.should_not be_nil - image.architecture.should be_a(String) - image.owner_id.should_not be_nil - image.owner_id.should be_a(String) + image.uri.wont_be_nil + image.uri.must_be_kind_of String + image.description.wont_be_nil + image.description.must_be_kind_of String + image.architecture.wont_be_nil + image.architecture.must_be_kind_of String + image.owner_id.wont_be_nil + image.owner_id.must_be_kind_of String end end end @@ -64,20 +64,20 @@ describe "images" do it "should allow retrieval of a single image by ID" do DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client| image = client.image( 'img1' ) - image.should_not be_nil - image.uri.should eql( API_URL + '/images/img1' ) - image.id.should eql( 'img1' ) - image.architecture.should eql( 'x86_64' ) + image.wont_be_nil + image.uri.must_equal API_URL + '/images/img1' + image.id.must_equal 'img1' + image.architecture.must_equal 'x86_64' end end it "should allow retrieval of a single image by URI" do DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client| image = client.fetch_image( API_URL + '/images/img1' ) - image.should_not be_nil - image.uri.should eql( API_URL + '/images/img1' ) - image.id.should eql( 'img1' ) - image.architecture.should eql( 'x86_64' ) + image.wont_be_nil + image.uri.must_equal API_URL + '/images/img1' + image.id.must_equal 'img1' + image.architecture.must_equal 'x86_64' end end @@ -85,14 +85,14 @@ describe "images" do it "return matching images" do DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client| images = client.images( :architecture=>'x86_64' ) - images.should_not be_empty + images.wont_be_empty images.each do |image| - image.architecture.should eql( 'x86_64' ) + image.architecture.must_equal 'x86_64' end images = client.images( :architecture=>'i386' ) - images.should_not be_empty + images.wont_be_empty images.each do |image| - image.architecture.should eql( 'i386' ) + image.architecture.must_equal 'i386' end end end @@ -100,7 +100,7 @@ describe "images" do it "should return an empty array for no matches" do DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client| images = client.images( :architecture=>'8088' ) - images.should be_empty + images.must_be_empty end end end diff --git a/client/tests/instance_states_test.rb b/client/tests/instance_states_test.rb index c79c273..2981e98 100644 --- a/client/tests/instance_states_test.rb +++ b/client/tests/instance_states_test.rb @@ -16,41 +16,32 @@ # License for the specific language governing permissions and limitations # under the License. +require 'rubygems' +require 'require_relative' if RUBY_VERSION =~ /^1\.8/ -require 'specs/spec_helper' +require_relative './test_helper.rb' -=begin -Spec::Matchers.define :include_transition do |action,to| - match do |transitions| - found = transitions.find{|e| e.action.to_s == action.to_s && e.to.to_s == to.to_s } - ! found.nil? - end -end -=end - -describe "instance-states" do - - it_should_behave_like "all resources" +describe "Instance States" do it "should allow retrieval of instance-state information" do [API_URL, API_URL_REDIRECT].each do |entry_point| DeltaCloud.new( API_NAME, API_PASSWORD, entry_point ) do |client| instance_states = client.instance_states - instance_states.should_not be_nil - instance_states.should_not be_empty + instance_states.wont_be_nil + instance_states.wont_be_empty - instance_states[0].name.should eql( 'start' ) - instance_states[0].transitions.size.should eql( 1 ) - instance_states[0].transitions[0].should_not be_auto + instance_states[0].name.must_equal 'start' + instance_states[0].transitions.size.must_equal 1 + instance_states[0].transitions[0].wont_equal :auto - instance_states[1].name.should eql( 'pending' ) - instance_states[1].transitions.size.should eql( 1 ) - instance_states[1].transitions[0].should be_auto + instance_states[1].name.must_equal 'pending' + instance_states[1].transitions.size.must_equal 1 + instance_states[1].transitions[0].wont_equal :auto - instance_states[2].name.should eql( 'running' ) - instance_states[2].transitions.size.should eql( 2 ) - includes_transition( instance_states[2].transitions, :reboot, :running ).should be_true - includes_transition( instance_states[2].transitions, :stop, :stopped ).should be_true + instance_states[2].name.must_equal 'running' + instance_states[2].transitions.size.must_equal 2 + includes_transition( instance_states[2].transitions, :reboot, :running ).must_equal true + includes_transition( instance_states[2].transitions, :stop, :stopped ).must_equal true end end end @@ -58,16 +49,16 @@ describe "instance-states" do it "should allow retrieval of a single instance-state blob" do DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client| instance_state = client.instance_state( :pending ) - instance_state.should_not be_nil - instance_state.name.should eql( 'pending' ) - instance_state.transitions.size.should eql( 1 ) - instance_state.transitions[0].should be_auto + instance_state.wont_be_nil + instance_state.name.must_equal 'pending' + instance_state.transitions.size.must_equal 1 + instance_state.transitions[0].wont_equal :auto instance_state = client.instance_state( :running ) - instance_state.name.should eql( 'running' ) - instance_state.transitions.size.should eql( 2 ) - includes_transition( instance_state.transitions, :reboot, :running ).should be_true - includes_transition( instance_state.transitions, :stop, :stopped ).should be_true + instance_state.name.must_equal 'running' + instance_state.transitions.size.must_equal 2 + includes_transition( instance_state.transitions, :reboot, :running ).must_equal true + includes_transition( instance_state.transitions, :stop, :stopped ).must_equal true end end diff --git a/client/tests/instances_test.rb b/client/tests/instances_test.rb index f7fc7e7..bff1a7f 100644 --- a/client/tests/instances_test.rb +++ b/client/tests/instances_test.rb @@ -16,35 +16,35 @@ # License for the specific language governing permissions and limitations # under the License. +require 'rubygems' +require 'require_relative' if RUBY_VERSION =~ /^1\.8/ -require 'specs/spec_helper' +require_relative './test_helper.rb' -describe "instances" do - - it_should_behave_like "all resources" +describe "Instances" do it "should allow retrieval of all instances" do [API_URL, API_URL_REDIRECT].each do |entry_point| DeltaCloud.new( API_NAME, API_PASSWORD, entry_point ) do |client| instances = client.instances - instances.should_not be_empty + instances.wont_be_empty instances.each do |instance| - instance.uri.should_not be_nil - instance.uri.should be_a( String ) - instance.owner_id.should_not be_nil - instance.owner_id.should be_a( String ) - instance.image.should_not be_nil - instance.image.to_s.should match(/DeltaCloud::API::.*::Image/) - instance.hardware_profile.should_not be_nil - instance.hardware_profile.should be_a( DeltaCloud::API::Base::HardwareProfile ) - instance.state.should_not be_nil - instance.state.should be_a( String ) - instance.public_addresses.should_not be_nil - instance.public_addresses.should_not be_empty - instance.public_addresses.should be_a( Array ) - instance.private_addresses.should_not be_nil - instance.private_addresses.should_not be_empty - instance.private_addresses.should be_a( Array ) + instance.uri.wont_be_nil + instance.uri.must_be_kind_of String + instance.owner_id.wont_be_nil + instance.owner_id.must_be_kind_of String + instance.image.wont_be_nil + instance.image.to_s.must_match /DeltaCloud::API::.*::Image/ + instance.hardware_profile.wont_be_nil + instance.hardware_profile.must_be_kind_of DeltaCloud::API::Base::HardwareProfile + instance.state.wont_be_nil + instance.state.must_be_kind_of String + instance.public_addresses.wont_be_nil + instance.public_addresses.wont_be_empty + instance.public_addresses.must_be_kind_of Array + instance.private_addresses.wont_be_nil + instance.private_addresses.wont_be_empty + instance.private_addresses.must_be_kind_of Array end end end @@ -53,60 +53,60 @@ describe "instances" do it "should allow navigation from instance to image" do DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client| instances = client.instances - instances.should_not be_empty + instances.wont_be_empty instance = instances.first - instance.image.should_not be_nil - instance.image.description.should_not be_nil - instance.image.description.should be_a(String) + instance.image.wont_be_nil + instance.image.description.wont_be_nil + instance.image.description.must_be_kind_of String end end it "should allow retrieval of a single instance" do DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client| instance = client.instance( "inst0" ) - instance.should_not be_nil - instance.name.should_not be_nil - instance.name.should eql( 'Mock Instance With Profile Change' ) - instance.uri.should_not be_nil - instance.uri.should be_a( String ) - instance.owner_id.should eql( "mockuser" ) - instance.public_addresses.first.class.should eql(Hash) - instance.public_addresses.first[:type].should eql('hostname') - instance.public_addresses.first[:address].should eql('img1.inst0.public.com') - instance.image.should_not be_nil - instance.image.uri.should eql( API_URL + "/images/img1" ) - instance.hardware_profile.should_not be_nil - instance.hardware_profile.should_not be_nil - instance.hardware_profile.uri.should eql( API_URL + "/hardware_profiles/m1-large" ) - instance.hardware_profile.memory.value.should eql('10240') - instance.hardware_profile.storage.value.should eql('850') - instance.state.should eql( "RUNNING" ) - instance.actions.should_not be_nil + instance.wont_be_nil + instance.name.wont_be_nil + instance.name.must_equal 'Mock Instance With Profile Change' + instance.uri.wont_be_nil + instance.uri.must_be_kind_of String + instance.owner_id.must_equal "mockuser" + instance.public_addresses.first.class.must_equal Hash + instance.public_addresses.first[:type].must_equal 'hostname' + instance.public_addresses.first[:address].must_equal 'img1.inst0.public.com' + instance.image.wont_be_nil + instance.image.uri.must_equal API_URL + "/images/img1" + instance.hardware_profile.wont_be_nil + instance.hardware_profile.wont_be_nil + instance.hardware_profile.uri.must_equal API_URL + "/hardware_profiles/m1-large" + instance.hardware_profile.memory.value.must_equal '10240' + instance.hardware_profile.storage.value.must_equal '850' + instance.state.must_equal "RUNNING" + instance.actions.wont_be_nil end end it "should allow creation of new instances with reasonable defaults" do DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client| instance = client.create_instance( 'img1', :name=>'TestInstance', :hardware_profile => 'm1-large' ) - instance.should_not be_nil - instance.uri.should match( %r{#{API_URL}/instances/inst[0-9]+} ) - instance.id.should match( /inst[0-9]+/ ) - instance.name.should eql( 'TestInstance' ) - instance.image.id.should eql( 'img1' ) - instance.hardware_profile.id.should eql( 'm1-large' ) - instance.realm.id.should eql( 'us' ) + instance.wont_be_nil + instance.uri.must_match %r{#{API_URL}/instances/inst[0-9]+} + instance.id.must_match /inst[0-9]+/ + instance.name.must_equal 'TestInstance' + instance.image.id.must_equal 'img1' + instance.hardware_profile.id.must_equal 'm1-large' + instance.realm.id.must_equal 'us' end end it "should allow creation of new instances with specific realm" do DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client| instance = client.create_instance( 'img1', :realm=>'eu', :hardware_profile => 'm1-large' ) - instance.should_not be_nil - instance.uri.should match( %r{#{API_URL}/instances/inst[0-9]+} ) - instance.id.should match( /inst[0-9]+/ ) - instance.image.id.should eql( 'img1' ) - instance.hardware_profile.id.should eql( 'm1-large' ) - instance.realm.id.should eql( 'eu' ) + instance.wont_be_nil + instance.uri.must_match %r{#{API_URL}/instances/inst[0-9]+} + instance.id.must_match /inst[0-9]+/ + instance.image.id.must_equal 'img1' + instance.hardware_profile.id.must_equal 'm1-large' + instance.realm.id.must_equal 'eu' end end @@ -114,12 +114,12 @@ describe "instances" do DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client| instance = client.create_instance( 'img1', :hardware_profile=>'m1-xlarge' ) - instance.should_not be_nil - instance.uri.should match( %r{#{API_URL}/instances/inst[0-9]+} ) - instance.id.should match( /inst[0-9]+/ ) - instance.image.id.should eql( 'img1' ) - instance.hardware_profile.id.should eql( 'm1-xlarge' ) - instance.realm.id.should eql( 'us' ) + instance.wont_be_nil + instance.uri.must_match %r{#{API_URL}/instances/inst[0-9]+} + instance.id.must_match /inst[0-9]+/ + instance.image.id.must_equal 'img1' + instance.hardware_profile.id.must_equal 'm1-xlarge' + instance.realm.id.must_equal 'us' end end @@ -127,13 +127,13 @@ describe "instances" do DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client| hwp = { :id => 'm1-xlarge', :memory => 32768 } instance = client.create_instance( 'img1', :hardware_profile=> hwp ) - instance.should_not be_nil - instance.uri.should match( %r{#{API_URL}/instances/inst[0-9]+} ) - instance.id.should match( /inst[0-9]+/ ) - instance.image.id.should eql( 'img1' ) - instance.hardware_profile.id.should eql( 'm1-xlarge' ) - instance.hardware_profile.memory.value.should eql('12288') - instance.realm.id.should eql( 'us' ) + instance.wont_be_nil + instance.uri.must_match %r{#{API_URL}/instances/inst[0-9]+} + instance.id.must_match /inst[0-9]+/ + instance.image.id.must_equal 'img1' + instance.hardware_profile.id.must_equal 'm1-xlarge' + instance.hardware_profile.memory.value.must_equal'12288' + instance.realm.id.must_equal 'us' end end @@ -141,30 +141,30 @@ describe "instances" do DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client| instance = client.create_instance( 'img1', :realm=>'eu', :hardware_profile=>'m1-xlarge' ) - instance.should_not be_nil - instance.uri.should match( %r{#{API_URL}/instances/inst[0-9]+} ) - instance.id.should match( /inst[0-9]+/ ) - instance.image.id.should eql( 'img1' ) - instance.hardware_profile.id.should eql( 'm1-xlarge' ) - instance.realm.id.should eql( 'eu' ) + instance.wont_be_nil + instance.uri.must_match %r{#{API_URL}/instances/inst[0-9]+} + instance.id.must_match /inst[0-9]+/ + instance.image.id.must_equal 'img1' + instance.hardware_profile.id.must_equal 'm1-xlarge' + instance.realm.id.must_equal 'eu' end end it "should allow fetching of instances by id" do DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client| instance = client.instance( 'inst1' ) - instance.should_not be_nil - instance.uri.should_not be_nil - instance.uri.should be_a( String ) + instance.wont_be_nil + instance.uri.wont_be_nil + instance.uri.must_be_kind_of String end end it "should allow fetching of instances by URI" do DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client| instance = client.fetch_instance( API_URL + '/instances/inst1' ) - instance.should_not be_nil - instance.uri.should eql( API_URL + '/instances/inst1' ) - instance.id.should eql( 'inst1' ) + instance.wont_be_nil + instance.uri.must_equal API_URL + '/instances/inst1' + instance.id.must_equal 'inst1' end end @@ -172,26 +172,26 @@ describe "instances" do it "should allow actions that are valid" do DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client| instance = client.instance( 'inst1' ) - instance.should_not be_nil - instance.state.should eql( "RUNNING" ) - instance.uri.should eql( API_URL + '/instances/inst1' ) - instance.id.should eql( 'inst1' ) + instance.wont_be_nil + instance.state.must_equal "RUNNING" + instance.uri.must_equal API_URL + '/instances/inst1' + instance.id.must_equal 'inst1' instance.stop! - instance.state.should eql( "STOPPED" ) + instance.state.must_equal "STOPPED" instance.start! - instance.state.should eql( "RUNNING" ) + instance.state.must_equal "RUNNING" end end it "should not allow actions that are invalid" do DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client| instance = client.instance( 'inst1' ) - instance.should_not be_nil + instance.wont_be_nil unless instance.state.eql?("RUNNING") instance.start! end - instance.state.should eql( "RUNNING" ) - lambda{instance.start!}.should raise_error + instance.state.must_equal "RUNNING" + lambda{instance.start!}.must_raise NoMethodError end end @@ -201,9 +201,7 @@ describe "instances" do :name=>'TestDestroyInstance', :hardware_profile => 'm1-xlarge' ) instance.stop! - lambda { - instance.destroy! - }.should_not raise_error + instance.destroy!.must_be_nil end end end diff --git a/client/tests/keys_tests.rb b/client/tests/keys_tests.rb index fa2ff54..ecd661a 100644 --- a/client/tests/keys_tests.rb +++ b/client/tests/keys_tests.rb @@ -16,20 +16,23 @@ # License for the specific language governing permissions and limitations # under the License. -require 'specs/spec_helper' +require 'rubygems' +require 'require_relative' if RUBY_VERSION =~ /^1\.8/ + +require_relative './test_helper.rb' def check_key(the_key, key_name = "") - the_key.should_not be_nil - the_key.id.should be_a(String) - the_key.id.should eql(key_name) - the_key.actions.should_not be_nil - the_key.actions.size.should eql(1) - the_key.actions.first[0].should eql("destroy") - the_key.actions.first[1].should eql("#{API_URL}/keys/#{key_name}") - the_key.fingerprint.should_not be_nil - the_key.fingerprint.should be_a(String) - the_key.pem.should_not be_nil - the_key.pem.first.should be_a(String) + the_key.wont_be_nil + the_key.id.must_be_kind_of String + the_key.id.must_equal key_name + the_key.actions.wont_be_nil + the_key.actions.size.must_equal 1 + the_key.actions.first[0].must_equal "destroy" + the_key.actions.first[1].must_equal "#{API_URL}/keys/#{key_name}" + the_key.fingerprint.wont_be_nil + the_key.fingerprint.must_be_kind_of String + the_key.pem.wont_be_nil + the_key.pem.must_be_kind_of String end def create_key_if_necessary(client, key_name) @@ -40,22 +43,17 @@ def create_key_if_necessary(client, key_name) end -describe "keys" do - - it_should_behave_like "all resources" - +describe "Keys" do it "should allow retrieval of all keys" do [API_URL, API_URL_REDIRECT].each do |entry_point| DeltaCloud.new( API_NAME, API_PASSWORD, entry_point ) do |client| - lambda{ - client.keys - }.should_not raise_error + client.keys.wont_be_empty end end end end -describe "operations on keys" do +describe "Operations on Keys" do it "should allow successful creation of a new key" do DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client| @@ -79,7 +77,7 @@ describe "operations on keys" do create_key_if_necessary(client, name) lambda{ client.create_key({:name => name}) - }.should raise_error + }.must_raise DeltaCloud::HTTPError::Forbidden end end @@ -88,9 +86,7 @@ describe "operations on keys" do name = "my_new_key" create_key_if_necessary(client, name) the_key = client.key(name) - lambda{ - the_key.destroy! - }.should_not raise_error + the_key.destroy!.must_be_nil end end diff --git a/client/tests/realms_test.rb b/client/tests/realms_test.rb index 241fb5c..d01a825 100644 --- a/client/tests/realms_test.rb +++ b/client/tests/realms_test.rb @@ -16,26 +16,27 @@ # License for the specific language governing permissions and limitations # under the License. -require 'specs/spec_helper' +require 'rubygems' +require 'require_relative' if RUBY_VERSION =~ /^1\.8/ -describe "realms" do +require_relative './test_helper.rb' - it_should_behave_like "all resources" +describe "Realms" do + + before do + @client = DeltaCloud.new(API_NAME, API_PASSWORD, API_URL) + end it "should allow retrieval of all realms" do - [API_URL, API_URL_REDIRECT].each do |entry_point| - DeltaCloud.new( API_NAME, API_PASSWORD, entry_point ) do |client| - realms = client.realms - realms.should_not be_empty - realms.each do |realm| - realm.uri.should_not be_nil - realm.uri.should be_a(String) - realm.id.should_not be_nil - realm.id.should be_a(String) - realm.name.should_not be_nil - realm.name.should be_a(String) - end - end + realms = @client.realms + realms.wont_be_empty + realms.each do |realm| + realm.uri.wont_be_nil + realm.uri.must_be_kind_of String + realm.id.wont_be_nil + realm.id.must_be_kind_of String + realm.name.wont_be_nil + realm.name.must_be_kind_of String end end @@ -43,23 +44,23 @@ describe "realms" do it "should allow fetching a realm by id" do DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client| realm = client.realm( 'us' ) - realm.should_not be_nil - realm.id.should eql( 'us' ) - realm.name.should eql( 'United States' ) - realm.state.should eql( 'AVAILABLE' ) + realm.wont_be_nil + realm.id.must_equal 'us' + realm.name.must_equal 'United States' + realm.state.must_equal 'AVAILABLE' realm = client.realm( 'eu' ) - realm.should_not be_nil - realm.id.should eql( 'eu' ) - realm.name.should eql( 'Europe' ) - realm.state.should eql( 'AVAILABLE' ) + realm.wont_be_nil + realm.id.must_equal 'eu' + realm.name.must_equal 'Europe' + realm.state.must_equal 'AVAILABLE' end end it "should allow fetching a realm by URI" do DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client| realm = client.fetch_realm( API_URL + '/realms/us' ) - realm.should_not be_nil - realm.id.should eql( 'us' ) + realm.wont_be_nil + realm.id.must_equal 'us' end end diff --git a/client/tests/storage_snapshot_test.rb b/client/tests/storage_snapshot_test.rb index 94f149c..b26454b 100644 --- a/client/tests/storage_snapshot_test.rb +++ b/client/tests/storage_snapshot_test.rb @@ -16,66 +16,66 @@ # License for the specific language governing permissions and limitations # under the License. +require 'rubygems' +require 'require_relative' if RUBY_VERSION =~ /^1\.8/ -require 'specs/spec_helper' +require_relative './test_helper.rb' -describe "storage snapshot" do - - it_should_behave_like "all resources" +describe "Storage Snapshot" do it "allow retrieval of all storage volumes owned by the current user" do [API_URL, API_URL_REDIRECT].each do |entry_point| client = DeltaCloud.new( API_NAME, API_PASSWORD, entry_point ) - client.connect do |client| - storage_snapshots = client.storage_snapshots - storage_snapshots.should_not be_nil - storage_snapshots.should_not be_empty + client.connect do |c| + storage_snapshots = c.storage_snapshots + storage_snapshots.wont_be_nil + storage_snapshots.wont_be_empty ids = storage_snapshots.collect{|e| e.id} - ids.size.should eql( 3 ) - ids.should include( 'snap2' ) - ids.should include( 'snap3' ) + ids.size.must_equal 3 + ids.must_include 'snap2' + ids.must_include 'snap3' end end end it "should allow fetching of storage volume by id" do client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) - client.connect do |client| - storage_snapshot = client.storage_snapshot( 'snap2' ) - storage_snapshot.should_not be_nil - storage_snapshot.id.should eql( 'snap2' ) - storage_snapshot.storage_volume.capacity.should eql( 1.0 ) - storage_snapshot.storage_volume.id.should eql( 'vol2' ) + client.connect do |c| + storage_snapshot = c.storage_snapshot( 'snap2' ) + storage_snapshot.wont_be_nil + storage_snapshot.id.must_equal 'snap2' + storage_snapshot.storage_volume.capacity.must_equal 1.0 + storage_snapshot.storage_volume.id.must_equal 'vol2' end end it "should allow fetching of storage volume by URI" do client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) - client.connect do |client| - storage_snapshot = client.fetch_storage_snapshot( API_URL + '/storage_snapshots/snap2' ) - storage_snapshot.should_not be_nil - storage_snapshot.id.should eql( 'snap2' ) - storage_snapshot.storage_volume.capacity.should eql( 1.0 ) - storage_snapshot.storage_volume.id.should eql( 'vol2' ) + client.connect do |c| + storage_snapshot = c.fetch_storage_snapshot( API_URL + '/storage_snapshots/snap2' ) + storage_snapshot.wont_be_nil + storage_snapshot.id.must_equal 'snap2' + storage_snapshot.storage_volume.capacity.must_equal 1.0 + storage_snapshot.storage_volume.id.must_equal 'vol2' end end it "should return nil for unknown storage volume by ID" do client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) lambda { - client.connect do |client| - client.storage_snapshot( "bogus" ) + client.connect do |c| + c.storage_snapshot( "bogus" ) end - }.should raise_error(DeltaCloud::HTTPError::NotFound) + }.must_raise DeltaCloud::HTTPError::NotFound end it "should return nil for unknown storage volume by URI" do client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) lambda { - client.connect do |client| - client.fetch_storage_snapshot( API_URL + '/storage_snapshots/bogus' ) + client.connect do |c| + c.fetch_storage_snapshot( API_URL + '/storage_snapshots/bogus' ) end - }.should raise_error(DeltaCloud::HTTPError::NotFound) + }.must_raise DeltaCloud::HTTPError::NotFound end end diff --git a/client/tests/storage_volume_test.rb b/client/tests/storage_volume_test.rb index 8fb153e..1d6bd8d 100644 --- a/client/tests/storage_volume_test.rb +++ b/client/tests/storage_volume_test.rb @@ -16,75 +16,75 @@ # License for the specific language governing permissions and limitations # under the License. +require 'rubygems' +require 'require_relative' if RUBY_VERSION =~ /^1\.8/ -require 'specs/spec_helper' +require_relative './test_helper.rb' -describe "storage volumes" do - - it_should_behave_like "all resources" +describe "Storage Volumes" do it "allow retrieval of all storage volumes owned by the current user" do [API_URL, API_URL_REDIRECT].each do |entry_point| client = DeltaCloud.new( API_NAME, API_PASSWORD, entry_point ) - client.connect do |client| - storage_volumes = client.storage_volumes - storage_volumes.should_not be_nil - storage_volumes.should_not be_empty + client.connect do |c| + storage_volumes = c.storage_volumes + storage_volumes.wont_be_nil + storage_volumes.wont_be_nil ids = storage_volumes.collect{|e| e.id} - ids.size.should eql( 3 ) - ids.should include( 'vol2' ) - ids.should include( 'vol3' ) + ids.size.must_equal 3 + ids.must_include 'vol1' + ids.must_include 'vol3' end end end it "should allow fetching of storage volume by id" do client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) - client.connect do |client| - storage_volume = client.storage_volume( 'vol3' ) - storage_volume.id.should eql( 'vol3' ) - storage_volume.uri.should eql( API_URL + '/storage_volumes/vol3' ) - storage_volume.capacity.should eql( 1.0 ) - storage_volume.device.should eql( '/dev/sda1' ) - storage_volume.instance.should_not be_nil - storage_volume.instance.id.should eql( 'inst1' ) + client.connect do |c| + storage_volume = c.storage_volume( 'vol3' ) + storage_volume.id.must_equal 'vol3' + storage_volume.uri.must_equal API_URL + '/storage_volumes/vol3' + storage_volume.capacity.must_equal 1.0 + storage_volume.device.must_equal '/dev/sda1' + storage_volume.instance.wont_be_nil + storage_volume.instance.id.must_equal 'inst1' ip = storage_volume.instance - ip.hardware_profile.architecture.value.should eql( 'i386' ) + ip.hardware_profile.architecture.value.must_equal 'i386' end end it "should allow fetching of storage volume by URI" do client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) - client.connect do |client| - storage_volume = client.fetch_storage_volume( API_URL + '/storage_volumes/vol3' ) - storage_volume.should_not be_nil - storage_volume.id.should eql( 'vol3' ) - storage_volume.uri.should eql( API_URL + '/storage_volumes/vol3' ) - storage_volume.capacity.should eql( 1.0 ) - storage_volume.device.should eql( '/dev/sda1' ) - storage_volume.instance.should_not be_nil - storage_volume.instance.id.should eql( 'inst1' ) + client.connect do |c| + storage_volume = c.fetch_storage_volume( API_URL + '/storage_volumes/vol3' ) + storage_volume.wont_be_nil + storage_volume.id.must_equal 'vol3' + storage_volume.uri.must_equal API_URL + '/storage_volumes/vol3' + storage_volume.capacity.must_equal 1.0 + storage_volume.device.must_equal '/dev/sda1' + storage_volume.instance.wont_be_nil + storage_volume.instance.id.must_equal 'inst1' ip = storage_volume.instance - ip.hardware_profile.architecture.value.should eql( 'i386' ) + ip.hardware_profile.architecture.value.must_equal 'i386' end end it "should raise exception for unknown storage volume by ID" do client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) lambda { - client.connect do |client| - client.storage_volume( 'bogus' ) + client.connect do |c| + c.storage_volume( 'bogus' ) end - }.should raise_error(DeltaCloud::HTTPError::NotFound) + }.must_raise DeltaCloud::HTTPError::NotFound end it "should raise exception for unknown storage volume by URI" do client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) lambda { - client.connect do |client| + client.connect do |c| client.fetch_storage_volume( API_URL + '/storage_volumes/bogus' ) end - }.should raise_error(DeltaCloud::HTTPError::NotFound) + }.must_raise DeltaCloud::HTTPError::NotFound end diff --git a/client/tests/test_helper.rb b/client/tests/test_helper.rb new file mode 100644 index 0000000..40a2c02 --- /dev/null +++ b/client/tests/test_helper.rb @@ -0,0 +1,17 @@ +require 'rubygems' +require 'require_relative' if RUBY_VERSION =~ /^1\.8/ +require 'minitest/autorun' + +require_relative '../lib/deltacloud.rb' + +# Configuration: + +API_HOST = 'localhost' +API_PORT = '3001' +API_PATH = '/api' + +API_NAME = 'mockuser' +API_PASSWORD = 'mockpassword' + +API_URL_REDIRECT = "http://#{API_HOST}:#{API_PORT}" +API_URL = "#{API_URL_REDIRECT}#{API_PATH}" -- 1.7.10.2
