1 # -*- encoding: binary -*-
5 require "mogstored_rack"
7 class TestUnitMogstoredRack < Test::Unit::TestCase
11 @docroot = Dir.mktmpdir(["mogstored_rack", ".docroot"])
15 req = Rack::MockRequest.new(MogstoredRack.new(@docroot))
20 req = Rack::MockRequest.new(MogstoredRack.new(@docroot, :fsync=>true))
25 assert_equal 200, req.get("/").status # needed to pass "mogadm check"
26 assert ! File.directory?("#@docroot/dev666")
28 r = req.request("PUT", "/dev666/666.fid", :input => StringIO.new("AAAA"))
29 assert_equal 403, r.status
31 assert ! File.directory?("#@docroot/dev666")
33 assert_equal 204, req.request("MKCOL", "/dev666").status
34 assert File.directory?("#@docroot/dev666")
36 io = StringIO.new("HELLO")
37 r = req.request("PUT", "/dev666/666.fid", :input => io)
38 assert_equal 201, r.status
39 assert_equal "HELLO", IO.read("#@docroot/dev666/666.fid")
42 io = StringIO.new("WORLD")
43 md5 = [ Digest::MD5.new.digest ].pack("m").strip!
44 opts = { :input => io, "HTTP_CONTENT_MD5" => md5 }
45 r = req.request("PUT", "/dev666/666.fid", opts)
46 assert_equal 400, r.status
49 io = StringIO.new("VALID")
50 md5 = [ Digest::MD5.digest("VALID") ].pack("m").strip!
51 opts = { :input => io, "HTTP_CONTENT_MD5" => md5 }
52 r = req.request("PUT", "/dev666/666.fid", opts)
53 assert_equal 201, r.status
54 assert_equal "VALID", IO.read("#@docroot/dev666/666.fid")
56 r = req.request("GET", "/dev666/666.fid")
57 assert_equal 200, r.status
58 assert_equal "VALID", r.body
60 r = req.request("DELETE", "/dev666/666.fid")
61 assert_equal 204, r.status
62 assert ! File.exist?("#@docroot/dev666/666.fid")
66 FileUtils.rmtree(@docroot)