deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [4/31] git commit: Detect which tests to run dynamically
Date Wed, 25 Jul 2012 13:56:38 GMT
Detect which tests to run dynamically

We load all testfiles and skip tests if the needed collection/feature isn't
supported by the driver.


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

Branch: refs/heads/master
Commit: b0388032a129c5913d38c04ef0721f9c4bbd713d
Parents: 1f35cdc
Author: David Lutterkort <lutter@redhat.com>
Authored: Mon Jul 23 17:15:55 2012 -0700
Committer: marios <marios@redhat.com>
Committed: Tue Jul 24 12:03:03 2012 +0300

----------------------------------------------------------------------
 tests/Rakefile                   |    6 +--
 tests/deltacloud/buckets_test.rb |   17 +++++---
 tests/deltacloud/test_setup.rb   |   70 ++++++++++++++++++++-------------
 3 files changed, 53 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/b0388032/tests/Rakefile
----------------------------------------------------------------------
diff --git a/tests/Rakefile b/tests/Rakefile
index 6ee5b13..6ac2106 100644
--- a/tests/Rakefile
+++ b/tests/Rakefile
@@ -15,14 +15,10 @@
 # under the License.
 
 require 'rake/testtask'
-require 'deltacloud/test_setup.rb'
 
 namespace :test do
-
   desc "Run tests for the Deltacloud API frontend."
   Rake::TestTask.new(:deltacloud) do |t|
-    file_list = Rake::FileList.new(deltacloud_test_file_names)
-    t.test_files = file_list << "deltacloud/base_api_test.rb"
+    t.test_files = FileList["deltacloud/*_test.rb"]
   end
-
 end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/b0388032/tests/deltacloud/buckets_test.rb
----------------------------------------------------------------------
diff --git a/tests/deltacloud/buckets_test.rb b/tests/deltacloud/buckets_test.rb
index 84533d6..e4ee12e 100644
--- a/tests/deltacloud/buckets_test.rb
+++ b/tests/deltacloud/buckets_test.rb
@@ -44,9 +44,10 @@ end
 #make sure we have at least one bucket and blob to test
 created_bucket_and_blob = create_a_bucket_and_blob
 
-features_hash = discover_features
-
 describe 'Deltacloud API buckets collection' do
+  include Deltacloud::Test::Methods
+
+  need_collection :buckets
 
   MiniTest::Unit.after_tests {
     bucket, blob = created_bucket_and_blob
@@ -92,12 +93,14 @@ describe 'Deltacloud API buckets collection' do
     res.code.must_equal 204
   end
 
-  it 'should be possible to specify location for POST /api/buckets if bucket_location feature'
do
-    skip("No bucket_location feature specified for driver #{api.driver} running at #{api.url}...
skipping test") unless features_hash["buckets"].include?("bucket_location")
-    bucket_name = random_name
-    #    res = post({:name=>bucket_name, :bucket_location=>
-  end
+  describe "with feature bucket_location" do
+    need_feature :buckets, :bucket_location
 
+    it 'should be possible to specify location for POST /api/buckets if bucket_location feature'
do
+      bucket_name = random_name
+      #    res = post({:name=>bucket_name, :bucket_location=>
+    end
+  end
 
   it 'should support the JSON media type' do
     res = get(BUCKETS, :accept=>:json)

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/b0388032/tests/deltacloud/test_setup.rb
----------------------------------------------------------------------
diff --git a/tests/deltacloud/test_setup.rb b/tests/deltacloud/test_setup.rb
index ca37186..b2f6861 100644
--- a/tests/deltacloud/test_setup.rb
+++ b/tests/deltacloud/test_setup.rb
@@ -72,6 +72,18 @@ module Deltacloud
         xml.root[:version]
       end
 
+      def collections
+        xml.xpath("//api/link").map { |c| c[:rel].to_sym }
+      end
+
+      def features
+        result = {}
+        xml.xpath("//api/link").each do |coll|
+          result[coll[:rel].to_sym] = coll.xpath("feature").map { |c| c[:name].to_sym }
+        end
+        result
+      end
+
       private
       def xml
         unless @xml
@@ -162,37 +174,39 @@ def process_url_params(path, params)
   [url, headers]
 end
 
-#the TEST_FILES hash and deltacloud_test_file_names method
-#which follows is used in the Rakefile for the rake test:deltacloud task
-TEST_FILES =  { :images             => "images_test.rb",
-  :realms             => "realms_test.rb",
-  :hardware_profiles  => "hardware_profiles_test.rb",
-  :instance_states    => "instance_states_test.rb",
-  :instances          => "instances_test.rb",
-  :keys               => "keys_test.rb",
-  :firewalls          => "firewalls_test.rb",
-  :addresses          => "addresses_test.rb",
-  :load_balancers     => "load_balancers_test.rb",
-  :storage_volumes    => "storage_volumes_test.rb",
-  :storage_snapshots  => "storage_snapshots_test.rb",
-  :buckets            => "buckets_test.rb"
-}
-#gets the list of collections from the server running at api.url and translates those into
file names accoring to TEST_FILES
-def deltacloud_test_file_names
-  driver_collections = (RestClient.get api.url, {:accept=>:xml}).xml.xpath("//api/link").inject([]){|res,
current| res<<current[:rel].to_sym ;res}
-  driver_collections.inject([]){|res, current| res << "deltacloud/#{TEST_FILES[current]}"
if TEST_FILES[current] ;res}
+module Deltacloud::Test::Methods
+
+  def self.included(base)
+    base.extend ClassMethods
+  end
+
+  module ClassMethods
+    # Only run tests if collection +name+ is supported by current
+    # driver. Use inside a 'describe' block. Tests that are not run because
+    # of a missing collection are marked as skipped
+    def need_collection(name)
+      before :each do
+        unless api.collections.include?(name.to_sym)
+          skip "#{api.driver} doesn't support #{name}"
+        end
+      end
+    end
+
+    # Only run tests if collection +collection+ supports feature +name+ in
+    # the current driver. Use inside a 'describe' block. Tests that are not
+    # run because of a missing collection are marked as skipped
+    def need_feature(collection, name)
+      before :each do
+        f = api.features[collection.to_sym]
+        unless f && f.include?(name.to_sym)
+          skip "#{collection} for #{api.driver} doesn't support #{name}"
+        end
+      end
+    end
+  end
 end
 
 def random_name
   name = rand(36**10).to_s(36)
   name.insert(0, "apitest")
 end
-
-def discover_features
-  res = get("/")
-  features_hash = res.xml.xpath("//api/link").inject({}) do |result, collection|
-    result.merge!({collection[:rel] => []})
-    collection.children.inject([]){|features, current_child| result[collection[:rel]] <<
current_child[:name] if current_child.name == "feature"}
-    result
-  end
-end


Mime
View raw message