deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [3/7] git commit: Updated google driver tests to new minitest/spec format
Date Mon, 04 Jun 2012 11:24:58 GMT
Updated google driver tests to new minitest/spec format


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

Branch: refs/heads/master
Commit: 11cde595ce4d69892684004200392a567e2793be
Parents: b8120dc
Author: marios <marios@redhat.com>
Authored: Fri Jun 1 13:34:45 2012 +0300
Committer: marios <marios@redhat.com>
Committed: Mon Jun 4 14:24:12 2012 +0300

----------------------------------------------------------------------
 server/tests/drivers/google/api_test.rb     |   40 +----
 server/tests/drivers/google/buckets_test.rb |  176 ++++++++++------------
 server/tests/drivers/google/common.rb       |   72 ++++++----
 3 files changed, 129 insertions(+), 159 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/11cde595/server/tests/drivers/google/api_test.rb
----------------------------------------------------------------------
diff --git a/server/tests/drivers/google/api_test.rb b/server/tests/drivers/google/api_test.rb
index 3bb53ef..aa40151 100644
--- a/server/tests/drivers/google/api_test.rb
+++ b/server/tests/drivers/google/api_test.rb
@@ -1,41 +1,19 @@
 $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..')
 require 'tests/drivers/google/common'
 
-module GoogleTest
+describe 'Deltacloud API' do
 
-  class ApiTest < Test::Unit::TestCase
-    include Rack::Test::Methods
+  before do
+    VCR.insert_cassette __name__
+  end
 
-    def app
-      Rack::Builder.new {
-        map '/' do
-          use Rack::Static, :urls => ["/stylesheets", "/javascripts"], :root => "public"
-          run Rack::Cascade.new([Deltacloud::API])
-        end
-      }
-    end
+  after do
+    VCR.eject_cassette
+  end
 
-    def test_01_it_returns_entry_points
-      get_auth_url '/api?force_auth=1'
-      (last_xml_response/'/api').first[:driver].should == 'google'
-      (last_xml_response/'/api/link').length.should > 0
-    end
+  include Deltacloud::Test
 
-    def test_02_it_has_google_features
-      get_url '/api'
-      features = (last_xml_response/'/api/link[@rel="buckets"]/feature').collect { |f| f[:name]
}
-      features.include?('bucket_location').should == true
-      features.length.should == 1
-    end
+  eval File.read('tests/minitest_common_api_test.rb')
 
-    def test_03_it_has_google_collections
-      get_url '/api'
-      puts last_xml_response
-      collections = (last_xml_response/'/api/link').collect { |f| f[:rel] }
-      collections.include?('buckets').should == true
-      collections.include?('drivers').should == true
-      collections.length.should == 2
-    end
 
-  end
 end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/11cde595/server/tests/drivers/google/buckets_test.rb
----------------------------------------------------------------------
diff --git a/server/tests/drivers/google/buckets_test.rb b/server/tests/drivers/google/buckets_test.rb
index 14a953f..5980175 100644
--- a/server/tests/drivers/google/buckets_test.rb
+++ b/server/tests/drivers/google/buckets_test.rb
@@ -1,122 +1,100 @@
 $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..')
 require 'tests/drivers/google/common'
 
-module GoogleTest
+describe 'Deltacloud API' do
 
-  class BucketsTest < Test::Unit::TestCase
-    include Rack::Test::Methods
+  before do
+    VCR.insert_cassette __name__
+  end
 
-    def app
-      Rack::Builder.new {
-        map '/' do
-          use Rack::Static, :urls => ["/stylesheets", "/javascripts"], :root => "public"
-          run Rack::Cascade.new([Deltacloud::API])
-        end
-      }
-    end
+  after do
+    VCR.eject_cassette
+  end
+
+  include Deltacloud::Test
+
+i_suck_and_my_tests_are_order_dependent!
 
     @@bucket_name_google="#{@@created_bucket_name}googel"
     @@blob_name_google="#{@@created_blob_name}googel"
 #intentional typos here - bucket names cannot contain 'google'
 #see http://code.google.com/apis/storage/docs/reference/v1/developer-guidev1.html
