修正上传相关测试用例,建立固定Bucket(用后不删除),避免631响应码问题。

This commit is contained in:
Liang Tao
2014-03-19 11:16:21 +08:00
parent 1a72e1055b
commit 345fafd609
+91 -42
View File
@@ -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