From 345fafd60970e33a3f2d46d9fc9628c826c320a7 Mon Sep 17 00:00:00 2001 From: Liang Tao Date: Wed, 19 Mar 2014 11:16:21 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B=EF=BC=8C?= =?UTF-8?q?=E5=BB=BA=E7=AB=8B=E5=9B=BA=E5=AE=9ABucket=EF=BC=88=E7=94=A8?= =?UTF-8?q?=E5=90=8E=E4=B8=8D=E5=88=A0=E9=99=A4=EF=BC=89=EF=BC=8C=E9=81=BF?= =?UTF-8?q?=E5=85=8D631=E5=93=8D=E5=BA=94=E7=A0=81=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/qiniu/upload_spec.rb | 133 ++++++++++++++++++++++++++------------ 1 file changed, 91 insertions(+), 42 deletions(-) diff --git a/spec/qiniu/upload_spec.rb b/spec/qiniu/upload_spec.rb index 4739c31..4ed58a2 100755 --- a/spec/qiniu/upload_spec.rb +++ b/spec/qiniu/upload_spec.rb @@ -10,41 +10,41 @@ module Qiniu describe Storage do before :all do - @bucket = 'RubySdkTest' + (Time.now.to_i+rand(1000)).to_s + @bucket = 'RubySDK-Test-Storage' @key = Digest::SHA1.hexdigest((Time.now.to_i+rand(100)).to_s) - @localfile1 = "bigfile.txt" - File.open(@localfile1, "w"){|f| 5242888.times{ f.write(rand(9).to_s) }} - @key1 = Digest::SHA1.hexdigest(@localfile1+Time.now.to_s) + @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) - @localfile2 = "bigfile2.txt" - File.open(@localfile2, "w"){|f| (1 << 22).times{ f.write(rand(9).to_s) }} - @key2 = Digest::SHA1.hexdigest(@localfile2+Time.now.to_s) + @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) - @localfile3 = "bigfile3.txt" - File.open(@localfile3, "w"){|f| (1 << 23).times{ f.write(rand(9).to_s) }} - @key3 = Digest::SHA1.hexdigest(@localfile3+Time.now.to_s) + @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) - @localfile4 = "smallfile.txt" - File.open(@localfile4, "w"){|f| (1 << 20).times{ f.write(rand(9).to_s) }} - @key4 = Digest::SHA1.hexdigest(@localfile4+Time.now.to_s) + @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) + ### 尝试创建Bucket result = Qiniu.mkbucket(@bucket) puts result.inspect - result.should be_true end after :all do - File.unlink(@localfile1) if File.exists?(@localfile1) - File.unlink(@localfile2) if File.exists?(@localfile2) - File.unlink(@localfile3) if File.exists?(@localfile3) - File.unlink(@localfile4) if File.exists?(@localfile4) + ### 清除本地临时文件 + File.unlink(@localfile_5m) if File.exists?(@localfile_5m) + File.unlink(@localfile_4m) if File.exists?(@localfile_4m) + File.unlink(@localfile_8m) if File.exists?(@localfile_8m) + File.unlink(@localfile_1m) if File.exists?(@localfile_1m) - result = Qiniu.drop(@bucket) - puts result.inspect - result.should_not be_false + ### 不删除Bucket以备下次使用 end + ### 测试单文件直传 context ".put_file" do it "should works" do code, data = Qiniu::Storage.put_file(__FILE__, @bucket, @key, 'application/x-ruby', 'customMeta', true) @@ -53,6 +53,22 @@ module Qiniu end end + context ".stat" do + it "should exists" do + code, data = Qiniu::Storage.stat(@bucket, @key) + puts data.inspect + code.should == 200 + end + end + + context ".delete" do + it "should works" do + code, data = Qiniu::Storage.delete(@bucket, @key) + puts data.inspect + code.should == 200 + end + end + context ".upload_with_token" do it "should works" do upopts = {:scope => @bucket, :expires_in => 3600, :customer => "why404@gmail.com"} @@ -63,6 +79,22 @@ module Qiniu end end + context ".stat" do + it "should exists" do + code, data = Qiniu::Storage.stat(@bucket, @key) + puts data.inspect + code.should == 200 + end + end + + context ".delete" do + it "should works" do + code, data = Qiniu::Storage.delete(@bucket, @key) + puts data.inspect + code.should == 200 + end + end + context ".upload_with_token_2" do it "should works" do upopts = {:scope => @bucket, :expires_in => 3600, :endUser => "why404@gmail.com"} @@ -75,19 +107,9 @@ module Qiniu end end # .upload_with_token_2 - context ".resumable_upload_with_token" do - it "should works" do - upopts = {:scope => @bucket, :expires_in => 3600, :customer => "why404@gmail.com"} - uptoken = Qiniu.generate_upload_token(upopts) - code, data = Qiniu::Storage.resumable_upload_with_token(uptoken, @localfile1, @bucket, @key1) - puts data.inspect - (code/100).should == 2 - end - end - context ".stat" do it "should exists" do - code, data = Qiniu::Storage.stat(@bucket, @key1) + code, data = Qiniu::Storage.stat(@bucket, @key) puts data.inspect code.should == 200 end @@ -95,7 +117,34 @@ module Qiniu context ".delete" do it "should works" do - code, data = Qiniu::Storage.delete(@bucket, @key1) + code, data = Qiniu::Storage.delete(@bucket, @key) + puts data.inspect + code.should == 200 + end + end + + ### 测试断点续上传 + context ".resumable_upload_with_token" do + it "should works" do + upopts = {:scope => @bucket, :expires_in => 3600, :customer => "why404@gmail.com"} + uptoken = Qiniu.generate_upload_token(upopts) + code, data = Qiniu::Storage.resumable_upload_with_token(uptoken, @localfile_5m, @bucket, @key_5m) + puts data.inspect + (code/100).should == 2 + end + end + + context ".stat" do + it "should exists" do + code, data = Qiniu::Storage.stat(@bucket, @key_5m) + puts data.inspect + code.should == 200 + end + end + + context ".delete" do + it "should works" do + code, data = Qiniu::Storage.delete(@bucket, @key_5m) puts data.inspect code.should == 200 end @@ -105,7 +154,7 @@ module Qiniu it "should works" do upopts = {:scope => @bucket, :expires_in => 3600, :customer => "why404@gmail.com"} uptoken = Qiniu.generate_upload_token(upopts) - code, data = Qiniu::Storage.resumable_upload_with_token(uptoken, @localfile2, @bucket, @key2) + code, data = Qiniu::Storage.resumable_upload_with_token(uptoken, @localfile_4m, @bucket, @key_4m) puts data.inspect (code/100).should == 2 end @@ -113,7 +162,7 @@ module Qiniu context ".stat" do it "should exists" do - code, data = Qiniu::Storage.stat(@bucket, @key2) + code, data = Qiniu::Storage.stat(@bucket, @key_4m) puts data.inspect code.should == 200 end @@ -121,7 +170,7 @@ module Qiniu context ".delete" do it "should works" do - code, data = Qiniu::Storage.delete(@bucket, @key2) + code, data = Qiniu::Storage.delete(@bucket, @key_4m) puts data.inspect code.should == 200 end @@ -131,7 +180,7 @@ module Qiniu it "should works" do upopts = {:scope => @bucket, :expires_in => 3600, :customer => "why404@gmail.com"} uptoken = Qiniu.generate_upload_token(upopts) - code, data = Qiniu::Storage.resumable_upload_with_token(uptoken, @localfile3, @bucket, @key3) + code, data = Qiniu::Storage.resumable_upload_with_token(uptoken, @localfile_8m, @bucket, @key_8m) puts data.inspect (code/100).should == 2 end @@ -139,7 +188,7 @@ module Qiniu context ".stat" do it "should exists" do - code, data = Qiniu::Storage.stat(@bucket, @key3) + code, data = Qiniu::Storage.stat(@bucket, @key_8m) puts data.inspect code.should == 200 end @@ -147,7 +196,7 @@ module Qiniu context ".delete" do it "should works" do - code, data = Qiniu::Storage.delete(@bucket, @key3) + code, data = Qiniu::Storage.delete(@bucket, @key_8m) puts data.inspect code.should == 200 end @@ -157,7 +206,7 @@ module Qiniu it "should works" do upopts = {:scope => @bucket, :expires_in => 3600, :customer => "why404@gmail.com"} uptoken = Qiniu.generate_upload_token(upopts) - code, data = Qiniu::Storage.resumable_upload_with_token(uptoken, @localfile4, @bucket, @key4) + code, data = Qiniu::Storage.resumable_upload_with_token(uptoken, @localfile_1m, @bucket, @key_1m) puts data.inspect (code/100).should == 2 end @@ -165,7 +214,7 @@ module Qiniu context ".stat" do it "should exists" do - code, data = Qiniu::Storage.stat(@bucket, @key4) + code, data = Qiniu::Storage.stat(@bucket, @key_1m) puts data.inspect code.should == 200 end @@ -173,7 +222,7 @@ module Qiniu context ".delete" do it "should works" do - code, data = Qiniu::Storage.delete(@bucket, @key4) + code, data = Qiniu::Storage.delete(@bucket, @key_1m) puts data.inspect code.should == 200 end From 128e6f0fd72ca93caa827929e344959673ac6983 Mon Sep 17 00:00:00 2001 From: Liang Tao Date: Wed, 19 Mar 2014 13:48:42 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B=EF=BC=8C?= =?UTF-8?q?=E5=BB=BA=E7=AB=8B=E5=9B=BA=E5=AE=9ABucket=EF=BC=88=E7=94=A8?= =?UTF-8?q?=E5=90=8E=E4=B8=8D=E5=88=A0=E9=99=A4=EF=BC=89=EF=BC=8C=E9=81=BF?= =?UTF-8?q?=E5=85=8D631=E5=93=8D=E5=BA=94=E7=A0=81=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/qiniu/management_spec.rb | 51 +++++++---------------------------- spec/qiniu/misc_spec.rb | 9 ++----- 2 files changed, 11 insertions(+), 49 deletions(-) diff --git a/spec/qiniu/management_spec.rb b/spec/qiniu/management_spec.rb index 383c2c8..f624b3a 100755 --- a/spec/qiniu/management_spec.rb +++ b/spec/qiniu/management_spec.rb @@ -11,21 +11,21 @@ module Qiniu describe Storage do before :all do - @bucket = 'RubySdkTest' + (Time.now.to_i+rand(1000)).to_s + @bucket = 'RubySDK-Test-Management' @key = Digest::SHA1.hexdigest((Time.now.to_i+rand(100)).to_s) @key2 = @key + rand(100).to_s + ### 尝试创建Bucket code, data = Storage.mkbucket(@bucket) puts [code, data].inspect code.should == 200 end after :all do - code, data = Storage.drop(@bucket) - puts [code, data].inspect - code.should == 200 + ### 不删除Bucket以备下次使用 end + ### 准备数据 context ".put_file" do it "should works" do code, data = Storage.put_file(__FILE__, @bucket, @key, 'application/x-ruby', 'customMeta', true) @@ -34,6 +34,7 @@ module Qiniu end end + ### 列举Bucket context ".buckets" do it "should works" do code, data = Storage.buckets @@ -52,7 +53,7 @@ module Qiniu context ".get" do it "should works" do - code, data = Storage.get(@bucket, @key, "rs_spec.rb", 1) + code, data = Storage.get(@bucket, @key, "management_spec.rb", 1) code.should == 200 puts data.inspect end @@ -88,10 +89,6 @@ module Qiniu code.should == 200 puts data.inspect - #code2, data2 = Qiniu.stat(@bucket, @key2) - #code2.should == 200 - #puts data2.inspect - code, data = Storage.delete @bucket, @key2 code.should == 200 puts data.inspect @@ -104,34 +101,12 @@ module Qiniu code.should == 200 puts data.inspect - #code2, data2 = Qiniu.stat(@bucket, @key2) - #code2.should == 200 - #puts data2.inspect - code3, data3 = Storage.batch_move @bucket, @key2, @bucket, @key code3.should == 200 puts data3.inspect end end -=begin - context ".publish" do - it "should works" do - code, data = Qiniu.publish(@domain, @bucket) - code.should == 200 - puts data.inspect - end - end - - context ".unpublish" do - it "should works" do - code, data = Qiniu.unpublish(@domain) - code.should == 200 - puts data.inspect - end - end -=end - context ".move" do it "should works" do code, data = Storage.move(@bucket, @key, @bucket, @key2) @@ -154,9 +129,9 @@ module Qiniu code.should == 200 puts data.inspect - #code2, data2 = Qiniu.stat(@bucket, @key2) - #code2.should == 200 - #puts data2.inspect + code, data = Storage.delete(@bucket, @key2) + code.should == 200 + puts data.inspect end end @@ -168,14 +143,6 @@ module Qiniu end end - context ".drop" do - it "should works" do - code, data = Storage.drop(@bucket) - code.should == 200 - puts data.inspect - end - end - end end # module Storage end # module Qiniu diff --git a/spec/qiniu/misc_spec.rb b/spec/qiniu/misc_spec.rb index f9fa2c5..b4f0d35 100755 --- a/spec/qiniu/misc_spec.rb +++ b/spec/qiniu/misc_spec.rb @@ -10,16 +10,11 @@ module Qiniu describe Misc do before :all do - @bucket = 'RubySdkTest' + (Time.now.to_i+rand(1000)).to_s - result = Qiniu.mkbucket(@bucket) - puts result.inspect - result.should_not be_false + ### 复用RubySDK-Test-Management空间 + @bucket = 'RubySDK-Test-Management' end after :all do - result = Qiniu.drop(@bucket) - puts result.inspect - result.should_not be_false end context ".set_protected" do From e97dc07ba3164a936c527994eff9e864d7c52a98 Mon Sep 17 00:00:00 2001 From: Liang Tao Date: Wed, 19 Mar 2014 14:11:10 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=94=A8=E4=BE=8B=EF=BC=8C=E5=BB=BA=E7=AB=8B=E5=9B=BA=E5=AE=9A?= =?UTF-8?q?Bucket=EF=BC=88=E7=94=A8=E5=90=8E=E4=B8=8D=E5=88=A0=E9=99=A4?= =?UTF-8?q?=EF=BC=89=EF=BC=8C=E9=81=BF=E5=85=8D631=E5=93=8D=E5=BA=94?= =?UTF-8?q?=E7=A0=81=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/qiniu/image_spec.rb | 12 ++++++------ spec/qiniu/management_spec.rb | 10 +++++----- spec/qiniu/misc_spec.rb | 4 ++++ spec/qiniu/upload_spec.rb | 9 +++++---- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/spec/qiniu/image_spec.rb b/spec/qiniu/image_spec.rb index 986c9c0..1047ef2 100755 --- a/spec/qiniu/image_spec.rb +++ b/spec/qiniu/image_spec.rb @@ -11,12 +11,14 @@ module Qiniu before :all do - @bucket = 'RubySdkTest' + (Time.now.to_i+rand(1000)).to_s - @key = "image_logo_for_test.png" + ### 复用RubySDK-Test-Storage空间 + @bucket = 'RubySDK-Test-Storage' + ### 尝试创建空间 result = Qiniu.mkbucket(@bucket) puts result.inspect - result.should be_true + + @key = "image_logo_for_test.png" local_file = File.expand_path('../' + @key, __FILE__) @@ -53,9 +55,7 @@ module Qiniu end after :all do - result = Qiniu.drop(@bucket) - puts result.inspect - result.should_not be_false + ### 不删除Bucket以备下次使用 end context ".info" do diff --git a/spec/qiniu/management_spec.rb b/spec/qiniu/management_spec.rb index f624b3a..b780534 100755 --- a/spec/qiniu/management_spec.rb +++ b/spec/qiniu/management_spec.rb @@ -12,13 +12,13 @@ module Qiniu before :all do @bucket = 'RubySDK-Test-Management' - @key = Digest::SHA1.hexdigest((Time.now.to_i+rand(100)).to_s) - @key2 = @key + rand(100).to_s ### 尝试创建Bucket - code, data = Storage.mkbucket(@bucket) - puts [code, data].inspect - code.should == 200 + result = Qiniu.mkbucket(@bucket) + puts result.inspect + + @key = Digest::SHA1.hexdigest((Time.now.to_i+rand(100)).to_s) + @key2 = @key + rand(100).to_s end after :all do diff --git a/spec/qiniu/misc_spec.rb b/spec/qiniu/misc_spec.rb index b4f0d35..e970ce9 100755 --- a/spec/qiniu/misc_spec.rb +++ b/spec/qiniu/misc_spec.rb @@ -12,9 +12,13 @@ module Qiniu before :all do ### 复用RubySDK-Test-Management空间 @bucket = 'RubySDK-Test-Management' + + result = Qiniu.mkbucket(@bucket) + puts result.inspect end after :all do + ### 不删除Bucket以备下次使用 end context ".set_protected" do diff --git a/spec/qiniu/upload_spec.rb b/spec/qiniu/upload_spec.rb index 4ed58a2..bdb1631 100755 --- a/spec/qiniu/upload_spec.rb +++ b/spec/qiniu/upload_spec.rb @@ -11,6 +11,11 @@ module Qiniu before :all do @bucket = 'RubySDK-Test-Storage' + + ### 尝试创建Bucket + result = Qiniu.mkbucket(@bucket) + puts result.inspect + @key = Digest::SHA1.hexdigest((Time.now.to_i+rand(100)).to_s) @localfile_5m = "5M.txt" @@ -28,10 +33,6 @@ module Qiniu @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) - - ### 尝试创建Bucket - result = Qiniu.mkbucket(@bucket) - puts result.inspect end after :all do From 8bd052e3091e4a707cfaaf1cd6fd14d978c8c5dd Mon Sep 17 00:00:00 2001 From: Liang Tao Date: Wed, 19 Mar 2014 14:35:20 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=94=A8=E4=BE=8B=EF=BC=8C=E5=BB=BA=E7=AB=8B=E5=9B=BA=E5=AE=9A?= =?UTF-8?q?Bucket=EF=BC=88=E7=94=A8=E5=90=8E=E4=B8=8D=E5=88=A0=E9=99=A4?= =?UTF-8?q?=EF=BC=89=EF=BC=8C=E9=81=BF=E5=85=8D631=E5=93=8D=E5=BA=94?= =?UTF-8?q?=E7=A0=81=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/qiniu/management_spec.rb | 2 +- spec/qiniu/qiniu_spec.rb | 71 ++++++----------------------------- 2 files changed, 12 insertions(+), 61 deletions(-) diff --git a/spec/qiniu/management_spec.rb b/spec/qiniu/management_spec.rb index b780534..6c32671 100755 --- a/spec/qiniu/management_spec.rb +++ b/spec/qiniu/management_spec.rb @@ -53,7 +53,7 @@ module Qiniu context ".get" do it "should works" do - code, data = Storage.get(@bucket, @key, "management_spec.rb", 1) + code, data = Storage.get(@bucket, @key) code.should == 200 puts data.inspect end diff --git a/spec/qiniu/qiniu_spec.rb b/spec/qiniu/qiniu_spec.rb index 0c266b6..1c62d43 100755 --- a/spec/qiniu/qiniu_spec.rb +++ b/spec/qiniu/qiniu_spec.rb @@ -9,19 +9,17 @@ module Qiniu describe Qiniu do before :all do - @bucket = 'RubySdkTest' + (Time.now.to_i+rand(1000)).to_s + @bucket = 'RubySDK-Test' + @test_image_bucket = @bucket + + ### 尝试创建Bucket + result = Qiniu.mkbucket(@bucket) + puts result.inspect + @key = Digest::SHA1.hexdigest Time.now.to_s @key2 = @key + rand(100).to_s #@domain = @bucket + '.dn.qbox.me' - result = Qiniu.mkbucket(@bucket) - result.should_not be_false - - @test_image_bucket = 'RubySdkTest' + (Time.now.to_i+rand(1000)).to_s - result2 = Qiniu.mkbucket(@test_image_bucket) - puts result2.inspect - result2.should be_true - @test_image_key = 'image_logo_for_test.png' local_file = File.expand_path('./' + @test_image_key, File.dirname(__FILE__)) puts local_file.inspect @@ -32,16 +30,7 @@ module Qiniu end after :all do - #result = Qiniu.unpublish(@domain) - #result.should_not be_false - - result1 = Qiniu.drop(@bucket) - puts result1.inspect - result1.should_not be_false - - result2 = Qiniu.drop(@test_image_bucket) - puts result2.inspect - result2.should_not be_false + ### 不删除Bucket以备下次使用 end context ".put_file" do @@ -180,7 +169,7 @@ module Qiniu context ".get" do it "should works" do - result = Qiniu.get(@bucket, @key, "rs_spec.rb", 10) + result = Qiniu.get(@bucket, @key, "qiniu_spec.rb", 10) result.should_not be_false result.should_not be_empty puts result.inspect @@ -232,24 +221,6 @@ module Qiniu end end -=begin - context ".publish" do - it "should works" do - result = Qiniu.publish(@domain, @bucket) - result.should_not be_false - end - end -=end - -=begin - context ".unpublish" do - it "should works" do - result = Qiniu.unpublish(@domain) - result.should_not be_false - end - end -=end - =begin context ".batch_copy" do it "should works" do @@ -293,8 +264,8 @@ module Qiniu result = Qiniu.copy(@bucket, @key, @bucket, @key2) result.should_not be_false - #result2 = Qiniu.stat(@bucket, @key2) - #result2.should_not be_false + result3 = Qiniu.delete(@bucket, @key2) + result3.should_not be_false end end @@ -305,13 +276,6 @@ module Qiniu end end - context ".drop" do - it "should works" do - result = Qiniu.drop(@bucket) - result.should_not be_false - end - end - context ".image_info" do it "should works" do data = Qiniu.get(@test_image_bucket, @test_image_key) @@ -325,19 +289,6 @@ module Qiniu end end -=begin - context ".image_exif" do - it "should works" do - data = Qiniu.get(@test_image_bucket, @test_image_key) - data.should_not be_false - data.should_not be_empty - puts data.inspect - result = Qiniu.image_exif(data["url"]) - puts result.inspect - end - end -=end - context ".image_mogrify_save_as" do it "should works" do data = Qiniu.get(@test_image_bucket, @test_image_key) From 3cae9276b25b5c2cdf1b0111539de53696e65869 Mon Sep 17 00:00:00 2001 From: Liang Tao Date: Wed, 19 Mar 2014 17:17:32 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E5=9F=BA=E4=BA=8EAK=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E7=94=9F=E6=88=90=E5=85=A8=E7=BD=91=E5=94=AF=E4=B8=80=E7=9A=84?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=94=A8Bucket=EF=BC=8C=E4=BB=A5=E5=8F=8A?= =?UTF-8?q?=E5=9F=BA=E4=BA=8ERuby=E7=89=88=E6=9C=AC=E7=94=9F=E6=88=90?= =?UTF-8?q?=E7=A9=BA=E9=97=B4=E5=86=85=E5=94=AF=E4=B8=80=E7=9A=84=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=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