You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by ma...@redhat.com on 2010/10/04 17:01:42 UTC
Cucumber features/steps for buckets - mock driver
This patch adds some cucumber features and steps for the mock driver. You will need to have a fairly recent version of core (with the blobstore stuff in the mock driver and corresponding yaml) to try it out. After applying the patch you can try: (note - from directory /deltacloud/server) 'cucumber ../tests/mock/buckets.feature'
marios
[PATCH] Adds Cucumber features and steps for buckets - mock driver
Posted by ma...@redhat.com.
From: marios <ma...@redhat.com>
---
tests/mock/buckets.feature | 64 ++++++++++++++++++++++++++
tests/mock/step_definitions/buckets_steps.rb | 52 +++++++++++++++++++++
tests/mock/step_definitions/images_steps.rb | 2 +
3 files changed, 118 insertions(+), 0 deletions(-)
create mode 100644 tests/mock/buckets.feature
create mode 100644 tests/mock/step_definitions/buckets_steps.rb
diff --git a/tests/mock/buckets.feature b/tests/mock/buckets.feature
new file mode 100644
index 0000000..855c563
--- /dev/null
+++ b/tests/mock/buckets.feature
@@ -0,0 +1,64 @@
+Feature: Listing and showing buckets
+
+ Scenario: Listing buckets when none exist
+ Given URI /api/buckets exists
+ And authentification is required for this URI
+ When client access this URI
+ Then client should get root element 'buckets'
+
+ Scenario: Listing current buckets
+ Given URI /api/buckets exists
+ And authentification is required for this URI
+ When client access this URI
+ Then client should get root element 'buckets'
+ And each bucket should have at least:
+ | name |
+ | size |
+ And each bucket should have 'href' attribute with valid URI
+ And this URI should be available in XML, JSON, HTML format
+
+ Scenario: Get details about (show) the first bucket
+ Given URI /api/buckets exists
+ And authentification is required for this URI
+ When client access this URI
+ Then client should get root element 'buckets'
+ And this element contains some buckets
+ When client want to show first bucket
+ Then client follow href attribute in first bucket
+ Then client should get this bucket
+ And this bucket should have at least:
+ | name |
+ | size |
+
+ Scenario: Create a new bucket
+ Given URI /api/buckets exists
+ And authentification is required for this URI
+ When client want to create a new bucket
+ Then client should choose name 'deltacloudtestbucket1'
+ When client request for a new bucket
+ Then new bucket should be created
+
+ Scenario: Create bucket using HTML form
+ Given URI /api/buckets/new exists in HTML format
+ And authentification is required for this URI
+ When client access this URI
+ Then client should get HTML form
+
+
+ Scenario: Delete an empty bucket
+ Given URI /api/buckets exists
+ And authentification is required for this URI
+ When client deletes bucket with name 'deltacloudtestbucket1'
+ Then this bucket should be destroyed
+
+
+ Scenario: Delete a non-empty bucket
+ Given URI /api/buckets exists
+ And authentification is required for this URI
+ When client deletes bucket with name 'bucket1'
+ Then this will cause a 'bucket-not-empty' error
+
+ Scenario: Get a blob in a bucket
+ Given URI /api/buckets exists
+ And authentification is required for this URI
+ Then client can request blob with name 'blob1' in bucket 'bucket1' without error
diff --git a/tests/mock/step_definitions/buckets_steps.rb b/tests/mock/step_definitions/buckets_steps.rb
new file mode 100644
index 0000000..741bdda
--- /dev/null
+++ b/tests/mock/step_definitions/buckets_steps.rb
@@ -0,0 +1,52 @@
+Then /^each ([\w\-]+) should have at least:$/ do |item, table|
+ properties = table.raw.flatten.sort
+ output_xml.xpath("/#{@last_element.name}/#{item}").each do |element|
+ childrens = (element > '*').collect { |c| c.name }
+ childrens.sort.include?(properties)
+ end
+end
+
+Then /^this ([\w\-]+) should have at least:$/ do |item, table|
+ properties = table.raw.flatten.sort
+ output_xml.xpath("/#{@last_element.name}/#{item}").each do |element|
+ childrens = (element > '*').collect { |c| c.name }
+ childrens.sort.include?(properties)
+ end
+end
+
+When /^client want to create a new bucket$/ do
+end
+
+Then /^client should choose name '(\w+)'$/ do |name|
+ @name = name
+end
+
+When /^client request for a new bucket$/ do
+ params = {:name => @name}
+ post "/api/buckets", params
+end
+
+Then /^new bucket should be created$/ do
+ output_xml.xpath('/bucket').size.should == 1
+end
+
+When /^client deletes bucket with name '(\w+)'$/ do |id|
+ @id = id
+ delete "/api/buckets/#{@id}", {}
+end
+
+Then /^this bucket should be destroyed$/ do
+ get "/api/buckets/#{@id}", {}
+ last_response.status.should_not == 200
+end
+
+
+Then /^this will cause a 'bucket\-not\-empty' error$/ do
+ delete "/api/buckets/#{@id}", {}
+ last_response.errors.match(/^Deltacloud::BackendError: bucket-not-empty/).should_not == nil
+end
+
+Then /^client can request blob with name '(\w+)' in bucket '(\w+)' without error$/ do |blob, bucket|
+ result = get "/api/buckets/#{bucket}/#{blob}"
+ result.status.should == 200
+end
diff --git a/tests/mock/step_definitions/images_steps.rb b/tests/mock/step_definitions/images_steps.rb
index 323778c..36f1525 100644
--- a/tests/mock/step_definitions/images_steps.rb
+++ b/tests/mock/step_definitions/images_steps.rb
@@ -39,6 +39,8 @@ When /^client want to show first (.+)$/ do |element|
path = '/storage_volumes/storage_volume'
when 'storage_snapshot':
path = '/storage_snapshots/storage_snapshot'
+ when 'bucket':
+ path = '/buckets/bucket'
end
@element = output_xml.xpath(path).first
@element.should_not be_nil
--
1.7.2.3