http_get: fix retries on broken connections
[omgdav.git] / test / test_urlmap.rb
blob5f4af84cefcbe89f026bc5f967bf87717a9e3f77
1 # -*- encoding: binary -*-
2 # Copyright (C) 2012-2017 all contributors <omgdav-public@bogomips.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 require './test/integration'
5 require 'rack/builder'
6 require 'rack/lobster'
8 # ensure everything works when we're using Rack::URLMap with builder
9 class TestUrlmap < Minitest::Test
10   include TestMogileFSIntegration
12   def test_url_map
13     old_app = @app
14     @app = Rack::Builder.new do
15       map "/test" do
16         run old_app
17       end
18       map "http://example.com/test" do
19         run old_app
20       end
21       map "/bogus" do
22         run Rack::Lobster.new
23       end
24     end.to_app
26     assert_equal 201, req("PUT", "/test/foo", input: StringIO.new("H"))[0].to_i
28     assert_equal "foo", @db[:paths].where { self.~(parent_id: 0) }.first[:name]
29     status, headers, body = req("PROPFIND", "/test", "HTTP_DEPTH" => "1")
30     xml = Nokogiri.XML(body)
31     hrefs = xml.search("//D:href").to_a.map { |x| x.text }
32     assert_equal 2, hrefs.size
33     assert hrefs.include?("/test/"), hrefs.inspect
34     assert hrefs.include?("/test/foo"), hrefs.inspect
36     assert_equal 200, req("HEAD", "/test/foo")[0].to_i
38     opts = {
39       "HTTP_DESTINATION" => "http://example.com/test/bar",
40       "HTTP_HOST" => "example.com",
41     }
42     assert_equal 201, req("MOVE", "/test/foo", opts)[0].to_i
43     opts["HTTP_DESTINATION"] = "http://example.com/bar"
44     assert_equal 502, req("MOVE", "/test/bar", opts)[0].to_i
46     opts["HTTP_DESTINATION"] = "http://example.com/test/foo"
47     assert_equal 201, req("COPY", "/test/bar", opts)[0].to_i
49     assert_equal 201, req("MKCOL", "/test/col")[0].to_i
50     opts["HTTP_DESTINATION"] = "http://example.com/test/col/foo"
51     assert_equal 201, req("COPY", "/test/bar", opts)[0].to_i
53     opts["HTTP_DESTINATION"] = "http://example.com/zz"
54     assert_equal 502, req("MOVE", "/test/col/", opts)[0].to_i
56     opts["HTTP_DESTINATION"] = "http://example.com/test/COL"
57     assert_equal 201, req("MOVE", "/test/col/", opts)[0].to_i
58   end
59 end