deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@redhat.com
Subject [PATCH core 5/5] CIMI: Added initial support for CIMI collections tests
Date Fri, 03 Aug 2012 09:10:42 GMT
From: Michal Fojtik <mfojtik@redhat.com>


Signed-off-by: Michal fojtik <mfojtik@redhat.com>
---
 server/Rakefile                                    |    2 +
 .../cimi/collections/cloud_entry_point_test.rb     |   46 ++++++++++++++++++++
 server/tests/cimi/collections/common.rb            |   26 +++++++++++
 .../tests/cimi/collections/machine_images_test.rb  |   44 +++++++++++++++++++
 server/tests/cimi/collections/machines_test.rb     |   41 +++++++++++++++++
 .../cimi/spec/cimi/model/machine_admin_spec.rb     |    3 ++
 .../spec/cimi/model/machine_configuration_spec.rb  |    3 +-
 .../cimi/spec/cimi/model/machine_image_spec.rb     |    2 +
 server/tests/cimi/spec/cimi/model/machine_spec.rb  |    2 +
 .../cimi/spec/cimi/model/machine_template_spec.rb  |    2 +
 server/tests/cimi/spec/cimi/model/schema_spec.rb   |    2 +
 .../spec/cimi/model/volume_configuration_spec.rb   |    2 +
 .../cimi/spec/cimi/model/volume_image_spec.rb      |    2 +
 server/tests/cimi/spec/cimi/model/volume_spec.rb   |    2 +
 .../cimi/spec/cimi/model/volume_template_spec.rb   |    2 +
 server/tests/cimi/spec/spec_helper.rb              |    1 +
 16 files changed, 181 insertions(+), 1 deletion(-)
 create mode 100644 server/tests/cimi/collections/cloud_entry_point_test.rb
 create mode 100644 server/tests/cimi/collections/common.rb
 create mode 100644 server/tests/cimi/collections/machine_images_test.rb
 create mode 100644 server/tests/cimi/collections/machines_test.rb

diff --git a/server/Rakefile b/server/Rakefile
index ec3984b..184fe6c 100644
--- a/server/Rakefile
+++ b/server/Rakefile
@@ -185,11 +185,13 @@ namespace :test do
   namespace :cimi do
     Rake::TestTask.new(:models) do |t|
       t.ruby_opts << '-r./tests/cimi/spec/spec_helper.rb'    # Load SimpleCov when
COVERAGE=1 is set
+      t.ruby_opts << '-r./tests/test_helper.rb'    # Load SimpleCov when COVERAGE=1
is set
       unless RUBY_VERSION < '1.9.0'
         t.loader = :testrb
       end
       t.test_files = FileList[
         'tests/cimi/spec/cimi/model/*spec.rb',        # CIMI frontend serialization API tests
+        'tests/cimi/collections/*test.rb',        # CIMI frontend API tests
       ]
     end
   end
