about summary refs log tree commit homepage
path: root/test
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2013-11-04 05:33:31 +0000
committerEric Wong <normalperson@yhbt.net>2013-11-05 21:55:39 +0000
commit52487c2dac216944543a823ac0f921471b685d60 (patch)
tree95eeba1cad0535914c285ffab2b8bc286788572b /test
parent12f8394fc46aecb19616fc54969c7ab87cccd208 (diff)
downloadyahns-52487c2dac216944543a823ac0f921471b685d60.tar.gz
Unlike Rack::Directory, this this also avoids tables and CSS for
preformatted HTML.  This is meant to resemble nginx autoindex
and index functionality (combined).
Diffstat (limited to 'test')
-rw-r--r--test/test_extras_autoindex.rb53
1 files changed, 53 insertions, 0 deletions
diff --git a/test/test_extras_autoindex.rb b/test/test_extras_autoindex.rb
new file mode 100644
index 0000000..ed0e1d5
--- /dev/null
+++ b/test/test_extras_autoindex.rb
@@ -0,0 +1,53 @@
+# Copyright (C) 2013, Eric Wong <normalperson@yhbt.net> and all contributors
+# License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
+require_relative 'server_helper'
+require 'zlib'
+require 'time'
+
+class TestExtrasAutoindex < Testcase
+  ENV["N"].to_i > 1 and parallelize_me!
+  include ServerHelper
+
+  def setup
+    @tmpdir = Dir.mktmpdir
+    server_helper_setup
+  end
+
+  def teardown
+    server_helper_teardown
+    FileUtils.rm_rf @tmpdir
+  end
+
+  def test_autoindex
+    err, cfg, host, port = @err, Yahns::Config.new, @srv.addr[3], @srv.addr[1]
+    tmpdir = @tmpdir
+    pid = mkserver(cfg) do
+      $LOAD_PATH.unshift "#{Dir.pwd}/extras"
+      require 'try_gzip_static'
+      require 'autoindex'
+      cfg.instance_eval do
+        app(:rack, Autoindex.new(TryGzipStatic.new(tmpdir))) do
+          listen "#{host}:#{port}"
+        end
+        stderr_path err.path
+      end
+    end
+
+    Net::HTTP.start(host, port) do |http|
+      res = http.request(Net::HTTP::Get.new("/"))
+      assert_equal 200, res.code.to_i
+      File.open("#@tmpdir/foo", "w").close
+      res = http.request(Net::HTTP::Get.new("/"))
+      assert_equal 200, res.code.to_i
+      assert_match %r{foo}, res.body
+      Dir.mkdir "#@tmpdir/bar"
+
+      res = http.request(Net::HTTP::Get.new("/"))
+      assert_equal 200, res.code.to_i
+      assert_match %r{foo}, res.body
+      assert_match %r{bar/}, res.body
+    end
+  ensure
+    quit_wait pid
+  end
+end