From 3cae9276b25b5c2cdf1b0111539de53696e65869 Mon Sep 17 00:00:00 2001 From: Liang Tao Date: Wed, 19 Mar 2014 17:17:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=BA=E4=BA=8EAK=E4=BF=A1=E6=81=AF=E7=94=9F?= =?UTF-8?q?=E6=88=90=E5=85=A8=E7=BD=91=E5=94=AF=E4=B8=80=E7=9A=84=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E7=94=A8Bucket=EF=BC=8C=E4=BB=A5=E5=8F=8A=E5=9F=BA?= =?UTF-8?q?=E4=BA=8ERuby=E7=89=88=E6=9C=AC=E7=94=9F=E6=88=90=E7=A9=BA?= =?UTF-8?q?=E9=97=B4=E5=86=85=E5=94=AF=E4=B8=80=E7=9A=84=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=94=A8Key=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/qiniu/image_spec.rb | 6 ++++-- spec/qiniu/management_spec.rb | 3 +++ spec/qiniu/misc_spec.rb | 1 + spec/qiniu/qiniu_spec.rb | 4 ++++ spec/qiniu/upload_spec.rb | 6 ++++++ spec/spec_helper.rb | 8 ++++++++ 6 files changed, 26 insertions(+), 2 deletions(-) diff --git a/spec/qiniu/image_spec.rb b/spec/qiniu/image_spec.rb index 1047ef2..b6d054a 100755 --- a/spec/qiniu/image_spec.rb +++ b/spec/qiniu/image_spec.rb @@ -13,14 +13,16 @@ module Qiniu ### 复用RubySDK-Test-Storage空间 @bucket = 'RubySDK-Test-Storage' + @bucket = make_unique_bucket(@bucket) ### 尝试创建空间 result = Qiniu.mkbucket(@bucket) puts result.inspect - @key = "image_logo_for_test.png" + pic_fname = "image_logo_for_test.png" + @key = make_unique_key_in_bucket(pic_fname) - local_file = File.expand_path('../' + @key, __FILE__) + local_file = File.expand_path('../' + pic_fname, __FILE__) upopts = { :scope => @bucket, diff --git a/spec/qiniu/management_spec.rb b/spec/qiniu/management_spec.rb index 6c32671..34ab775 100755 --- a/spec/qiniu/management_spec.rb +++ b/spec/qiniu/management_spec.rb @@ -12,12 +12,15 @@ module Qiniu before :all do @bucket = 'RubySDK-Test-Management' + @bucket = make_unique_bucket(@bucket) ### 尝试创建Bucket result = Qiniu.mkbucket(@bucket) puts result.inspect @key = Digest::SHA1.hexdigest((Time.now.to_i+rand(100)).to_s) + @key = make_unique_key_in_bucket(@key) + @key2 = @key + rand(100).to_s end diff --git a/spec/qiniu/misc_spec.rb b/spec/qiniu/misc_spec.rb index e970ce9..c49f818 100755 --- a/spec/qiniu/misc_spec.rb +++ b/spec/qiniu/misc_spec.rb @@ -12,6 +12,7 @@ module Qiniu before :all do ### 复用RubySDK-Test-Management空间 @bucket = 'RubySDK-Test-Management' + @bucket = make_unique_bucket(@bucket) result = Qiniu.mkbucket(@bucket) puts result.inspect diff --git a/spec/qiniu/qiniu_spec.rb b/spec/qiniu/qiniu_spec.rb index 1c62d43..86a014e 100755 --- a/spec/qiniu/qiniu_spec.rb +++ b/spec/qiniu/qiniu_spec.rb @@ -10,6 +10,8 @@ module Qiniu before :all do @bucket = 'RubySDK-Test' + @bucket = make_unique_bucket(@bucket) + @test_image_bucket = @bucket ### 尝试创建Bucket @@ -17,6 +19,8 @@ module Qiniu puts result.inspect @key = Digest::SHA1.hexdigest Time.now.to_s + @key = make_unique_key_in_bucket(@key) + @key2 = @key + rand(100).to_s #@domain = @bucket + '.dn.qbox.me' diff --git a/spec/qiniu/upload_spec.rb b/spec/qiniu/upload_spec.rb index bdb1631..895d54a 100755 --- a/spec/qiniu/upload_spec.rb +++ b/spec/qiniu/upload_spec.rb @@ -11,28 +11,34 @@ module Qiniu before :all do @bucket = 'RubySDK-Test-Storage' + @bucket = make_unique_bucket(@bucket) ### 尝试创建Bucket result = Qiniu.mkbucket(@bucket) puts result.inspect @key = Digest::SHA1.hexdigest((Time.now.to_i+rand(100)).to_s) + @key = make_unique_key_in_bucket(@key) @localfile_5m = "5M.txt" File.open(@localfile_5m, "w"){|f| 5242888.times{ f.write(rand(9).to_s) }} @key_5m = Digest::SHA1.hexdigest(@localfile_5m+Time.now.to_s) + @key_5m = make_unique_key_in_bucket(@key_5m) @localfile_4m = "4M.txt" File.open(@localfile_4m, "w"){|f| (1 << 22).times{ f.write(rand(9).to_s) }} @key_4m = Digest::SHA1.hexdigest(@localfile_4m+Time.now.to_s) + @key_4m = make_unique_key_in_bucket(@key_4m) @localfile_8m = "8M.txt" File.open(@localfile_8m, "w"){|f| (1 << 23).times{ f.write(rand(9).to_s) }} @key_8m = Digest::SHA1.hexdigest(@localfile_8m+Time.now.to_s) + @key_8m = make_unique_key_in_bucket(@key_8m) @localfile_1m = "1M.txt" File.open(@localfile_1m, "w"){|f| (1 << 20).times{ f.write(rand(9).to_s) }} @key_1m = Digest::SHA1.hexdigest(@localfile_1m+Time.now.to_s) + @key_1m = make_unique_key_in_bucket(@key_1m) end after :all do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e695e04..b5ec3ee 100755 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -9,3 +9,11 @@ RSpec.configure do |config| Qiniu.establish_connection! :access_key => ENV["QINIU_ACCESS_KEY"], :secret_key => ENV["QINIU_SECRET_KEY"] end end + +def make_unique_bucket (bucket) + bucket + "-" + ENV["QINIU_ACCESS_KEY"][0, 8] +end # make_unique_bucket + +def make_unique_key_in_bucket (key) + "#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}-" + key +end # make_unique_key_in_bucket