diff --git a/server/tests/cimi/collections/cloud_entry_point_test.rb b/server/tests/cimi/collections/cloud_entry_point_test.rb
new file mode 100644
index 0000000..95b09c1
--- /dev/null
+++ b/server/tests/cimi/collections/cloud_entry_point_test.rb
@@ -0,0 +1,46 @@
+require 'rubygems'
+require 'require_relative'
+
+require 'minitest/autorun'
+require_relative './common.rb'
+
+describe CIMI::Collections::CloudEntryPoint do
+
+  before do
+    def app; CIMI::API; end
+    @collection = CIMI::Collections.collection(:cloudEntryPoint)
+  end
+
+  it 'has index operation' do
+    @collection.operation(:index).must_equal Sinatra::Rabbit::CloudentrypointCollection::IndexOperation
+  end
+
+  it 'set the CIMI-Version header' do
+    get root_url
+    headers['X-CIMI-Specification-Version'].wont_be_nil
+    headers['X-CIMI-Specification-Version'].must_equal '1.0.0'
+  end
+
+  it 'advertise CIMI collections in XML format' do
+    get root_url + '/cloudEntryPoint'
+    xml.root.name.must_equal 'CloudEntryPoint'
+    (xml.root/'description').first.text.wont_be_empty
+    (xml.root/'id').first.text.wont_be_empty
+  end
+
+  it 'advertise CIMI collections in JSON format' do
+    get root_url + '/cloudEntryPoint?format=json'
+    json.wont_be_empty
+    json['description'].wont_be_empty
+    json['id'].wont_be_empty
+  end
+
+  it 'allow to force authentication using force_auth parameter in URI' do
+    get root_url + '/cloudEntryPoint?force_auth=1'
+    status.must_equal 401
+    authorize 'mockuser', 'mockpassword'
+    get root_url + '/cloudEntryPoint?force_auth=1'
+    status.must_equal 200
+  end
+
+end
diff --git a/server/tests/cimi/collections/common.rb b/server/tests/cimi/collections/common.rb
new file mode 100644
index 0000000..0706dc4
--- /dev/null
+++ b/server/tests/cimi/collections/common.rb
@@ -0,0 +1,26 @@
+require_relative File.join('..', '..', '..', 'lib', 'deltacloud_rack.rb')
+
+unless Time.respond_to? :be
+  require_relative '../../test_helper.rb'
+end
+
+# Set the default driver used for server API tests
+#
+ENV['API_DRIVER'] = 'mock'
+
+# Setup Deltacloud::API Sinatra instance
+#
+unless Deltacloud::config[:cimi]
+  Deltacloud::configure(:cimi) do |server|
+    server.root_url '/cimi'
+    server.version '1.0.0'
+    server.klass 'CIMI::API'
+    server.logger Rack::DeltacloudLogger.setup(ENV['API_LOG'], ENV['API_VERBOSE'])
+  end
+
+  Deltacloud.require_frontend!(:cimi)
+end
+
+def root_url(url=''); Deltacloud.config[:cimi].root_url + url; end
+def formats; [ 'application/xml', 'application/json' ]; end
+def json; JSON::parse(response_body); end
diff --git a/server/tests/cimi/collections/machine_images_test.rb b/server/tests/cimi/collections/machine_images_test.rb
new file mode 100644
index 0000000..c5367a3
--- /dev/null
+++ b/server/tests/cimi/collections/machine_images_test.rb
@@ -0,0 +1,44 @@
+require 'rubygems'
+require 'require_relative'
+require 'minitest/autorun'
+require_relative './common.rb'
+
+describe CIMI::Collections::MachineImages do
+
+  before do
+    def app; CIMI::API; end
+    authorize 'mockuser', 'mockpassword'
+    @collection = CIMI::Collections.collection(:machine_images)
+  end
+
+  it 'has index operation' do
+    @collection.operation(:index).must_equal Sinatra::Rabbit::MachineImagesCollection::IndexOperation
+  end
+
+  it 'has show operation' do
+    @collection.operation(:show).must_equal Sinatra::Rabbit::MachineImagesCollection::ShowOperation
+  end
+
+  it 'returns list of images in various formats with index operation' do
+    formats.each do |format|
+      header 'Accept', format
+      get root_url + '/machine_images'
+      status.must_equal 200
+    end
+  end
+
+  it 'should allow to retrieve the single image' do
+    get root_url '/machine_images/img1'
+    status.must_equal 200
+    xml.root.name.must_equal 'MachineImage'
+  end
+
+  it 'should allow to filter using CIMISelect' do
+    get root_url '/machine_images?CIMISelect=description'
+    status.must_equal 200
+    xml.root.name.must_equal 'MachineImageCollection'
+    (xml/'description').wont_be_empty
+    (xml/'id').must_be_empty
+  end
+
+end
diff --git a/server/tests/cimi/collections/machines_test.rb b/server/tests/cimi/collections/machines_test.rb
new file mode 100644
index 0000000..328b712
--- /dev/null
+++ b/server/tests/cimi/collections/machines_test.rb
@@ -0,0 +1,41 @@
+require 'rubygems'
+require 'require_relative'
+require 'minitest/autorun'
+require_relative './common.rb'
+
+describe CIMI::Collections::Machines do
+
+  before do
+    def app; CIMI::API; end
+    authorize 'mockuser', 'mockpassword'
+    @collection = CIMI::Collections.collection(:machines)
+  end
+
+  it 'has index operation' do
+    @collection.operation(:index).must_equal Sinatra::Rabbit::MachinesCollection::IndexOperation
+  end
+
+  it 'has show operation' do
+    @collection.operation(:show).must_equal Sinatra::Rabbit::MachinesCollection::ShowOperation
+  end
+
+  it 'returns list of machines in various formats with index operation' do
+    formats.each do |format|
+      header 'Accept', format
+      get root_url + '/machines'
+      status.must_equal 200
+    end
+  end
+
+  it 'should allow to retrieve the single machine' do
+    get root_url '/machines/inst1'
+    status.must_equal 200
+    xml.root.name.must_equal 'Machine'
+  end
+
+  it 'should not return non-existing machine' do
+    get root_url '/machines/unknown-machine'
+    status.must_equal 404
+  end
+
+end
diff --git a/server/tests/cimi/spec/cimi/model/machine_admin_spec.rb b/server/tests/cimi/spec/cimi/model/machine_admin_spec.rb
index 132272d..3fc272c 100644
--- a/server/tests/cimi/spec/cimi/model/machine_admin_spec.rb
+++ b/server/tests/cimi/spec/cimi/model/machine_admin_spec.rb
@@ -14,6 +14,9 @@
 # under the License.
 #
 
