couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From iil...@apache.org
Subject [2/3] chttpd commit: updated refs/heads/master to be1e959
Date Fri, 15 Apr 2016 18:33:16 GMT
Add `log_format_test` test case

COUCHDB-2973


Project: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/commit/cd00955b
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/tree/cd00955b
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/diff/cd00955b

Branch: refs/heads/master
Commit: cd00955bbe3f6dcbdd11d78781bb4576f7643f9d
Parents: d2665ce
Author: ILYA Khlopotov <iilyak@ca.ibm.com>
Authored: Mon Mar 21 13:06:28 2016 -0700
Committer: ILYA Khlopotov <iilyak@ca.ibm.com>
Committed: Fri Apr 15 09:06:46 2016 -0700

----------------------------------------------------------------------
 src/chttpd.erl | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/cd00955b/src/chttpd.erl
----------------------------------------------------------------------
diff --git a/src/chttpd.erl b/src/chttpd.erl
index e5c6b65..ee90e5d 100644
--- a/src/chttpd.erl
+++ b/src/chttpd.erl
@@ -1145,4 +1145,46 @@ check_url_encoding_fail_test_() ->
             check_url_encoding("/dbname%g2"))
     ].
 
+log_format_test() ->
+    ?assertEqual(
+        "nonce 127.0.0.1 127.0.0.1:15984 undefined "
+        "GET /_cluster_setup 201 ok 10000",
+        test_log_request("/_cluster_setup", undefined)),
+    ?assertEqual(
+        "nonce 127.0.0.1 127.0.0.1:15984 user_foo "
+        "GET /_all_dbs 201 ok 10000",
+        test_log_request("/_all_dbs", #user_ctx{name = <<"user_foo">>})),
+
+    %% Utf8Name = unicode:characters_to_binary(Something),
+    Utf8User = <<227,130,136,227,129,134,227,129,147,227,129,157>>,
+    ?assertEqual(
+        "nonce 127.0.0.1 127.0.0.1:15984 %E3%82%88%E3%81%86%E3%81%93%E3%81%9D "
+        "GET /_all_dbs 201 ok 10000",
+        test_log_request("/_all_dbs", #user_ctx{name = Utf8User})),
+    ok.
+
+test_log_request(RawPath, UserCtx) ->
+    Headers = mochiweb_headers:make([{"HOST", "127.0.0.1:15984"}]),
+    MochiReq = mochiweb_request:new(socket, [], 'POST', RawPath, version, Headers),
+    Req = #httpd{
+        mochi_req = MochiReq,
+        begin_ts = {1458,588713,124003},
+        original_method = 'GET',
+        peer = "127.0.0.1",
+        nonce = "nonce",
+        user_ctx = UserCtx
+    },
+    Resp = #httpd_resp{
+        end_ts = {1458,588723,124303},
+        code = 201,
+        status = ok
+    },
+    ok = meck:new(couch_log, [passthrough]),
+    ok = meck:expect(couch_log, notice, fun(Format, Args) ->
+        lists:flatten(io_lib:format(Format, Args))
+    end),
+    Message = maybe_log(Req, Resp),
+    ok = meck:unload(couch_log),
+    Message.
+
 -endif.


Mime
View raw message