deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject [4/65] git commit: Core: Added more collection tests and test_helper to run simplecov
Date Fri, 20 Jul 2012 09:59:21 GMT
Core: Added more collection tests and test_helper to run simplecov


Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/13929848
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/13929848
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/13929848

Branch: refs/heads/master
Commit: 1392984883a135dc91c0bb1bd5629904c38d2d33
Parents: b8331b1
Author: Michal Fojtik <mfojtik@redhat.com>
Authored: Thu Jul 19 14:52:52 2012 +0200
Committer: Michal fojtik <mfojtik@redhat.com>
Committed: Fri Jul 20 11:59:09 2012 +0200

----------------------------------------------------------------------
 server/Rakefile                                    |   10 ++-
 .../collections/buckets_collection_test.rb         |   64 +++++++++++++++
 .../collections/drivers_collection_test.rb         |   36 ++++++++
 .../collections/images_collection_test.rb          |   58 +++++++++++++
 .../collections/instance_states_collection_test.rb |   33 ++++++++
 .../collections/instances_collection_test.rb       |   24 ++++++
 server/tests/helpers/core_ext/integer_test.rb      |    2 +-
 server/tests/test_helper.rb                        |   21 +++++
 8 files changed, 243 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/13929848/server/Rakefile
----------------------------------------------------------------------
diff --git a/server/Rakefile b/server/Rakefile
index bd50a35..bc84c96 100644
--- a/server/Rakefile
+++ b/server/Rakefile
@@ -109,10 +109,12 @@ task :routes do
 end
 
 Rake::TestTask.new do |t|
+  t.ruby_opts << '-r./tests/test_helper.rb'   # Load SimpleCov when COVERAGE=1 is set
   t.test_files = FileList[
-    'tests/helpers/**/*test.rb',      # Deltacloud extensions (core_ext) and other helpers
-    'tests/drivers/base/*test.rb',    # Deltacloud drivers API tests
-    'tests/drivers/models/*test.rb',  # Deltacloud models tests
-    'tests/deltacloud/*test.rb'       # Deltacloud internal API tests
+    'tests/helpers/**/*test.rb',              # Deltacloud extensions (core_ext) and other
helpers
+    'tests/drivers/base/*test.rb',            # Deltacloud drivers API tests
+    'tests/drivers/models/*test.rb',          # Deltacloud models tests
+    'tests/deltacloud/*test.rb',              # Deltacloud internal API tests
+    'tests/deltacloud/collections/*test.rb'   # Deltacloud collections
   ]
 end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/13929848/server/tests/deltacloud/collections/buckets_collection_test.rb