+  it 'can create a new bucket' do
+    authenticate
+    bucket_name = @@bucket_name_google
+    post collection_url(:buckets), {:name=>bucket_name}
+    last_response.status.must_equal 201
+    bucket = xml_response
+    check_bucket_basics(bucket, "googel")
+    (bucket/'bucket/size').first.text.must_equal "0"
+  end
 
-   def test_01_it_can_create_new_bucket
-      params = {
-        :name => @@bucket_name_google,
-        :'api[driver]' => 'google'
-      }
-      vcr_cassette = stable_vcr_cassette_name('post', '/api/buckets', params)
-      post_url '/api/buckets', params, {'vcr_cassette'=>vcr_cassette}
-      last_response.status.should == 201 # Created
-      bucket = last_xml_response
-      check_bucket_basics(bucket, "googel")
-      (bucket/'bucket/size').first.text.should == "0"
-    end
-
-    def test_02_it_can_post_new_blob
-      temp_file=File.open(@@created_blob_local_file)
-      params = {
-        'blob_id' => @@blob_name_google,
-        :meta_params=>"2",
-        :meta_name1=>"Author",
-        :meta_value1=>"deltacloud",
-        :meta_name2=>"foo",
-        :meta_value2=>"bar",
-        :'api[driver]' => 'google'
-      }
-      uri="/api/buckets/#{@@bucket_name_google}"
-      vcr_cassette = stable_vcr_cassette_name('post', uri, params)
-      params.merge!({'blob_data' => Rack::Test::UploadedFile.new(temp_file.path, "text/html")})
-      post_url uri, params, {'vcr_cassette'=>vcr_cassette}
-      last_response.status.should == 200
-      blob= last_xml_response
-      check_blob_basics(blob, "googel")
-    end
+  it 'can create a new blob with HTTP POST' do
+    authenticate
+    temp_file=File.open(@@created_blob_local_file)
+    params = { 'blob_id' => @@blob_name_google,
+              :meta_params=>"2",
+              :meta_name1=>"Author",
+              :meta_value1=>"deltacloud",
+              :meta_name2=>"foo",
+              :meta_value2=>"bar",
+              'blob_data' => Rack::Test::UploadedFile.new(temp_file.path, "text/html")
}
+    post "#{collection_url(:buckets)}/#{@@bucket_name_google}", params
+    last_response.status.must_equal 200
+    blob = xml_response
+    check_blob_basics(blob, "googel")
+  end
 
-    def test_03_it_can_retrieve_named_bucket_details
-       params = {
-        :'api[driver]' => 'google'
-      }
-      get_url "/api/buckets/#{@@bucket_name_google}", params
-      last_response.status.should == 200
-      bucket = last_xml_response
-      check_bucket_basics(bucket, "googel")
-      (bucket/'bucket/size').first.text.should == "1" #assuming blob created succesfully
right?
-    end
+  it 'can retrieve named bucket details' do
+    authenticate
+    get "#{collection_url(:buckets)}/#{@@bucket_name_google}"
+    last_response.status.must_equal 200
+    bucket = xml_response
+    check_bucket_basics(bucket, "googel")
+    (bucket/'bucket/size').first.text.must_equal "1" #assuming blob created succesfully right?
+  end
 
-    def test_04_it_can_retrieve_named_blob_details
-      params = {
-                :'api[driver]' => 'google'
-               }
-      get_url "/api/buckets/#{@@bucket_name_google}/#{@@blob_name_google}", params
-      last_response.status.should == 200
-      blob = last_xml_response
+  it 'can retrieve details of a named blob' do
+      authenticate
+      get "#{collection_url(:buckets)}/#{@@bucket_name_google}/#{@@blob_name_google}"
+      last_response.status.must_equal 200
+      blob = xml_response
       check_blob_basics(blob, "googel")
       check_blob_metadata(blob, {"author"=>"deltacloud", "foo"=>"bar"})
