From aa9859e2330ac2b95d6096e61e64fde07e691f6f Mon Sep 17 00:00:00 2001 From: Dan Dorman Date: Tue, 28 Jan 2020 17:15:49 -0700 Subject: [PATCH] Add more `--index-document-path` tests Also tweaks test setup a bit to suppress logging. --- src/http/server.clj | 2 +- test/http/server_test.clj | 22 +++++++++++++++------- test_resources/dir/bar.html | 2 +- test_resources/dir/sub/a.txt | 1 + 4 files changed, 18 insertions(+), 9 deletions(-) create mode 100644 test_resources/dir/sub/a.txt diff --git a/src/http/server.clj b/src/http/server.clj index 1ad5737..0f8ca04 100644 --- a/src/http/server.clj +++ b/src/http/server.clj @@ -344,7 +344,7 @@ ;; we rely on `inject-content-length` being ;; invoked earlier :expressionless: len (get headers "content-length" "-")] - (log/infof "\"%s %s HTTP/1.1\" %s %s" method' uri status len)) + (log/infof "\"%s %s HTTP/1.1\" %s %s" method' uri status len)) response)))) (defn password-prompt! [] diff --git a/test/http/server_test.clj b/test/http/server_test.clj index 6a1f79b..57eaeef 100644 --- a/test/http/server_test.clj +++ b/test/http/server_test.clj @@ -4,6 +4,8 @@ [byte-streams :refer [convert]] [clojure.string :as str] [clojure.test :refer :all] + [clojure.tools.logging :as log] + [clojure.tools.logging.impl :as log-impl] [http.server :as nasus]) (:import [java.io File])) @@ -27,11 +29,12 @@ (-> response :body (convert String))) (defmacro with-nasus [var-name opts & body] - `(let [~var-name (nasus/start (merge {:port 0} ~opts))] - (try - ~@body - (finally - (nasus/stop ~var-name))))) + `(with-redefs [log/*logger-factory* log-impl/disabled-logger-factory] + (let [~var-name (nasus/start (merge {:port 0} ~opts))] + (try + ~@body + (finally + (nasus/stop ~var-name)))))) ;; tests @@ -39,7 +42,7 @@ (with-nasus server {:dir (fs-path (pwd) "test_resources" "dir")} (let [response @(http/get (url server "/"))] (is (= (:status response) 200)) - (is (= (body response) "bar.html\r\nfoo.txt\r\n"))))) + (is (= (body response) "bar.html\r\nfoo.txt\r\nsub\r\n"))))) (deftest html-listing-test (with-nasus server {:dir (fs-path (pwd) "test_resources" "dir")} @@ -53,6 +56,7 @@ \r
\r "))))) @@ -73,4 +77,8 @@ (with-nasus server {:dir (fs-path (pwd) "test_resources" "dir") :index-document-path "bar.html"} (let [response @(http/get (url server "/"))] - (is (= (body response) "\nhello"))))) + (is (= (body response) "\nbar\n") "returns index document")) + (let [response @(http/get (url server "/foo.txt"))] + (is (= (body response) "foo\n") "returns explicit file")) + (let [response @(http/get (url server "/sub/") {:throw-exceptions false})] + (is (= (:status response) 404) "no index doc returns not found")))) diff --git a/test_resources/dir/bar.html b/test_resources/dir/bar.html index f1d2570..5dcc586 100644 --- a/test_resources/dir/bar.html +++ b/test_resources/dir/bar.html @@ -1,2 +1,2 @@ -hello \ No newline at end of file +bar diff --git a/test_resources/dir/sub/a.txt b/test_resources/dir/sub/a.txt new file mode 100644 index 0000000..7898192 --- /dev/null +++ b/test_resources/dir/sub/a.txt @@ -0,0 +1 @@ +a