+require 'rubygems'
+require 'require_relative'
+
 if require 'minitest/autorun'
   require_relative '../../spec_helper.rb'
 end
diff --git a/server/tests/cimi/spec/cimi/model/machine_configuration_spec.rb b/server/tests/cimi/spec/cimi/model/machine_configuration_spec.rb
index e59fcc0..f990871 100644
--- a/server/tests/cimi/spec/cimi/model/machine_configuration_spec.rb
+++ b/server/tests/cimi/spec/cimi/model/machine_configuration_spec.rb
@@ -13,7 +13,8 @@
 # License for the specific language governing permissions and limitations
 # under the License.
 #
-
+require 'rubygems'
+require 'require_relative'
 require_relative '../../spec_helper.rb' if require 'minitest/autorun'
 
 describe "MachineConfiguration model" do
diff --git a/server/tests/cimi/spec/cimi/model/machine_image_spec.rb b/server/tests/cimi/spec/cimi/model/machine_image_spec.rb
index 7eef29a..dd5ddbe 100644
--- a/server/tests/cimi/spec/cimi/model/machine_image_spec.rb
+++ b/server/tests/cimi/spec/cimi/model/machine_image_spec.rb
@@ -13,6 +13,8 @@
 # License for the specific language governing permissions and limitations
 # under the License.
 #
+require 'rubygems'
+require 'require_relative'
 
 require_relative '../../spec_helper.rb' if require 'minitest/autorun'
 
diff --git a/server/tests/cimi/spec/cimi/model/machine_spec.rb b/server/tests/cimi/spec/cimi/model/machine_spec.rb
index b10ecfe..ad9f11e 100644
--- a/server/tests/cimi/spec/cimi/model/machine_spec.rb
+++ b/server/tests/cimi/spec/cimi/model/machine_spec.rb
@@ -13,6 +13,8 @@
 # License for the specific language governing permissions and limitations
 # under the License.
 #
+require 'rubygems'
+require 'require_relative'
 
 require_relative '../../spec_helper.rb' if require 'minitest/autorun'
 
diff --git a/server/tests/cimi/spec/cimi/model/machine_template_spec.rb b/server/tests/cimi/spec/cimi/model/machine_template_spec.rb
index 7210c92..97bdce9 100644
--- a/server/tests/cimi/spec/cimi/model/machine_template_spec.rb
+++ b/server/tests/cimi/spec/cimi/model/machine_template_spec.rb
@@ -13,6 +13,8 @@
 # License for the specific language governing permissions and limitations
 # under the License.
 #