----------------------------------------------------------------------
diff --git a/server/tests/deltacloud/collections/buckets_collection_test.rb b/server/tests/deltacloud/collections/buckets_collection_test.rb
new file mode 100644
index 0000000..6eff7ad
--- /dev/null
+++ b/server/tests/deltacloud/collections/buckets_collection_test.rb
@@ -0,0 +1,64 @@
+require 'minitest/autorun'
+
+load File.join(File.dirname(__FILE__), '..', 'common.rb')
+
+describe Deltacloud::Collections::Buckets do
+
+  before do
+    def app; Deltacloud::API; end
+    authorize 'mockuser', 'mockpassword'
+    @collection = Deltacloud::Collections.collection(:buckets)
+  end
+
+  it 'has index operation' do
+    @collection.operation(:index).must_equal Sinatra::Rabbit::BucketsCollection::IndexOperation
+  end
+
+  it 'provides URL to specify new bucket' do
+    header 'Accept', 'text/html'
+    get root_url + '/buckets/new/' + Deltacloud::Helpers::Application::NEW_BLOB_FORM_ID
+    status.must_equal 200
+  end
+
+  it 'returns list of buckets in various formats with index operation' do
+    formats.each do |format|
+      header 'Accept', format
+      get root_url + '/buckets'
+      status.must_equal 200
+    end
+  end
+
+  it 'must support creating a new bucket and destroying it' do
+    post root_url + '/buckets', { :name => 'test-bucket1' }
+    status.must_equal 201
+    xml.root.name.must_equal 'bucket'
+    delete root_url + '/buckets/' + xml.root[:id]
+    status.must_equal 204
+  end
+
+  it 'returns blob metadata' do
+    head root_url + '/buckets/bucket1/blob1'
+    headers['X-Deltacloud-Blobmeta-SOMENEWKEY'].must_equal 'NEWVALUE'
+    status.must_equal 204
+    head root_url + '/buckets/bucket1/non-existing-blob'
+    status.must_equal 404
+  end
+
+  it 'returns blob details on show operation in various formats' do
+    formats.each do |format|
+      header 'Accept', format
+      get root_url + '/buckets/bucket1/blob1'
+      last_response
+      status.must_equal 200
+    end
+  end
+
+  it 'creates a new blob and then destroy it' do
+    post root_url + '/buckets/bucket1', { :blob_id => 'test-blob', :blob_data => 'test',
:meta_params => '1', :meta_name1 => 'test-meta1' }
+    status.must_equal 201
+    delete root_url + '/buckets/bucket1/test-blob'
+    status.must_equal 204
+  end
+
+
+end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/13929848/server/tests/deltacloud/collections/drivers_collection_test.rb
----------------------------------------------------------------------
diff --git a/server/tests/deltacloud/collections/drivers_collection_test.rb b/server/tests/deltacloud/collections/drivers_collection_test.rb
new file mode 100644
index 0000000..4467b68
--- /dev/null
+++ b/server/tests/deltacloud/collections/drivers_collection_test.rb
@@ -0,0 +1,36 @@
+require 'minitest/autorun'
+
+load File.join(File.dirname(__FILE__), '..', 'common.rb')
+
+describe Deltacloud::Collections::Drivers do
+
+  before do
+    def app; Deltacloud::API; end
+    @collection = Deltacloud::Collections.collection(:drivers)
+  end
+
+  it 'has index operation' do
+    @collection.operation(:index).must_equal Sinatra::Rabbit::DriversCollection::IndexOperation
+  end
+
+  it 'has show operation' do
+    @collection.operation(:show).must_equal Sinatra::Rabbit::DriversCollection::ShowOperation
+  end
+
+  it 'returns list of drivers in various formats with index operation' do
+    formats.each do |format|
+      header 'Accept', format
+      get root_url + '/drivers'
+      status.must_equal 200
+    end
+  end
+
+  it 'returns details about driver in various formats with show operation' do
+    formats.each do |format|
+      header 'Accept', format
+      get root_url + '/drivers/mock'
+      status.must_equal 200
+    end
+  end
+
+end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/13929848/server/tests/deltacloud/collections/images_collection_test.rb
----------------------------------------------------------------------
diff --git a/server/tests/deltacloud/collections/images_collection_test.rb b/server/tests/deltacloud/collections/images_collection_test.rb
new file mode 100644
index 0000000..8262df8
--- /dev/null
+++ b/server/tests/deltacloud/collections/images_collection_test.rb
@@ -0,0 +1,58 @@
+require 'minitest/autorun'
+
+load File.join(File.dirname(__FILE__), '..', 'common.rb')
+
+describe Deltacloud::Collections::Images do
+
+  before do
+    def app; Deltacloud::API; end
+    authorize 'mockuser', 'mockpassword'
+    @collection = Deltacloud::Collections.collection(:images)
+  end
+
+  it 'has index operation' do
+    @collection.operation(:index).must_equal Sinatra::Rabbit::ImagesCollection::IndexOperation
+  end
+
+  it 'has show operation' do
+    @collection.operation(:show).must_equal Sinatra::Rabbit::ImagesCollection::ShowOperation
+  end
+
+  it 'returns list of drivers in various formats with index operation' do
+    formats.each do |format|
+      header 'Accept', format
+      get root_url + '/images'
+      status.must_equal 200
+    end
+  end
+
+  it 'returns details about driver in various formats with show operation' do
+    formats.each do |format|
+      header 'Accept', format
+      get root_url + '/images/img1'
+      status.must_equal 200
+    end
+  end
+
+  it 'provides URL to specify new image' do
+    header 'Accept', 'text/html'
+    get root_url + '/images/new?instance_id=inst1'
+    status.must_equal 200
+    get root_url + '/images/new'
+    status.must_equal 404
+  end
+
+  it 'allow to create and destroy the new image' do
+    post root_url + '/images', { :instance_id => 'inst1', :name => 'img-test1', :description
=> 'test image' }
+    status.must_equal 201
+    xml.root[:id].wont_be_nil
+    delete root_url + '/images/' + xml.root[:id]
+    status.must_equal 204
+  end
+
+  it 'reports 404 when querying non-existing image' do
+    get root_url + '/images/non-existing-one'
+    status.must_equal 404
+  end
+
+end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/13929848/server/tests/deltacloud/collections/instance_states_collection_test.rb
----------------------------------------------------------------------
diff --git a/server/tests/deltacloud/collections/instance_states_collection_test.rb b/server/tests/deltacloud/collections/instance_states_collection_test.rb
new file mode 100644
index 0000000..ecf86c5
--- /dev/null
+++ b/server/tests/deltacloud/collections/instance_states_collection_test.rb
@@ -0,0 +1,33 @@
+require 'minitest/autorun'
+
+load File.join(File.dirname(__FILE__), '..', 'common.rb')
+
+describe Deltacloud::Collections::InstanceStates do
+
+  before do
+    def app; Deltacloud::API; end
+    authorize 'mockuser', 'mockpassword'
+    @collection = Deltacloud::Collections.collection(:instance_states)
+  end
+
+  it 'has index operation' do
+    @collection.operation(:index).must_equal Sinatra::Rabbit::InstanceStatesCollection::IndexOperation
+  end
+
+  it 'returns list of states for current driver in various formats with index operation'
do
+    get root_url + '/instance_states'
+    status.must_equal 200
+    xml.root.name.must_equal 'states'
+    header 'Accept', 'application/json'
+    get root_url + '/instance_states'
+    status.must_equal 200
+    JSON::parse(response_body).must_be_kind_of Array
+    JSON::parse(response_body).wont_be_empty
+    header 'Accept', 'image/png'
+    get root_url + '/instance_states'
+    status.must_equal 200
+    last_response.content_type.must_equal 'image/png'
+  end
+
+
+end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/13929848/server/tests/deltacloud/collections/instances_collection_test.rb
----------------------------------------------------------------------
diff --git a/server/tests/deltacloud/collections/instances_collection_test.rb b/server/tests/deltacloud/collections/instances_collection_test.rb
new file mode 100644
index 0000000..a1da030
--- /dev/null
+++ b/server/tests/deltacloud/collections/instances_collection_test.rb
@@ -0,0 +1,24 @@
+require 'minitest/autorun'
+
+load File.join(File.dirname(__FILE__), '..', 'common.rb')
+
+describe Deltacloud::Collections::Instances do
+
+  before do
+    def app; Deltacloud::API; end
+    authorize 'mockuser', 'mockpassword'
+    @collection = Deltacloud::Collections.collection(:instances)
+  end
+
+  it 'has index operation' do
+    @collection.operation(:index).must_equal Sinatra::Rabbit::InstancesCollection::IndexOperation
+  end
+
+  it 'provides URL to specify new instance' do
+    header 'Accept', 'text/html'
+    get root_url + '/instances/new?image_id=img1'
+    status.must_equal 200
+  end
+
+
+end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/13929848/server/tests/helpers/core_ext/integer_test.rb
----------------------------------------------------------------------
diff --git a/server/tests/helpers/core_ext/integer_test.rb b/server/tests/helpers/core_ext/integer_test.rb
index 2ddf09b..b4d50f6 100644
--- a/server/tests/helpers/core_ext/integer_test.rb
+++ b/server/tests/helpers/core_ext/integer_test.rb
@@ -11,7 +11,7 @@ class TestInteger < MiniTest::Unit::TestCase
     assert_equal '2nd', 2.ordinalize
     assert_equal '3rd', 3.ordinalize
     assert_equal '6th', 6.ordinalize
