deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lut...@apache.org
Subject [15/15] git commit: CIMI Tests: factor collection tests into test_helper and use w/ machine_colln
Date Thu, 08 Nov 2012 17:13:51 GMT
CIMI Tests: factor collection tests into test_helper and use w/ machine_colln

These tests only perform basic collection sanity checks, and are therefore
applicable for most collections


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

Branch: refs/heads/master
Commit: 90200d320127be9e690580b5f821eafda0adaff6
Parents: bd498ee
Author: David Lutterkort <lutter@redhat.com>
Authored: Tue Nov 6 16:45:36 2012 -0800
Committer: David Lutterkort <lutter@redhat.com>
Committed: Thu Nov 8 09:11:01 2012 -0800

----------------------------------------------------------------------
 tests/cimi/machine_collection_test.rb |    4 +++-
 tests/cimi/network_collection_test.rb |   15 +--------------
 tests/cimi/test_helper.rb             |   21 +++++++++++++++++++++
 3 files changed, 25 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/90200d32/tests/cimi/machine_collection_test.rb
----------------------------------------------------------------------
diff --git a/tests/cimi/machine_collection_test.rb b/tests/cimi/machine_collection_test.rb
index c390b5b..a5ad3f4 100644
--- a/tests/cimi/machine_collection_test.rb
+++ b/tests/cimi/machine_collection_test.rb
@@ -24,9 +24,11 @@ class MachineCollectionBehavior < CIMI::Test::Spec
 
   model :machines, CIMI::Model::MachineCollection do |fmt|
     mcoll_uri = cep(:accept => :json).json["machines"]["href"]
-    get(mcoll_uri, :accept => :json)
+    get(mcoll_uri, :accept => fmt)
   end
 
+  check_collection :machines, CIMI::Model::Machine
+
   it "should have the correct resourceURI", :only => :json do
     machines.wont_be_nil      # Make sure we talk to the server
     last_response.json["resourceURI"].must_equal RESOURCE_URI

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/90200d32/tests/cimi/network_collection_test.rb
----------------------------------------------------------------------
diff --git a/tests/cimi/network_collection_test.rb b/tests/cimi/network_collection_test.rb
index 3e8872b..cd01583 100644
--- a/tests/cimi/network_collection_test.rb
+++ b/tests/cimi/network_collection_test.rb
@@ -27,18 +27,5 @@ class NetworkCollectionBehavior < CIMI::Test::Spec
     get(coll_uri, :accept => fmt)
   end
 
-  it "must have the \"id\" and \"count\" attributes" do
-    networks.count.wont_be_nil
-    networks.count.to_i.must_equal networks.entries.size
-    networks.id.must_be_uri
-  end
-
-  it "must have a valid id and name for each member" do
-    networks.entries.each do |entry|
-      entry.id.must_be_uri
-      member = fetch(entry.id, CIMI::Model::Network)
-      member.id.must_equal entry.id
-      member.name.must_equal entry.name
-    end
-  end
+  check_collection :networks, CIMI::Model::Network
 end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/90200d32/tests/cimi/test_helper.rb
----------------------------------------------------------------------
diff --git a/tests/cimi/test_helper.rb b/tests/cimi/test_helper.rb
index e264af3..303cce0 100644
--- a/tests/cimi/test_helper.rb
+++ b/tests/cimi/test_helper.rb
@@ -122,6 +122,27 @@ module CIMI::Test::Methods
         end
       end
     end
+
+    # Perform basic collection checks; +model_name+ is the name of the
+    # method returning the collection model; +member_class+ is the class
+    # for the model of individual entries
+    def check_collection(model_name, member_class)
+      it "must have the \"id\" and \"count\" attributes" do
+        coll = self.send(model_name)
+        coll.count.wont_be_nil
+        coll.count.to_i.must_equal coll.entries.size
+        coll.id.must_be_uri
+      end
+
+      it "must have a valid id and name for each member" do
+        self.send(model_name).entries.each do |entry|
+          entry.id.must_be_uri
+          member = fetch(entry.id, member_class)
+          member.id.must_equal entry.id
+          member.name.must_equal entry.name
+        end
+      end
+    end
   end
 
   def self.included(base)


Mime
View raw message