-    end
+  end
 
-    def test_05_it_can_retrieve_blob_metadata
-      params = {
-                :'api[driver]' => 'google'
-               }
-      head_url "/api/buckets/#{@@bucket_name_google}/#{@@blob_name_google}", params
-      last_response.status.should == 200
-      puts last_response.body
-      blob_meta_hash = last_response.headers.inject({}){|result, (k,v)| result[k]=v if k=~/^X-Deltacloud-Blobmeta-/i
; result}
-      blob_meta_hash.gsub_keys(/x-.*meta-/i, "")
-      ({"author"=>"deltacloud", "foo"=>"bar"}.eql?(blob_meta_hash)).should == true
-    end
+  it 'can retrieve named blob metadata' do
+    authenticate
+    head "#{collection_url(:buckets)}/#{@@bucket_name_google}/#{@@blob_name_google}"
+    last_response.status.must_equal 204
+    blob_meta_hash = last_response.headers.inject({}){|result, (k,v)| result[k]=v if k=~/^X-Deltacloud-Blobmeta-/i
; result}
+    blob_meta_hash.gsub_keys(/x-.*meta-/i, "")
+    {"author"=>"deltacloud", "foo"=>"bar"}.must_equal blob_meta_hash
+  end
 
-    def test_06_it_can_update_blob_metadata
-      params = {
-                :'api[driver]' => 'google'
-               }
-      new_meta = {"X-Deltacloud-Blobmeta-author" => "ApacheDeltacloud", "X-Deltacloud-Blobmeta-oof"
=> "rab"}
-      new_meta.each_pair do |k,v|
-        header k, v
-      end
-      post_url "/api/buckets/#{@@bucket_name_google}/#{@@blob_name_google}", params
-      last_response.status.should == 204
-      new_meta.each_pair do |k,v|
-        (last_response.headers[k]==v).should == true
-      end
+  it 'can update blob metadata' do
+    authenticate
+    new_meta = {"X-Deltacloud-Blobmeta-author" => "ApacheDeltacloud", "X-Deltacloud-Blobmeta-oof"
=> "rab"}
+    new_meta.each_pair do |k,v|
+      header k, v
     end
-
-    def test_07_it_can_delete_blob
-      params = {
-                :'api[driver]' => 'google'
-               }
-      delete_url "/api/buckets/#{@@bucket_name_google}/#{@@blob_name_google}", params
-      last_response.status.should == 204
+    post "#{collection_url(:buckets)}/#{@@bucket_name_google}/#{@@blob_name_google}"
+    last_response.status.must_equal 204
+    new_meta.each_pair do |k,v|
+      last_response.headers[k].must_equal v
     end
+  end
 
-    def test_08_it_can_delete_bucket
-      params = {
-                :'api[driver]' => 'google'
-               }
-      delete_url "/api/buckets/#{@@bucket_name_google}", params
-      last_response.status.should == 204
-    end
+  it 'can delete blob' do
+    authenticate
+    delete "#{collection_url(:buckets)}/#{@@bucket_name_google}/#{@@blob_name_google}"
+    last_response.status.must_equal 204
+  end
 
+  it 'can delete bucket' do
+    authenticate
+    delete "#{collection_url(:buckets)}/#{@@bucket_name_google}"
+    last_response.status.must_equal 204
   end
+
 end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/11cde595/server/tests/drivers/google/common.rb
----------------------------------------------------------------------
diff --git a/server/tests/drivers/google/common.rb b/server/tests/drivers/google/common.rb
index ea008e2..6e35a8d 100644
--- a/server/tests/drivers/google/common.rb
+++ b/server/tests/drivers/google/common.rb
@@ -1,40 +1,54 @@
 ENV['API_DRIVER']   = "google"
