deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [1/31] git commit: API TESTS - initial commit for API tests rewrite:
Date Wed, 25 Jul 2012 13:56:38 GMT
Updated Branches:
  refs/heads/master bf14ec917 -> 99972905b


API TESTS - initial commit for API tests rewrite:

mini dsl for features/collections requirement by lutter
setup and common methods in test_setup.rb
initial tests exercising API and buckets collection


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

Branch: refs/heads/master
Commit: 99972905b868120b36d656793ae70de6d54c1469
Parents: d90175a
Author: marios <marios@redhat.com>
Authored: Wed Jul 25 16:53:48 2012 +0300
Committer: marios <marios@redhat.com>
Committed: Wed Jul 25 16:53:48 2012 +0300

----------------------------------------------------------------------
 tests/Rakefile                       |    1 +
 tests/config.yaml                    |   16 ++--
 tests/deltacloud/buckets_test.rb     |  117 ++++++++++++++++++++++++-----
 tests/deltacloud/test_blob_large.png |  Bin 0 -> 171052 bytes
 tests/deltacloud/test_blob_small.png |  Bin 0 -> 24436 bytes
 tests/deltacloud/test_setup.rb       |   31 +++++++-
 6 files changed, 137 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/99972905/tests/Rakefile
----------------------------------------------------------------------
diff --git a/tests/Rakefile b/tests/Rakefile
index 6ac2106..26b27a4 100644
--- a/tests/Rakefile
+++ b/tests/Rakefile
@@ -20,5 +20,6 @@ namespace :test do
   desc "Run tests for the Deltacloud API frontend."
   Rake::TestTask.new(:deltacloud) do |t|
     t.test_files = FileList["deltacloud/*_test.rb"]
+    t.options = "-v"
   end
 end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/99972905/tests/config.yaml
----------------------------------------------------------------------
diff --git a/tests/config.yaml b/tests/config.yaml
index e94a29e..3070b56 100644
--- a/tests/config.yaml
+++ b/tests/config.yaml
@@ -6,13 +6,13 @@ mock:
   password: "mockpassword"
 #EC2 DRIVER CONFIG:
 ec2:
-  user: #your EC2 KEY HERE
-  password: #your EC2 SECRET_KEY HERE
+  user: #EC2 KEY
+  password: #EC2 SECRET KEY
   bucket_locations:
   #location constraint : provider
-    "EU" : "eu-west-1"
-    "sa-east-1" : "sa-east-1"
-    "us-west-1" : "us-west-1"
-    "us-west-2" : "us-west-2"
-    "ap-southeast-1" : "ap-southeast-1"
-    "ap-northeast-1" : "ap-northeast-1"
+    - "EU"
+    - "sa-east-1"
+    - "us-west-1"
+    - "us-west-2"
+    - "ap-southeast-1"
+    - "ap-northeast-1"

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/99972905/tests/deltacloud/buckets_test.rb
----------------------------------------------------------------------
diff --git a/tests/deltacloud/buckets_test.rb b/tests/deltacloud/buckets_test.rb
index 1601546..e8732b1 100644
--- a/tests/deltacloud/buckets_test.rb
+++ b/tests/deltacloud/buckets_test.rb
@@ -17,10 +17,16 @@
 $:.unshift File.join(File.dirname(__FILE__), '..')
 require "deltacloud/test_setup.rb"
 
-
-require 'ruby-debug'
 BUCKETS = "/buckets"
 
+def small_blob_file
+ File.new(File::join(File::dirname(__FILE__),"test_blob_small.png"))
+end
+
+def large_blob_file
+ File.new(File::join(File::dirname(__FILE__),"test_blob_large.png"))
+end
+
 describe 'Deltacloud API buckets collection' do
   include Deltacloud::Test::Methods
 
@@ -28,37 +34,35 @@ describe 'Deltacloud API buckets collection' do
 
   #make sure we have at least one bucket and blob to test
   begin
-    @my_bucket = random_name
-    @my_blob = random_name
-    res = post(BUCKETS, :name=>@my_bucket)
+    @@my_bucket = random_name
+    @@my_blob = random_name
+    res = post(BUCKETS, :name=>@@my_bucket)
     unless res.code == 201
-      raise Exception.new("Failed to create bucket #{@my_bucket}")
+      raise Exception.new("Failed to create bucket #{@@my_bucket}")
     end
 
-    res = RestClient.put "#{api.url}/buckets/#{@my_bucket}/#{@my_blob}",
-    "This is the test blob content",
-    {:Authorization=>api.basic_auth,
-      :content_type=>"text/plain",
-      "X-Deltacloud-Blobmeta-Version"=>"1.0",
-      "X-Deltacloud-Blobmeta-Author"=>"herpyderp"}
+    res = put("#{BUCKETS}/#{@@my_bucket}/#{@@my_blob}", "This is the test blob content",
+           {:content_type=>"text/plain", "X-Deltacloud-Blobmeta-Version"=>"1.0",
+            "X-Deltacloud-Blobmeta-Author"=>"herpyderp"})
     unless res.code == 200