+require 'rubygems'
+require 'require_relative'
 
 require_relative '../../spec_helper.rb' if require 'minitest/autorun'
 
diff --git a/server/tests/cimi/spec/cimi/model/schema_spec.rb b/server/tests/cimi/spec/cimi/model/schema_spec.rb
index c5619b1..8b6de48 100644
--- a/server/tests/cimi/spec/cimi/model/schema_spec.rb
+++ b/server/tests/cimi/spec/cimi/model/schema_spec.rb
@@ -13,6 +13,8 @@
 # License for the specific language governing permissions and limitations
 # under the License.
 #
+require 'rubygems'
+require 'require_relative'
 
 require_relative '../../spec_helper.rb' if require 'minitest/autorun'
 
diff --git a/server/tests/cimi/spec/cimi/model/volume_configuration_spec.rb b/server/tests/cimi/spec/cimi/model/volume_configuration_spec.rb
index c12ac05..0f26edc 100644
--- a/server/tests/cimi/spec/cimi/model/volume_configuration_spec.rb
+++ b/server/tests/cimi/spec/cimi/model/volume_configuration_spec.rb
@@ -14,6 +14,8 @@
 # License for the specific language governing permissions and limitations
 # under the License.
 #
+require 'rubygems'
+require 'require_relative'
 
 require_relative '../../spec_helper.rb' if require 'minitest/autorun'
 
diff --git a/server/tests/cimi/spec/cimi/model/volume_image_spec.rb b/server/tests/cimi/spec/cimi/model/volume_image_spec.rb
index a6c4a20..10509da 100644
--- a/server/tests/cimi/spec/cimi/model/volume_image_spec.rb
+++ b/server/tests/cimi/spec/cimi/model/volume_image_spec.rb
@@ -13,6 +13,8 @@
 # License for the specific language governing permissions and limitations
 # under the License.
 #
+require 'rubygems'
+require 'require_relative'
 
 require_relative '../../spec_helper.rb' if require 'minitest/autorun'
 
diff --git a/server/tests/cimi/spec/cimi/model/volume_spec.rb b/server/tests/cimi/spec/cimi/model/volume_spec.rb
index 1176add..c3bad88 100644
--- a/server/tests/cimi/spec/cimi/model/volume_spec.rb
+++ b/server/tests/cimi/spec/cimi/model/volume_spec.rb
@@ -13,6 +13,8 @@
 # License for the specific language governing permissions and limitations
 # under the License.
 #
+require 'rubygems'
+require 'require_relative'
 
 require_relative '../../spec_helper.rb' if require 'minitest/autorun'
 
diff --git a/server/tests/cimi/spec/cimi/model/volume_template_spec.rb b/server/tests/cimi/spec/cimi/model/volume_template_spec.rb
index 444baa7..4bf969c 100644
--- a/server/tests/cimi/spec/cimi/model/volume_template_spec.rb
+++ b/server/tests/cimi/spec/cimi/model/volume_template_spec.rb
@@ -13,6 +13,8 @@
 # License for the specific language governing permissions and limitations
 # under the License.
 #
+require 'rubygems'
+require 'require_relative'
 
 require_relative '../../spec_helper.rb' if require 'minitest/autorun'
 
diff --git a/server/tests/cimi/spec/spec_helper.rb b/server/tests/cimi/spec/spec_helper.rb
index 3cde6cf..c2ea2d1 100644
--- a/server/tests/cimi/spec/spec_helper.rb
+++ b/server/tests/cimi/spec/spec_helper.rb
@@ -14,6 +14,7 @@
 # under the License.
 #
 
+require 'rubygems'
 require 'minitest/autorun'
 require 'minitest/spec'
 require 'xmlsimple'
-- 
1.7.10.2


Mime
View raw message