-ENV['API_USER']     = 'GOOGK7JXLS6UEYS6AYVO'
-ENV['API_PASSWORD'] = 'QjxUunLgszKhBGn/LISQajGR82CfwvraxA9lqnkg'
+ENV['TESTS_API_USERNAME']     = 'GOOGUM2I5ZVSPSV5H42U'
+ENV['TESTS_API_PASSWORD'] = 'sXhLOsE4SYU+M7SKsTwwNX2YPpMOKIiRyZaZxcBp'
 
-load File.join(File.dirname(__FILE__), '..', '..', 'common.rb')
+$:.unshift File.join(File.dirname(__FILE__), '..', '..', '..')
+require 'tests/minitest_common'
 
 require 'vcr'
 
-DeltacloudTestCommon::record!
-
-VCR.config do |c|
+VCR.configure do |c|
   c.cassette_library_dir = "#{File.dirname(__FILE__)}/fixtures/"
-  c.stub_with :excon
+  c.hook_into :excon
   c.default_cassette_options = { :record => :new_episodes}
 end
 
-#monkey patch fix for VCR normalisation code:
-#see https://github.com/myronmarston/vcr/issues/4
-#when body is a tempfile, like when creating new blob
-#this method of normalisation fails and excon throws errors
-#(Excon::Errors::SocketError:can't convert Tempfile into String)
-#
-#RELEVANT: https://github.com/myronmarston/vcr/issues/101
-#(will need revisiting when vcr 2 comes along)
-
-module VCR
-  module Normalizers
-    module Body
-
-    private
-    def normalize_body
-     self.body = case body
-          when nil, ''; nil
-          else
-            String.new(body) unless body.is_a?(Tempfile)
-        end
-      end
+#the following can probably be moved to somewhere more 'common'
+#once other driver tests start using them (e.g. openstack).
+
+  @@created_bucket_name="testbucki2rpux3wdelme"
+  @@created_blob_name="testblobk1ds91kVdelme"
+  @@created_blob_local_file="#{File.dirname(__FILE__)}/../common_fixtures/deltacloud_blob_test.png"
+
+  def check_bucket_basics(bucket, cloud)
+    (bucket/'bucket/name').first.text.must_equal "#{@@created_bucket_name}#{cloud}"
+    (bucket/'bucket').attribute("id").text.must_equal "#{@@created_bucket_name}#{cloud}"
+    (bucket/'bucket').length.must_be :>, 0
+    (bucket/'bucket/name').first.text.wont_be_nil
+    (bucket/'bucket').attribute("href").text.wont_be_nil
+  end
+
+  def check_blob_basics(blob, cloud)
+    (blob/'blob').length.must_equal 1
+    (blob/'blob').attribute("id").text.wont_be_nil
+    (blob/'blob').attribute("href").text.wont_be_nil
+    (blob/'blob/bucket').text.wont_be_nil
+    (blob/'blob/content_length').text.wont_be_nil
+    (blob/'blob/content_type').text.wont_be_nil
+    (blob/'blob').attribute("id").text.must_equal "#{@@created_blob_name}#{cloud}"
+    (blob/'blob/bucket').text.must_equal "#{@@created_bucket_name}#{cloud}"
+    (blob/'blob/content_length').text.to_i.must_equal File.size(@@created_blob_local_file)
+  end
+
+  def check_blob_metadata(blob, metadata_hash)
+    meta_from_blob = {}
+    #extract metadata from nokogiri blob xml
+    (0.. (((blob/'blob/user_metadata').first).elements.size - 1) ).each do |i|
+      meta_from_blob[(((blob/'blob/user_metadata').first).elements[i].attribute("key").value)]
=
+                                  (((blob/'blob/user_metadata').first).elements[i].children[1].text)
     end
+    #remove any 'x-goog-meta-' prefixes (problem for google blobs and vcr...)
+    meta_from_blob.gsub_keys(/x-.*-meta-/i, "")
+    meta_from_blob.must_equal metadata_hash
   end
-end
+


Mime
View raw message