-      raise Exception.new("Failed to create blob #{@my_blob}")
+      raise Exception.new("Failed to create blob #{@@my_blob}")
     end
   end
 
   # delete the bucket/blob we created for the tests
   MiniTest::Unit.after_tests {
-    res = delete("/buckets/#{@my_bucket}/#{@my_blob}")
+    res = delete("/buckets/#{@@my_bucket}/#{@@my_blob}")
     unless res.code == 204
-      raise Exception.new("Failed to delete blob #{@my_blob}")
+      raise Exception.new("Failed to delete blob #{@@my_blob}")
     end
-    res = delete("/buckets/#{@my_bucket}")
+    res = delete("/buckets/#{@@my_bucket}")
     unless res.code == 204
-      raise Exception.new("Failed to delete bucket #{@my_bucket}")
+      raise Exception.new("Failed to delete bucket #{@@my_bucket}")
     end
   }
 
   it 'must advertise the buckets collection in API entrypoint' do
+
     res = get("/").xml
     (res/'api/link[@rel=buckets]').wont_be_empty
   end
@@ -89,12 +93,89 @@ describe 'Deltacloud API buckets collection' do
     res.code.must_equal 204
   end
 
+  it 'should be possible to create large blob with PUT /api/buckets/:id/blob_id (STREAM)'
do
+    skip "Streaming PUT for blobs not supported by driver #{api.driver} currently running
at #{api.url}" if api.driver == "mock"
+    blob_name = random_name
+    #using @@my_bucket which we know exists
+    res = put("#{BUCKETS}/#{@@my_bucket}/#{blob_name}", large_blob_file,
+           {:content_type=>"image/png", "X-Deltacloud-Blobmeta-Createdfor"=>"putblobtest",
+            "X-Deltacloud-Blobmeta-Author"=>"herpyderp", "X-Deltacloud-Blobmeta-Type"=>"largeblob"})
+    res.code.must_equal 200
+    #GET it
+    res = get(BUCKETS+"/"+@@my_bucket+"/"+blob_name)
+    res.code.must_equal 200
+    #delete it:
+    res = delete("/buckets/#{@@my_bucket}/#{blob_name}")
+    res.code.must_equal 204
+  end
+
+  it 'should be possible to create small blob with PUT /api/buckets/:id/blob_id (NO STREAM)'
do
+    blob_name = random_name
+    #using @@my_bucket which we know exists
+    res = put("#{BUCKETS}/#{@@my_bucket}/#{blob_name}", small_blob_file,
+           {:content_type=>"image/png", "X-Deltacloud-Blobmeta-Createdfor"=>"putblobtest",
+            "X-Deltacloud-Blobmeta-Author"=>"herpyderp", "X-Deltacloud-Blobmeta-Type"=>"smallbob"})
+    res.code.must_equal 200
+    #GET it
+    res = get(BUCKETS+"/"+@@my_bucket+"/"+blob_name)
+    res.code.must_equal 200
+    #delete it:
+    res = delete("/buckets/#{@@my_bucket}/#{blob_name}")
+    res.code.must_equal 204
+  end
+
+  it 'should be possible to create blob with POST /api/buckets/:id' do
+    blob_name = random_name
+    res = post("#{BUCKETS}/#{@@my_bucket}", {:blob_id => blob_name, :blob_data => small_blob_file,
:multipart => true, :meta_params => 2, :meta_name1=>"Author", :meta_value1 =>
"herpyderp", :meta_name2 => "Type", :meta_value2 => "formPostedBlob"})
+    res.code.must_equal 201
+    #GET it
+    res = get(BUCKETS+"/"+@@my_bucket+"/"+blob_name)
+    res.code.must_equal 200
+    #delete it:
+    res = delete("/buckets/#{@@my_bucket}/#{blob_name}")
+    res.code.must_equal 204
+  end
+
+  it 'should be possible to get blob metadata with HEAD /api/buckets/:id/blob_id' do
+    res = head("#{BUCKETS}/#{@@my_bucket}/#{@@my_blob}")
+    res.code.must_equal 204
+    res.headers.keys.must_include :x_deltacloud_blobmeta_version
+    res.headers.keys.must_include :x_deltacloud_blobmeta_author
+  end
+
+  it 'should be possible to update blob metadata with POST /api/buckets/:id/blob' do
+    res = post("#{BUCKETS}/#{@@my_bucket}/#{@@my_blob}", "", {"X-Deltacloud-Blobmeta-Version"=>"2.5",
+               "X-Deltacloud-Blobmeta-Author"=>"derpyherpy", "X-Deltacloud-Blobmeta-Updated"=>"true"})
+    res.code.must_equal 204
+    res.headers.keys.must_include :x_deltacloud_blobmeta_version
+    res.headers.keys.must_include :x_deltacloud_blobmeta_author
+    res.headers.keys.must_include :x_deltacloud_blobmeta_updated
+  end
+
+  it 'should be possible to GET blob data with GET /api/buckets/:id/blob/content' do
+    res = get("#{BUCKETS}/#{@@my_bucket}/#{@@my_blob}/content")
+    res.code.must_equal 200
+    res.must_equal "This is the test blob content"
+  end
+
   describe "with feature bucket_location" do
     need_feature :buckets, :bucket_location
 
     it 'should be possible to specify location for POST /api/buckets if bucket_location feature'
