You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by lu...@redhat.com on 2012/08/08 02:55:20 UTC

Very simple CIMI tests

Some extremely simple CIMI tests - they just check that the cloud entry
point is there and returns something.

Note the interesting way in which we query for the collections in
cimi/test_helper.rb - I think the spec needs to be changed to make that a
little more precise.

David

[PATCH 2/2] tests: very simple CIMI tests

Posted by lu...@redhat.com.
From: David Lutterkort <lu...@redhat.com>

---
 tests/Rakefile            |    4 ++
 tests/cimi/cep_test.rb    |   38 ++++++++++++++++
 tests/cimi/test_helper.rb |  108 +++++++++++++++++++++++++++++++++++++++++++++
 tests/config.yaml         |    6 +++
 4 files changed, 156 insertions(+), 0 deletions(-)
 create mode 100644 tests/cimi/cep_test.rb
 create mode 100644 tests/cimi/test_helper.rb

diff --git a/tests/Rakefile b/tests/Rakefile
index 88c1966..f276dbb 100644
--- a/tests/Rakefile
+++ b/tests/Rakefile
@@ -30,4 +30,8 @@ namespace :test do
     end
   end
 
+  Rake::TestTask.new(:cimi) do |t|
+    t.test_files = FileList["cimi/*_test.rb"]
+  end
+
 end
diff --git a/tests/cimi/cep_test.rb b/tests/cimi/cep_test.rb
new file mode 100644
index 0000000..3dc2be5
--- /dev/null
+++ b/tests/cimi/cep_test.rb
@@ -0,0 +1,38 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.  The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the
+# License.  You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+$:.unshift File.join(File.dirname(__FILE__))
+
+require "test_helper.rb"
+
+describe "CIMI Entry Point" do
+  include CIMI::Test::Methods
+
+  it "should return XML if asked to" do
+    res = cep :accept => :xml
+    res.headers[:content_type].must_equal "application/xml"
+    res.xml.root.name.must_equal "CloudEntryPoint"
+    names = res.xml.xpath("/c:CloudEntryPoint", api.ns).map { |e| e.name }
+    names.must_equal ["CloudEntryPoint"]
+    (res.xml/"CloudEntryPoint/id").text.must_equal api.cep_url
+  end
+
+  it "should return JSON if asked to" do
+    res = cep :accept => :json
+    res.headers[:content_type].must_equal "application/json"
+    res.json["id"].must_equal api.cep_url
+  end
+end
diff --git a/tests/cimi/test_helper.rb b/tests/cimi/test_helper.rb
new file mode 100644
index 0000000..f26fa96
--- /dev/null
+++ b/tests/cimi/test_helper.rb
@@ -0,0 +1,108 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.  The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the
+# License.  You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+require 'rubygems'
+require 'require_relative'
+require_relative '../helpers/common.rb'
+
+require 'singleton'
+
+# Add CIMI specific config stuff
+module CIMI
+  module Test
+    class Config
+
+      include Singleton
+
+      def initialize
+        @hash = Deltacloud::Test::yaml_config
+        @cimi = @hash["cimi"]
+      end
+
+      def cep_url
+        @cimi["cep"]
+      end
+
+      def collections
+        xml.xpath("/c:CloudEntryPoint/c:*[@href]", ns).map { |c| c.name }
+      end
+
+      def features
+        {}
+      end
+
+      def ns
+        { "c" => "http://www.dmtf.org/cimi" }
+      end
+
+      private
+      def xml
+        unless @xml
+          @xml = RestClient.get(cep_url, "Accept" => "application/xml").xml
+        end
+        @xml
+      end
+    end
+
+    def self.config
+      Config::instance
+    end
+  end
+end
+
+module CIMI::Test::Methods
+
+  module Global
+    def api
+      CIMI::Test::config
+    end
+
+    def cep(params = {})
+      get(api.cep_url, params)
+    end
+
+    def get(path, params = {})
+      RestClient.get path, headers(params)
+    end
+
+    private
+    def headers(params)
+      headers = {}
+      if params[:accept]
+        headers["Accept"] = "application/#{params.delete(:accept)}" if params[:accept]
+      else #default to xml
+        headers["Accept"] = "application/xml"
+      end
+      headers
+    end
+  end
+
+  module ClassMethods
+    def need_collection(name)
+      before :each do
+        unless api.collections.include?(name.to_sym)
+          skip "Server at #{api.cep_url} doesn't support #{name}"
+        end
+      end
+    end
+  end
+
+  def self.included(base)
+    base.extend ClassMethods
+    base.extend Global
+    base.send(:include, Global)
+  end
+end
diff --git a/tests/config.yaml b/tests/config.yaml
index 5f905a6..1651261 100644
--- a/tests/config.yaml
+++ b/tests/config.yaml
@@ -29,3 +29,9 @@ ec2:
     preferred_image: "ami-2b5fba42"
     preferred_hwp: "m1.small"
     preferred_realm: "us-east-1b"