-    assert_equal '1100th', 1100.ordinalize
+    assert_equal '1211th', 1211.ordinalize
   end
 
 end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/13929848/server/tests/test_helper.rb
----------------------------------------------------------------------
diff --git a/server/tests/test_helper.rb b/server/tests/test_helper.rb
new file mode 100644
index 0000000..3bbd6a3
--- /dev/null
+++ b/server/tests/test_helper.rb
@@ -0,0 +1,21 @@
+
+%x[rake mock:fixtures:reset]
+
+if ENV['COVERAGE']
+  begin
+    require 'simplecov'
+    SimpleCov.start do
+      command_name 'Minitest tests'
+      project_name 'Deltacloud API'
+      add_filter "tests/"
+      add_group 'Drivers', 'lib/deltacloud/drivers'
+      add_group 'Collections', 'lib/deltacloud/collections'
+      add_group 'Models', 'lib/deltacloud/models'
+      add_group 'Helpers', 'lib/deltacloud/helpers'
+      add_group 'Extensions', 'lib/deltacloud/core_ext'
+      add_group 'Sinatra', 'lib/sinatra'
+    end
+  rescue LoadError
+    warn "To generate code coverage you need to install 'simplecov' (gem install simplecov
OR bundle)"
+  end
+end


Mime
View raw message