do
       bucket_name = random_name
-      #    res = post({:name=>bucket_name, :bucket_location=>
+      location = api.bucket_locations.choice #random element
+      raise Exception.new("Unable to get location constraint from config.yaml for driver
#{api.driver} - check configuration") unless location
+      res = post(BUCKETS, {:name=>bucket_name, :bucket_location=>location}, {:accept=>:xml})
+      res.code.must_equal 201
+      res.xml.xpath("//bucket/name").text.must_equal bucket_name
+      res.xml.xpath("//bucket").size.must_equal 1
+      res.xml.xpath("//bucket")[0][:id].must_equal bucket_name
+      #GET bucket
+      res = get(BUCKETS+"/"+bucket_name)
+      res.code.must_equal 200
+      #DELETE bucket
+      res = delete(BUCKETS+"/"+bucket_name)
+      res.code.must_equal 204
     end
   end
 

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/99972905/tests/deltacloud/test_blob_large.png
----------------------------------------------------------------------
diff --git a/tests/deltacloud/test_blob_large.png b/tests/deltacloud/test_blob_large.png
new file mode 100644
index 0000000..7fca107
Binary files /dev/null and b/tests/deltacloud/test_blob_large.png differ

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/99972905/tests/deltacloud/test_blob_small.png
----------------------------------------------------------------------
diff --git a/tests/deltacloud/test_blob_small.png b/tests/deltacloud/test_blob_small.png
new file mode 100644
index 0000000..bf1b766
Binary files /dev/null and b/tests/deltacloud/test_blob_small.png differ

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/99972905/tests/deltacloud/test_setup.rb
----------------------------------------------------------------------
diff --git a/tests/deltacloud/test_setup.rb b/tests/deltacloud/test_setup.rb
index 27b1252..a3bae4f 100644
--- a/tests/deltacloud/test_setup.rb
+++ b/tests/deltacloud/test_setup.rb
@@ -60,6 +60,10 @@ module Deltacloud
         "Basic #{Base64.encode64("#{u}:#{p}")}"
       end
 
+      def bucket_locations
+        @hash[driver]["bucket_locations"]
+      end
+
       def driver
         xml.root[:driver]
       end
@@ -124,6 +128,8 @@ module Deltacloud::Test::Methods
     #   :user, :password : use these for the auth header
     #   :accept          : can be :xml or :json, and sets the Accept header
     #   :driver, :provider : set driver and/or provider with the appropriate header
+    #   :content_type    : set content_type for upload (e.g. put blob)
+    #   :x_deltacloud_blobmeta-X : set deltacloud blob metadata
     #
     # If none of the auth relevant params are set, use the username and
     # password for the current driver from the config
@@ -137,6 +143,17 @@ module Deltacloud::Test::Methods
       RestClient.post url, post_body, headers
     end
 
+    def put(path, body, params={})
+      url, headers = process_url_params(path, params)
+      if body.is_a?(File)
+        #set timeouts http://rdoc.info/github/archiloque/rest-client/RestClient/Resource
+        resource = RestClient::Resource.new(url, :open_timeout => 10, :timeout=> 9999)
+        resource.put  body.read, headers
+      else
+        RestClient.put url, body, headers
+      end
+    end
+
     def delete(path, params={})
       url, headers = process_url_params(path, params)
       RestClient.delete url, headers
@@ -147,6 +164,11 @@ module Deltacloud::Test::Methods
       RestClient.options url, headers
     end
 
+    def head(path, params={})
+      url, headers = process_url_params(path, params)
+      RestClient.head url, headers
+    end
+
     def random_name
       name = rand(36**10).to_s(36)
       name.insert(0, "apitest")
@@ -167,9 +189,14 @@ module Deltacloud::Test::Methods
         end
       end
       headers["X-Deltacloud-Driver"] = params.delete(:driver) if params[:driver]
-      headers["X-Deltacloud-Provider"] = params.delete(:provider) if params[:providver]
+      headers["X-Deltacloud-Provider"] = params.delete(:provider) if params[:provider]
       headers["Accept"] = "application/#{params.delete(:accept)}" if params[:accept]
-
+      headers[:content_type] = params.delete(:content_type) if params[:content_type]
+      #grab X-Deltacloud-Blobmeta headers for blob metadata:
+      params.inject({}) do |res, (cur_k, cur_v)|
+        headers[cur_k] = params.delete(cur_k) if cur_k =~ /X-Deltacloud-Blobmeta/i
+        res
+      end
       if path =~ /^https?:/
         url = path
       else


Mime
View raw message