+
+# CIMI testing
+cimi:
+  cep: "http://localhost:3001/cimi/cloudEntryPoint"
+  user: "mockuser"
+  password: "mockpassword"
-- 
1.7.7.6


[PATCH 1/2] tests: split common helper out of test_setup.rb

Posted by lu...@redhat.com.
From: David Lutterkort <lu...@redhat.com>

---
 tests/deltacloud/test_setup.rb |   47 +++--------------------------
 tests/helpers/common.rb        |   63 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+), 42 deletions(-)
 create mode 100644 tests/helpers/common.rb

diff --git a/tests/deltacloud/test_setup.rb b/tests/deltacloud/test_setup.rb
index e034493..d0aa24b 100644
--- a/tests/deltacloud/test_setup.rb
+++ b/tests/deltacloud/test_setup.rb
@@ -15,46 +15,11 @@
 # under the License.
 
 require 'rubygems'
-require 'minitest/autorun'
-require 'rest_client'
-require 'nokogiri'
-require 'json'
-require 'base64'
-require 'yaml'
-require 'singleton'
-#SETUP
-topdir = File.join(File.dirname(__FILE__), '..')
-$:.unshift topdir
-require 'deltacloud/common_tests_collections.rb'
-
-module RestClient::Response
-  def xml
-    @xml ||= Nokogiri::XML(body)
-  end
+require 'require_relative'
+require_relative '../helpers/common.rb'
+require_relative 'common_tests_collections.rb'
 
-  def json
-    @json ||= JSON.parse(body)
-  end
-end
-
-class String
-  def singularize
-    return self.gsub(/ies$/, 'y') if self =~ /ies$/
-    return self.gsub(/es$/, '') if self =~ /sses$/
-    self.gsub(/s$/, '')
-  end
-end
-
-class Array
-  alias :original_method_missing :method_missing
-
-  def method_missing(name, *args)
-    if name == :choice
-      return self.sample(*args)
-    end
-    original_method_missing(name, *args)
-  end
-end
+require 'singleton'
 
 module Deltacloud
   module Test
@@ -64,9 +29,7 @@ module Deltacloud
       include Singleton
 
       def initialize
-        fname = ENV["CONFIG"] || File::join(File::dirname(__FILE__), "..",
-                                            "config.yaml")
-        @hash = YAML.load(File::open(fname))
+        @hash = Deltacloud::Test::yaml_config
       end
 
       def url
diff --git a/tests/helpers/common.rb b/tests/helpers/common.rb
new file mode 100644
index 0000000..0e1a4b1
--- /dev/null
+++ b/tests/helpers/common.rb
@@ -0,0 +1,63 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.  The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the
+# License.  You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+require 'rubygems'
+require 'minitest/autorun'
+require 'rest_client'
+require 'nokogiri'
+require 'json'
+require 'base64'
+require 'yaml'
+
+module RestClient::Response
+  def xml
+    @xml ||= Nokogiri::XML(body)
+  end
+
+  def json
+    @json ||= JSON.parse(body)
+  end
+end
+
+class String
+  def singularize
+    return self.gsub(/ies$/, 'y') if self =~ /ies$/
+    return self.gsub(/es$/, '') if self =~ /sses$/
+    self.gsub(/s$/, '')
+  end
+end
+
+class Array
+  alias :original_method_missing :method_missing
+
+  def method_missing(name, *args)
+    if name == :choice
+      return self.sample(*args)
+    end
+    original_method_missing(name, *args)
+  end
+end
+
+module Deltacloud
+  module Test
+
+    def self.yaml_config
+      fname = ENV["CONFIG"] || File::join(File::dirname(__FILE__), "..",
+                                          "config.yaml")
+      YAML.load(File::open(fname))
+    end
+  end
+end
-- 
1.7.7.6