Move module tests
Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-httpd/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-httpd/commit/32aac3ab Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-httpd/tree/32aac3ab Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-httpd/diff/32aac3ab Branch: refs/heads/split_out_httpd_stack Commit: 32aac3ab82a2ae3ab33e25e640f3407570bc3d59 Parents: 7f7ff5a Author: ILYA Khlopotov <iil...@ca.ibm.com> Authored: Fri Feb 26 10:15:34 2016 -0800 Committer: ILYA Khlopotov <iil...@ca.ibm.com> Committed: Tue Mar 1 08:35:08 2016 -0800 ---------------------------------------------------------------------- src/couch_httpd.erl | 41 +++++++++++++++++++++++++++++++++ src/couch_httpd_original.erl | 48 --------------------------------------- 2 files changed, 41 insertions(+), 48 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-couch-httpd/blob/32aac3ab/src/couch_httpd.erl ---------------------------------------------------------------------- diff --git a/src/couch_httpd.erl b/src/couch_httpd.erl index 321fbd3..a5df293 100644 --- a/src/couch_httpd.erl +++ b/src/couch_httpd.erl @@ -953,3 +953,44 @@ validate_callback([Char | Rest]) -> throw({bad_request, invalid_callback}) end, validate_callback(Rest). + +%%%%%%%% module tests below %%%%%%%% + +-ifdef(TEST). +-include_lib("couch/include/couch_eunit.hrl"). + +maybe_add_default_headers_test_() -> + DummyRequest = [], + NoCache = {"Cache-Control", "no-cache"}, + ApplicationJson = {"Content-Type", "application/json"}, + % couch_httpd uses process dictionary to check if currently in a + % json serving method. Defaults to 'application/javascript' otherwise. + % Therefore must-revalidate and application/javascript should be added + % by couch_httpd if such headers are not present + MustRevalidate = {"Cache-Control", "must-revalidate"}, + ApplicationJavascript = {"Content-Type", "application/javascript"}, + Cases = [ + {[], + [MustRevalidate, ApplicationJavascript], + "Should add Content-Type and Cache-Control to empty heaeders"}, + + {[NoCache], + [NoCache, ApplicationJavascript], + "Should add Content-Type only if Cache-Control is present"}, + + {[ApplicationJson], + [MustRevalidate, ApplicationJson], + "Should add Cache-Control if Content-Type is present"}, + + {[NoCache, ApplicationJson], + [NoCache, ApplicationJson], + "Should not add headers if Cache-Control and Content-Type are there"} + ], + Tests = lists:map(fun({InitialHeaders, ProperResult, Desc}) -> + {Desc, + ?_assertEqual(ProperResult, + maybe_add_default_headers(DummyRequest, InitialHeaders))} + end, Cases), + {"Tests adding default headers", Tests}. + +-endif. http://git-wip-us.apache.org/repos/asf/couchdb-couch-httpd/blob/32aac3ab/src/couch_httpd_original.erl ---------------------------------------------------------------------- diff --git a/src/couch_httpd_original.erl b/src/couch_httpd_original.erl index d879fb8..8d4e577 100644 --- a/src/couch_httpd_original.erl +++ b/src/couch_httpd_original.erl @@ -415,51 +415,3 @@ increment_method_stats(Method) -> % Utilities - - - - - - - - -%%%%%%%% module tests below %%%%%%%% - --ifdef(TEST). --include_lib("couch/include/couch_eunit.hrl"). - -maybe_add_default_headers_test_() -> - DummyRequest = [], - NoCache = {"Cache-Control", "no-cache"}, - ApplicationJson = {"Content-Type", "application/json"}, - % couch_httpd uses process dictionary to check if currently in a - % json serving method. Defaults to 'application/javascript' otherwise. - % Therefore must-revalidate and application/javascript should be added - % by chttpd if such headers are not present - MustRevalidate = {"Cache-Control", "must-revalidate"}, - ApplicationJavascript = {"Content-Type", "application/javascript"}, - Cases = [ - {[], - [MustRevalidate, ApplicationJavascript], - "Should add Content-Type and Cache-Control to empty heaeders"}, - - {[NoCache], - [NoCache, ApplicationJavascript], - "Should add Content-Type only if Cache-Control is present"}, - - {[ApplicationJson], - [MustRevalidate, ApplicationJson], - "Should add Cache-Control if Content-Type is present"}, - - {[NoCache, ApplicationJson], - [NoCache, ApplicationJson], - "Should not add headers if Cache-Control and Content-Type are there"} - ], - Tests = lists:map(fun({InitialHeaders, ProperResult, Desc}) -> - {Desc, - ?_assertEqual(ProperResult, - maybe_add_default_headers(DummyRequest, InitialHeaders))} - end, Cases), - {"Tests adding default headers", Tests}. - --endif.