diff --git a/lib/qingstor/sdk/request/preprocessor.rb b/lib/qingstor/sdk/request/preprocessor.rb index d7460cf..97f0cbc 100644 --- a/lib/qingstor/sdk/request/preprocessor.rb +++ b/lib/qingstor/sdk/request/preprocessor.rb @@ -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 diff --git a/lib/qingstor/sdk/service/bucket.rb b/lib/qingstor/sdk/service/bucket.rb index b68f73e..70c9cad 100644 --- a/lib/qingstor/sdk/service/bucket.rb +++ b/lib/qingstor/sdk/service/bucket.rb @@ -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? diff --git a/specs/qingstor b/specs/qingstor index c956b1f..8c87b29 160000 --- a/specs/qingstor +++ b/specs/qingstor @@ -1 +1 @@ -Subproject commit c956b1f69e2b14f859474a462bfed14c10954bc2 +Subproject commit 8c87b291dd8376f914cc2b6a7858b17772a62548 diff --git a/test/bucket_acl.rb b/test/bucket_acl.rb index 95c7989..b6c38fd 100644 --- a/test/bucket_acl.rb +++ b/test/bucket_acl.rb @@ -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 diff --git a/test/bucket_lifecycle.rb b/test/bucket_lifecycle.rb new file mode 100644 index 0000000..0e2c755 --- /dev/null +++ b/test/bucket_lifecycle.rb @@ -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 diff --git a/test/bucket_notification.rb b/test/bucket_notification.rb new file mode 100644 index 0000000..a3ba907 --- /dev/null +++ b/test/bucket_notification.rb @@ -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 diff --git a/test/features b/test/features index e06e815..e96a4a3 160000 --- a/test/features +++ b/test/features @@ -1 +1 @@ -Subproject commit e06e8155b0cfd6e7577dffb56339a298db78bc14 +Subproject commit e96a4a3420be7b47dd60172ecdc1fd40dc20d054 diff --git a/test/object.rb b/test/object.rb index d1e73c7..7e8d757 100644 --- a/test/object.rb +++ b/test/object.rb @@ -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", @@ -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 @@ -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