deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject [20/50] [abbrv] git commit: EC2: Initial unit tests for EC2 frontend
Date Mon, 30 Jul 2012 14:29:17 GMT
EC2: Initial unit tests for EC2 frontend


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

Branch: refs/heads/master
Commit: 41ea5de14c7490974a53750873a1070c21041999
Parents: 340a91d
Author: Michal Fojtik <mfojtik@redhat.com>
Authored: Thu Jul 26 15:50:13 2012 +0200
Committer: Michal fojtik <mfojtik@redhat.com>
Committed: Fri Jul 27 14:05:31 2012 +0200

----------------------------------------------------------------------
 server/tests/ec2/common.rb            |   19 ++++++
 server/tests/ec2/query_parser_test.rb |   97 ++++++++++++++++++++++++++++
 server/tests/ec2/server_test.rb       |   44 +++++++++++++
 3 files changed, 160 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/41ea5de1/server/tests/ec2/common.rb
----------------------------------------------------------------------
diff --git a/server/tests/ec2/common.rb b/server/tests/ec2/common.rb
new file mode 100644
index 0000000..21787c1
--- /dev/null
+++ b/server/tests/ec2/common.rb
@@ -0,0 +1,19 @@
+require_relative File.join('..', '..', 'lib', 'deltacloud_rack.rb')
+
+# Set the default driver used for server API tests
+#
+ENV['API_DRIVER'] = 'mock'
+
+# Setup Deltacloud::API Sinatra instance
+#
+unless Deltacloud::config[:ec2]
+  Deltacloud::configure(:ec2) do |server|
+    server.root_url '/'
+    server.version '2012-04-01'
+    server.klass 'Deltacloud::EC2::API'
+    server.logger Rack::DeltacloudLogger.setup(ENV['API_LOG'], ENV['API_VERBOSE'])
+  end
+  Deltacloud.require_frontend! :ec2
+end
+
+def root_url; Deltacloud.config[:ec2].root_url; end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/41ea5de1/server/tests/ec2/query_parser_test.rb
----------------------------------------------------------------------
diff --git a/server/tests/ec2/query_parser_test.rb b/server/tests/ec2/query_parser_test.rb
new file mode 100644
index 0000000..761e5bc
--- /dev/null
+++ b/server/tests/ec2/query_parser_test.rb
@@ -0,0 +1,97 @@
+require 'minitest/autorun'
+
+require_relative 'common.rb'
+require_relative File.join('..', '..', 'lib', 'deltacloud', 'api.rb')
+
+describe Deltacloud::EC2 do
+
+  describe Deltacloud::EC2::ActionHandler do
+
+    before do
+      @handler = Deltacloud::EC2::ActionHandler
+    end
+
+    it 'provides access to mappings' do
+      @handler.mappings.wont_be_nil
+      @handler.mappings.must_be_kind_of Hash
+    end
+
+  end
+
+  describe Deltacloud::EC2::QueryParser do
+
+    before do
+      @parser = Deltacloud::EC2::QueryParser
+    end
+
+    it 'parse request parameters and assign the action' do
+      result = @parser.parse({'Action' => 'DescribeAvailabilityZones', 'ZoneName.1' =>
'us'}, '1')
+      result.wont_be_nil
+      result.must_be_kind_of Deltacloud::EC2::ActionHandler
+      result.action.wont_be_nil
+      result.action.must_be_kind_of @parser
+      result.action.action.must_equal :describe_availability_zones
+      result.action.request_id.must_equal '1'
+      result.action.parameters.wont_be_nil
+      result.action.parameters.must_be_kind_of Hash
+      result.action.parameters['ZoneName.1'].must_equal 'us'
+    end
+
+    it 'must provide verification for actions' do
+      result = @parser.parse({'Action' => 'DescribeAvailabilityZones', 'ZoneName.1' =>
'us'}, '1')
+      result.wont_be_nil
+      result.must_be_kind_of Deltacloud::EC2::ActionHandler
+      result.action.wont_be_nil
+      result.action.must_be_kind_of @parser
+      result.action.valid_actions.wont_be_nil
+      result.action.valid_actions.must_include :describe_availability_zones
+      result.action.valid_action?.must_equal true
+    end
+
+    it 'must provide the Deltacloud method for EC2 action' do
+      result = @parser.parse({'Action' => 'DescribeAvailabilityZones', 'ZoneName.1' =>
'us'}, '1')
+      result.wont_be_nil
+      result.must_be_kind_of Deltacloud::EC2::ActionHandler
+      result.deltacloud_method.must_equal :realms
+      result.deltacloud_method_params[:id].wont_be_nil
+      result.deltacloud_method_params[:id].must_equal 'us'
+    end
+
+  end
+
+  describe Deltacloud::EC2::ResultParser do
+
+    before do
+      @parser = Deltacloud::EC2::QueryParser
+      @driver = Deltacloud::new(:mock, :user => 'mockuser', :password => 'mockpassword')
+      def app; Deltacloud::EC2::API; end
+    end
+
+    it 'must perform the EC2 action on Deltacloud driver' do
+      result = @parser.parse({'Action' => 'DescribeAvailabilityZones', 'ZoneName.1' =>
'us'}, '1')
+      result.wont_be_nil
+      result.must_be_kind_of Deltacloud::EC2::ActionHandler
+      result.action.wont_be_nil
+      result.action.must_be_kind_of @parser
+      result.must_respond_to :'perform!'
+      realms = result.perform!(@driver.credentials, @driver.backend)
+      realms.wont_be_empty
+      realms.first.must_be_kind_of Realm
+      realms.first.id.must_equal 'us'
+    end
+
+    it 'must parse the result of EC2 action to EC2 formatted XML' do
+      result = @parser.parse({'Action' => 'DescribeAvailabilityZones', 'ZoneName.1' =>
'us'}, '1')
+      result.wont_be_nil
+      result.must_be_kind_of Deltacloud::EC2::ActionHandler
+      result.action.wont_be_nil
+      result.action.must_be_kind_of @parser
+      result.must_respond_to :'perform!'
+      result.perform!(@driver.credentials, @driver.backend)
+      result = Nokogiri::XML(result.to_xml(app))
+      result.root.name.must_equal 'DescribeAvailabilityZonesResponse'
+    end
+
+  end
+
+end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/41ea5de1/server/tests/ec2/server_test.rb
----------------------------------------------------------------------
diff --git a/server/tests/ec2/server_test.rb b/server/tests/ec2/server_test.rb
new file mode 100644
index 0000000..cca030b
--- /dev/null
+++ b/server/tests/ec2/server_test.rb
@@ -0,0 +1,44 @@
+require 'minitest/autorun'
+
+require_relative 'common.rb'
+
+describe Deltacloud::EC2::API do
+
+  before do
+    def app; Deltacloud::EC2::API; end
+  end
+
+  it 'has the config set property' do
+    Deltacloud::config[:ec2].must_be_kind_of Deltacloud::Server
+    root_url.must_equal Deltacloud[:ec2].root_url
+  end
+
+  it 'must do a redirection when no Action parameter' do
+    get root_url
+    status.must_equal 301
+    headers['Location'].must_equal 'http://example.org/'
+  end
+
+  it 'must set the Connection header to close' do
+    get root_url
+    headers['Connection'].must_equal 'close'
+  end
+
+  it 'must advertise current API version in response headers' do
+    get root_url
+    headers['Server'].must_equal 'Apache-Deltacloud-EC2/2012-04-01'
+  end
+
+  it 'must return EC2 exception when unknown action' do
+    get root_url + '?Action=UnknownActionTest'
+    xml.root.name.must_equal 'Response'
+    (xml/'Response/Errors/Code').first.text.strip.must_equal 'InvalidAction'
+  end
+
+  it 'must return EC2 exception when authentication failed' do
+    authorize 'unknownuser', 'password'
+    get root_url + '?Action=DescribeAvailabilityZones'
+    status.must_equal 401
+  end
+
+end


Mime
View raw message