update unit tests

This commit is contained in:
404
2012-11-06 23:16:40 +08:00
parent bacf83dd3c
commit 000eef8870
9 changed files with 90 additions and 68 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
qiniu-rs (3.1.0)
qiniu-rs (3.1.1)
json (~> 1.7)
mime-types (~> 1.19)
rest-client (~> 1.6)
+12 -7
View File
@@ -1,7 +1,7 @@
# -*- encoding: utf-8 -*-
require 'spec_helper'
require 'qiniu/rs/io'
require 'qiniu/rs'
require 'qiniu/rs/pub'
require 'qiniu/rs/eu'
@@ -14,12 +14,15 @@ module Qiniu
@bucket = "wm_test_bucket"
@key = "image_logo_for_test.png"
result = Qiniu::RS.mkbucket(@bucket)
puts result.inspect
result.should be_true
local_file = File.expand_path('../' + @key, __FILE__)
upopts = {:scope => @bucket, :expires_in => 3600, :customer => @customer_id}
uptoken = Qiniu::RS.generate_upload_token(upopts)
code, data = Qiniu::RS::IO.upload_with_token(uptoken, local_file, @bucket, @key, nil, nil, nil, true)
code.should == 200
data = Qiniu::RS.upload_file :uptoken => uptoken, :file => local_file, :bucket => @bucket, :key => @key
puts data.inspect
code2, data2 = Qiniu::RS::Pub.set_separator(@bucket, "-")
@@ -31,10 +34,12 @@ module Qiniu
puts data3.inspect
end
#after :all do
# result = Qiniu::RS.drop(@bucket)
# result.should_not be_false
#end
after :all do
@bucket = "wm_test_bucket"
result = Qiniu::RS.drop(@bucket)
puts result.inspect
result.should_not be_false
end
context ".set_watermark" do
it "should works" do
+14 -22
View File
@@ -10,35 +10,20 @@ module Qiniu
describe Image do
before :all do
=begin
code, data = Qiniu::RS::Auth.exchange_by_password!("test@qbox.net", "test")
code.should == 200
data.should be_an_instance_of(Hash)
data["access_token"].should_not be_empty
data["refresh_token"].should_not be_empty
data["refresh_token"].should_not be_empty
puts data.inspect
=end
@bucket = "test_images_12345"
@key = "image_logo_for_test.png"
local_file = File.expand_path('../' + @key, __FILE__)
result = Qiniu::RS.drop(@bucket)
result.should_not be_false
result = Qiniu::RS.mkbucket(@bucket)
puts result.inspect
put_url = Qiniu::RS.put_auth(10)
put_url.should_not be_false
put_url.should_not be_empty
result = Qiniu::RS.upload :url => put_url,
:file => local_file,
:bucket => @bucket,
:key => @key,
:enable_crc32_check => true
result.should be_true
local_file = File.expand_path('../' + @key, __FILE__)
upopts = {:scope => @bucket, :expires_in => 3600, :customer => "awhy.xu@gmail.com"}
uptoken = Qiniu::RS.generate_upload_token(upopts)
data = Qiniu::RS.upload_file :uptoken => uptoken, :file => local_file, :bucket => @bucket, :key => @key
puts data.inspect
result = Qiniu::RS.get(@bucket, @key)
result["url"].should_not be_empty
@@ -56,6 +41,13 @@ module Qiniu
}
end
after :all do
@bucket = "test_images_12345"
result = Qiniu::RS.drop(@bucket)
puts result.inspect
result.should_not be_false
end
context ".info" do
it "should works" do
code, data = Qiniu::RS::Image.info(@source_image_url)
+12 -10
View File
@@ -10,17 +10,19 @@ module Qiniu
describe IO do
before :all do
=begin
code, data = Qiniu::RS::Auth.exchange_by_password!("test@qbox.net", "test")
code.should == 200
data.should be_an_instance_of(Hash)
data["access_token"].should_not be_empty
data["refresh_token"].should_not be_empty
data["refresh_token"].should_not be_empty
puts data.inspect
=end
@bucket = "test"
@bucket = "io_test_bucket"
@key = Digest::SHA1.hexdigest (Time.now.to_i+rand(100)).to_s
result = Qiniu::RS.mkbucket(@bucket)
puts result.inspect
result.should be_true
end
after :all do
@bucket = "io_test_bucket"
result = Qiniu::RS.drop(@bucket)
puts result.inspect
result.should_not be_false
end
context ".upload_file" do
+6 -14
View File
@@ -10,24 +10,16 @@ module Qiniu
describe Pub do
before :all do
@bucket = "test123"
code, data = Qiniu::RS::RS.mkbucket(@bucket)
code.should == 200
puts data.inspect
@bucket = "pub_test_bucket"
result = Qiniu::RS.mkbucket(@bucket)
puts result.inspect
result.should_not be_false
end
=begin
context ".mkbucket" do
it "should works" do
code, data = Qiniu::RS::RS.mkbucket(@bucket)
code.should == 200
puts data.inspect
end
end
=end
after :all do
@bucket = "pub_test_bucket"
result = Qiniu::RS.drop(@bucket)
puts result.inspect
result.should_not be_false
end
+10 -4
View File
@@ -11,13 +11,19 @@ module Qiniu
describe RS do
before :all do
@bucket = "test_bucket_1234"
@bucket = "rs_test_bucket"
@key = Digest::SHA1.hexdigest (Time.now.to_i+rand(100)).to_s
@domain = 'iovip.qbox.me/test'
@domain = 'rs-test-bucket.dn.qbox.me'
code, data = Qiniu::RS::RS.mkbucket(@bucket)
puts data.inspect
puts [code, data].inspect
code.should == 200
end
after :all do
@bucket = "rs_test_bucket"
code, data = Qiniu::RS::RS.drop(@bucket)
puts [code, data].inspect
code.should == 200
end
+11 -1
View File
@@ -12,12 +12,22 @@ module Qiniu
before :all do
@localfile = "bigfile.txt"
File.open(@localfile, "w"){|f| 9437184.times{f.write(Random.rand(9).to_s)}}
@bucket = "test"
@bucket = "up_test_bucket"
@key = Digest::SHA1.hexdigest(@localfile+Time.now.to_s)
code, data = Qiniu::RS::RS.mkbucket(@bucket)
puts [code, data].inspect
code.should == 200
end
after :all do
@localfile = "bigfile.txt"
File.unlink(@localfile) if File.exists?(@localfile)
@bucket = "up_test_bucket"
code, data = Qiniu::RS::RS.drop(@bucket)
puts [code, data].inspect
code.should == 200
end
context ".upload_with_token" do
+24 -4
View File
@@ -10,13 +10,33 @@ module Qiniu
before :all do
@bucket = 'qiniu_rs_test'
@key = Digest::SHA1.hexdigest Time.now.to_s
@domain = 'cdn.example.com'
@test_image_bucket = 'test_images_12345'
@test_image_key = 'image_logo_for_test.png'
@domain = 'qiniu-rs-test.dn.qbox.me'
result = Qiniu::RS.mkbucket(@bucket)
result.should_not be_false
@test_image_bucket = 'test_images_12345'
result2 = Qiniu::RS.mkbucket(@test_image_bucket)
puts result2.inspect
result2.should be_true
@test_image_key = 'image_logo_for_test.png'
local_file = File.expand_path('./rs/' + @test_image_key, File.dirname(__FILE__))
puts local_file.inspect
upopts = {:scope => @test_image_bucket, :expires_in => 3600, :customer => "awhy.xu@gmail.com"}
uptoken = Qiniu::RS.generate_upload_token(upopts)
data = Qiniu::RS.upload_file :uptoken => uptoken, :file => local_file, :bucket => @test_image_bucket, :key => @test_image_key
puts data.inspect
end
after :all do
result = Qiniu::RS.drop(@bucket)
puts result.inspect
result.should_not be_false
result2 = Qiniu::RS.drop(@test_image_bucket)
puts result2.inspect
result2.should_not be_false
end
context ".buckets" do
-5
View File
@@ -14,10 +14,5 @@ RSpec.configure do |config|
:up_host => "http://m1.qbox.me:13019",
:pub_host => "http://m1.qbox.me:13012",
:eu_host => "http://m1.qbox.me:13050"
=begin
Qiniu::RS.establish_connection! :access_key => "aPoWOtE9EFca1fLxFCtlkeZAOV7aADVMTLdSydmr",
:secret_key => "L3ShtjCQTCagVCDPfHJoOix7JO_o3qHz3ScyflUG"
=end
end
end