Skip to content

Commit

Permalink
test: Add test scenarios (#59)
Browse files Browse the repository at this point in the history
* test: Add test scenarios

* fix put bucket acl cannot blank

* fix blank array compacted

* add delete object with metadata test

* implement scenario test for lifecycle and notification
  • Loading branch information
Prnyself committed Feb 9, 2021
1 parent 8877fc1 commit 6be136f
Show file tree
Hide file tree
Showing 8 changed files with 169 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/qingstor/sdk/request/preprocessor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def self.decorate_input(input)
def self.compact(object)
object.each do |k, v|
object[k] = compact v if v.is_a? Hash
object.delete k if v.nil? || v == '' || v == []
object.delete k if v.nil? || v == ''
end
object
end
Expand Down
4 changes: 0 additions & 4 deletions lib/qingstor/sdk/service/bucket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1059,10 +1059,6 @@ def put_acl_request(acl: [])
def put_bucket_acl_input_validate(input)
input.deep_stringify_keys!

unless !input['request_elements']['acl'].nil? && !input['request_elements']['acl'].empty?
raise ParameterRequiredError.new('acl', 'PutBucketACLInput')
end

input['request_elements']['acl'].each do |x|
unless x['grantee'].nil?

Expand Down
2 changes: 1 addition & 1 deletion specs/qingstor
13 changes: 13 additions & 0 deletions test/bucket_acl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,16 @@
@get_bucket_acl_output[:acl].each { |acl| ok = true if acl[:grantee][:name] == name }
raise unless ok
end

# ----------------------------------------------------------------------------

When(/^put empty bucket ACL$/) do
bucket = @qs_service.bucket @test_config[:bucket_name], @test_config[:zone]
raise if bucket.nil?

@clear_bucket_acl_output = bucket.put_acl acl: []
end

Then(/^put empty bucket ACL status code is (\d+)$/) do |status_code|
raise unless @clear_bucket_acl_output[:status_code].to_s == status_code.to_s
end
61 changes: 61 additions & 0 deletions test/bucket_lifecycle.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# +-------------------------------------------------------------------------
# | Copyright (C) 2016 Yunify, Inc.
# +-------------------------------------------------------------------------
# | Licensed under the Apache License, Version 2.0 (the "License");
# | you may not use this work except in compliance with the License.
# | You may obtain a copy of the License in the LICENSE file, or at:
# |
# | http://www.apache.org/licenses/LICENSE-2.0
# |
# | Unless required by applicable law or agreed to in writing, software
# | distributed under the License is distributed on an "AS IS" BASIS,
# | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# | See the License for the specific language governing permissions and
# | limitations under the License.
# +-------------------------------------------------------------------------

require 'json'

require './qingstor-sdk'

# ----------------------------------------------------------------------------

bucket = nil

When(/^put bucket lifecycle:$/) do |lifecycle_string|
bucket = @qs_service.bucket @test_config[:bucket_name], @test_config[:zone]
raise if bucket.nil?

lifecycle = JSON.parse lifecycle_string
@put_bucket_lifecycle_output = bucket.put_lifecycle rule: lifecycle['rule']
end

Then(/^put bucket lifecycle status code is (\d+)$/) do |status_code|
raise unless @put_bucket_lifecycle_output[:status_code].to_s == status_code.to_s
end

# ----------------------------------------------------------------------------

When(/^get bucket lifecycle$/) do
@get_bucket_lifecycle_output = bucket.get_lifecycle
end

Then(/^get bucket lifecycle status code is (\d+)$/) do |status_code|
raise unless @get_bucket_lifecycle_output[:status_code].to_s == status_code.to_s
end

Then(/^get bucket lifecycle should have filter prefix "(.*)"$/) do |name|
ok = false
@get_bucket_lifecycle_output[:rule].each { |rule| ok = true if rule[:filter][:prefix] == name }
raise unless ok
end

# ----------------------------------------------------------------------------

When(/^delete bucket lifecycle$/) do
@delete_bucket_lifecycle_output = bucket.delete_lifecycle
end

Then(/^delete bucket lifecycle status code is (\d+)$/) do |status_code|
raise unless @delete_bucket_lifecycle_output[:status_code].to_s == status_code.to_s
end
61 changes: 61 additions & 0 deletions test/bucket_notification.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# +-------------------------------------------------------------------------
# | Copyright (C) 2016 Yunify, Inc.
# +-------------------------------------------------------------------------
# | Licensed under the Apache License, Version 2.0 (the "License");
# | you may not use this work except in compliance with the License.
# | You may obtain a copy of the License in the LICENSE file, or at:
# |
# | http://www.apache.org/licenses/LICENSE-2.0
# |
# | Unless required by applicable law or agreed to in writing, software
# | distributed under the License is distributed on an "AS IS" BASIS,
# | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# | See the License for the specific language governing permissions and
# | limitations under the License.
# +-------------------------------------------------------------------------

require 'json'

require './qingstor-sdk'

# ----------------------------------------------------------------------------

bucket = nil

When(/^put bucket notification:$/) do |notification_string|
bucket = @qs_service.bucket @test_config[:bucket_name], @test_config[:zone]
raise if bucket.nil?

notify = JSON.parse notification_string
@put_bucket_notification_output = bucket.put_notification notifications: notify['notifications']
end

Then(/^put bucket notification status code is (\d+)$/) do |status_code|
raise unless @put_bucket_notification_output[:status_code].to_s == status_code.to_s
end

# ----------------------------------------------------------------------------

When(/^get bucket notification$/) do
@get_bucket_notification_output = bucket.get_notification
end

Then(/^get bucket notification status code is (\d+)$/) do |status_code|
raise unless @get_bucket_notification_output[:status_code].to_s == status_code.to_s
end

Then(/^get bucket notification should have cloudfunc "(.*)"$/) do |name|
ok = false
@get_bucket_notification_output[:notifications].each { |notify| ok = true if notify[:cloudfunc] == name }
raise unless ok
end

# ----------------------------------------------------------------------------

When(/^delete bucket notification$/) do
@delete_bucket_notification_output = bucket.delete_notification
end

Then(/^delete bucket notification status code is (\d+)$/) do |status_code|
raise unless @delete_bucket_notification_output[:status_code].to_s == status_code.to_s
end
2 changes: 1 addition & 1 deletion test/features
31 changes: 31 additions & 0 deletions test/object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@
raise unless @put_object_output[:status_code].to_s == status_code.to_s
end

When(/^put object "(.+)" with metadata "(.+)":"(.+)", "(.+)":"(.+)"$/) do |object_key, k1, v1, k2, v2|
system 'dd if=/dev/zero of=/tmp/sdk_bin bs=1024 count=1'
@put_object_metadata_output = bucket.put_object(
"#{object_key}_meta",
x_qs_meta_data: {"#{k1}": v1, "#{k2}": v2},
body: File.open('/tmp/sdk_bin'),
)
system 'rm -f /tmp/sdk_bin'
end

Then(/^put object with metadata status code is (\d+)$/) do |status_code|
raise unless @put_object_metadata_output[:status_code].to_s == status_code.to_s
end

When(/^copy object with key "(.+)"$/) do |object_key|
@put_the_copy_object_output = bucket.put_object(
"#{object_key}_copy",
Expand Down Expand Up @@ -76,6 +90,15 @@
raise unless (@get_object_output[:body].length * 1024).to_s == length.to_s
end

When(/^get object "(.+)" and check metadata$/) do |object_key|
@get_object_meta_output = bucket.get_object "#{object_key}_meta"
end

Then(/^get object metadata is "(.+)":"(.+)", "(.+)":"(.+)"$/) do |k1, v1, k2, v2|
raise unless @get_object_meta_output[:"x_qs_meta_#{k1}"].to_s == v1
raise unless @get_object_meta_output[:"x_qs_meta_#{k2}"].to_s == v2
end

When(/^get object "(.+)" with content type "([^"]*)"$/) do |object_key, content_type|
@get_object_output = bucket.get_object object_key,
response_content_type: content_type
Expand Down Expand Up @@ -138,3 +161,11 @@
Then(/^delete the move object status code is (\d+)$/) do |status_code|
raise unless @delete_the_move_object_output[:status_code].to_s == status_code.to_s
end

When(/^delete object with metadata and "(.*)"$/) do |object_key|
@delete_obj_with_meta_output = bucket.delete_object "#{object_key}_meta"
end

Then(/^delete object with metadata status code is (\d+)$/) do |status_code|
raise unless @delete_obj_with_meta_output[:status_code].to_s == status_code.to_s
end

0 comments on commit 6be136f

Please sign in to comment.