From a29cfe5a7132b8aa07149ed9ca7b0f8a185938e7 Mon Sep 17 00:00:00 2001 From: longbai Date: Thu, 24 Jul 2014 14:38:59 +0800 Subject: [PATCH] update test --- .travis.yml | 4 ++-- lib/qiniu/management.rb | 25 ++----------------------- spec/qiniu/auth_spec.rb | 11 ++--------- spec/qiniu/image_spec.rb | 11 +---------- spec/qiniu/management_spec.rb | 8 +------- spec/qiniu/misc_spec.rb | 8 +------- spec/qiniu/pfop_spec.rb | 11 +---------- spec/qiniu/qiniu_spec.rb | 8 +------- spec/qiniu/upload_spec.rb | 9 +-------- spec/qiniu/utils_spec.rb | 8 ++++---- 10 files changed, 16 insertions(+), 87 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7a22ba1..06fa124 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,5 +5,5 @@ rvm: - 2.1.1 - jruby-19mode before_script: - - export QINIU_ACCESS_KEY=LGRqJsjX7LAvtdtX6hhyxs861lS57HwnOQmJsOuX - - export QINIU_SECRET_KEY=g_OxhuN5iJ1O7BoA6YdXyF6zSszk34UZFKDfdIIW + - export QINIU_ACCESS_KEY=QWYn5TFQsLLU1pL5MFEmX3s5DmHdUThav9WyOWOm + - export QINIU_SECRET_KEY=Bxckh6FA-Fbs9Yt3i3cbKVK22UPBmAOHJcL95pGz diff --git a/lib/qiniu/management.rb b/lib/qiniu/management.rb index 300372b..b115817 100755 --- a/lib/qiniu/management.rb +++ b/lib/qiniu/management.rb @@ -14,22 +14,6 @@ module Qiniu return HTTP.management_post(url) end # buckets - PRIVATE_BUCKET = 0 - PUBLIC_BUCKET = 1 - - def mkbucket(bucket_name, is_public = PUBLIC_BUCKET) - url = Config.settings[:rs_host] + '/mkbucket2/' + bucket_name + '/public/' + is_public.to_s - return HTTP.management_post(url) - end # mkbucket - - def make_a_private_bucket(bucket_name) - return mkbucket(bucket_name, PRIVATE_BUCKET) - end # make_a_private_bucket - - def make_a_public_bucket(bucket_name) - return mkbucket(bucket_name, PUBLIC_BUCKET) - end # make_a_public_bucket - def stat(bucket, key) url = Config.settings[:rs_host] + '/stat/' + encode_entry_uri(bucket, key) return HTTP.management_post(url) @@ -60,11 +44,6 @@ module Qiniu return HTTP.management_post(url) end # delete - def drop(bucket) - url = Config.settings[:rs_host] + "/drop/#{bucket}" - return HTTP.management_post(url) - end # drop - def batch(command, bucket, keys) execs = [] keys.each do |key| @@ -117,9 +96,9 @@ module Qiniu def _batch_cp_or_mv(command, *op_args) execs = [] - op_args.each do |e| + op_args.each do |e| execs << 'op=' + _generate_cp_or_mv_opstr(command, e[0], e[1], e[2], e[3]) if e.size == 4 - end + end url = Config.settings[:rs_host] + "/batch" return HTTP.management_post(url, execs.join("&")) end # _batch_cp_or_mv diff --git a/spec/qiniu/auth_spec.rb b/spec/qiniu/auth_spec.rb index c8a7a81..5648846 100755 --- a/spec/qiniu/auth_spec.rb +++ b/spec/qiniu/auth_spec.rb @@ -7,20 +7,13 @@ require 'qiniu/storage' require 'digest/sha1' module Qiniu - module Auth + module Auth describe Auth do before :all do - @bucket = 'RubySDK-Test-Private' - @bucket = make_unique_bucket(@bucket) - - ### 尝试创建Bucket - result = Qiniu::Storage.make_a_private_bucket(@bucket) - puts result.inspect + @bucket = 'rubysdk' end - after :all do - ### 不删除Bucket以备下次使用 end ### 测试私有资源下载 diff --git a/spec/qiniu/image_spec.rb b/spec/qiniu/image_spec.rb index b6d054a..0002326 100755 --- a/spec/qiniu/image_spec.rb +++ b/spec/qiniu/image_spec.rb @@ -10,15 +10,7 @@ module Qiniu describe Fop do before :all do - - ### 复用RubySDK-Test-Storage空间 - @bucket = 'RubySDK-Test-Storage' - @bucket = make_unique_bucket(@bucket) - - ### 尝试创建空间 - result = Qiniu.mkbucket(@bucket) - puts result.inspect - + @bucket = 'rubysdk' pic_fname = "image_logo_for_test.png" @key = make_unique_key_in_bucket(pic_fname) @@ -57,7 +49,6 @@ module Qiniu end after :all do - ### 不删除Bucket以备下次使用 end context ".info" do diff --git a/spec/qiniu/management_spec.rb b/spec/qiniu/management_spec.rb index abd1fff..86191c6 100755 --- a/spec/qiniu/management_spec.rb +++ b/spec/qiniu/management_spec.rb @@ -12,12 +12,7 @@ module Qiniu describe Storage do before :all do - @bucket = 'RubySDK-Test-Management' - @bucket = make_unique_bucket(@bucket) - - ### 尝试创建Bucket - result = Qiniu.mkbucket(@bucket) - puts result.inspect + @bucket = 'rubysdk' @key = Digest::SHA1.hexdigest((Time.now.to_i+rand(100)).to_s) @key = make_unique_key_in_bucket(@key) @@ -26,7 +21,6 @@ module Qiniu end after :all do - ### 不删除Bucket以备下次使用 end ### 准备数据 diff --git a/spec/qiniu/misc_spec.rb b/spec/qiniu/misc_spec.rb index c49f818..ae70763 100755 --- a/spec/qiniu/misc_spec.rb +++ b/spec/qiniu/misc_spec.rb @@ -10,16 +10,10 @@ module Qiniu describe Misc do before :all do - ### 复用RubySDK-Test-Management空间 - @bucket = 'RubySDK-Test-Management' - @bucket = make_unique_bucket(@bucket) - - result = Qiniu.mkbucket(@bucket) - puts result.inspect + @bucket = 'rubysdk' end after :all do - ### 不删除Bucket以备下次使用 end context ".set_protected" do diff --git a/spec/qiniu/pfop_spec.rb b/spec/qiniu/pfop_spec.rb index fb509a7..920915b 100644 --- a/spec/qiniu/pfop_spec.rb +++ b/spec/qiniu/pfop_spec.rb @@ -12,15 +12,7 @@ module Qiniu describe Persistance do before :all do - ### 复用RubySDK-Test-Storage空间 - @bucket = 'RubySDK-Test-Storage' - @bucket = make_unique_bucket(@bucket) - - ### 尝试创建空间 - code, data, headers = Qiniu::Storage.make_a_public_bucket(@bucket) - puts code.inspect - puts data.inspect - puts headers.inspect + @bucket = 'rubysdk' pic_fname = "image_logo_for_test.png" @key = make_unique_key_in_bucket(pic_fname) @@ -44,7 +36,6 @@ module Qiniu end after :all do - ### 不删除Bucket以备下次使用 end context ".pfop" do diff --git a/spec/qiniu/qiniu_spec.rb b/spec/qiniu/qiniu_spec.rb index 1136432..6f3bdbc 100755 --- a/spec/qiniu/qiniu_spec.rb +++ b/spec/qiniu/qiniu_spec.rb @@ -9,15 +9,10 @@ module Qiniu describe Qiniu do before :all do - @bucket = 'RubySDK-Test' - @bucket = make_unique_bucket(@bucket) + @bucket = 'rubysdk' @test_image_bucket = @bucket - ### 尝试创建Bucket - result = Qiniu.mkbucket(@bucket) - puts result.inspect - @key = Digest::SHA1.hexdigest Time.now.to_s @key = make_unique_key_in_bucket(@key) @@ -34,7 +29,6 @@ module Qiniu end after :all do - ### 不删除Bucket以备下次使用 end context ".buckets" do diff --git a/spec/qiniu/upload_spec.rb b/spec/qiniu/upload_spec.rb index f345c8e..7259652 100755 --- a/spec/qiniu/upload_spec.rb +++ b/spec/qiniu/upload_spec.rb @@ -11,12 +11,7 @@ module Qiniu describe Storage do before :all do - @bucket = 'RubySDK-Test-Storage' - @bucket = make_unique_bucket(@bucket) - - ### 尝试创建Bucket - result = Qiniu.mkbucket(@bucket) - puts result.inspect + @bucket = 'rubysdk' @key = Digest::SHA1.hexdigest((Time.now.to_i+rand(100)).to_s) @key = make_unique_key_in_bucket(@key) @@ -53,8 +48,6 @@ module Qiniu 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) - - ### 不删除Bucket以备下次使用 end ### 测试单文件直传 diff --git a/spec/qiniu/utils_spec.rb b/spec/qiniu/utils_spec.rb index 5ef8625..104b4c9 100755 --- a/spec/qiniu/utils_spec.rb +++ b/spec/qiniu/utils_spec.rb @@ -26,8 +26,8 @@ module Qiniu context ".send_request_with" do it "should works" do FakeWeb.allow_net_connect = false - FakeWeb.register_uri(:get, "http://docs.qiniutek.com/", :body => {:abc => 123}.to_json) - res = Utils.send_request_with 'http://docs.qiniutek.com/', nil, :method => :get + FakeWeb.register_uri(:get, "http://develoepr.qiniu.com/", :body => {:abc => 123}.to_json) + res = Utils.send_request_with 'http://develoepr.qiniu.com/', nil, :method => :get res.should == [200, {"abc" => 123}, {}] end @@ -35,9 +35,9 @@ module Qiniu context "upstream return http #{code}" do it "should raise RestClient::RequestFailed" do FakeWeb.allow_net_connect = false - FakeWeb.register_uri(:get, "http://docs.qiniutek.com/", :status => code) + FakeWeb.register_uri(:get, "http://develoepr.qiniu.com/", :status => code) lambda { - res = Utils.send_request_with 'http://docs.qiniutek.com/', nil, :method => :get + res = Utils.send_request_with 'http://develoepr.qiniu.com/', nil, :method => :get }.should raise_error RestClient::RequestFailed end end