diff options
Diffstat (limited to 'test/test_fresh.rb')
-rw-r--r-- | test/test_fresh.rb | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/test/test_fresh.rb b/test/test_fresh.rb index f20aacc..369e363 100644 --- a/test/test_fresh.rb +++ b/test/test_fresh.rb @@ -32,4 +32,62 @@ class TestMogFresh < Test::Unit::TestCase client = MogileFS::MogileFS.new :hosts => @hosts, :domain => @domain assert_equal false, client.exist?("non-existent") end + + def test_new_file_info(checksum = nil) + add_host_device_domain unless checksum + @client = MogileFS::MogileFS.new :hosts => @hosts, :domain => @domain + info = {} + opts = { :info => info } + key = "new_file_info" + content = "ZZZZ" + if checksum + opts[:content_md5] = [ Digest::MD5.digest(content) ].pack('m').rstrip + opts[:class] = "check" + end + rv = @client.new_file(key, opts) do |http_file| + http_file << content + end + + uris = info.delete(:uris) + assert_kind_of Array, uris + assert_equal(uris, (@client.get_uris(key) & uris)) + expect_info = @client.file_info(key, :devices => true) + match_keys = %w(class fid key domain length) + match_keys << "checksum" if checksum + match_keys.each do |field| + assert_equal expect_info.delete(field), info.delete(field) + end + assert_operator expect_info.delete("devcount"), :>=, info.delete("devcount") + devids = info.delete("devids") + assert_equal(devids, (expect_info.delete("devids") & devids)) + + assert info.empty?, info.inspect + assert expect_info.empty?, expect_info.inspect + ensure + @client.delete(key) + end + + def test_new_file_info_checksum + add_host_device_domain + opts = @admin.get_domains[@domain]["default"] + opts["hashtype"] = "MD5" + @admin.create_class(@domain, "check", opts) + yield_for_monitor_update do + tmp = @admin.get_domains[@domain]["check"] + if tmp + case tmp["hashtype"] + when "MD5" + break + when nil + warn "skipping checksum test, MogileFS server too old" + return + else + raise "Unhandled hashtype: #{tmp['hashtype']}" + end + end + end + test_new_file_info(:md5) + ensure + @admin.delete_class @domain, "check" + end end |