You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2015/09/28 15:25:30 UTC

[2/3] couch-log commit: updated refs/heads/master to fb41573

Remove the custom backend, mock it instead


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-log/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-log/commit/19e27160
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-log/tree/19e27160
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-log/diff/19e27160

Branch: refs/heads/master
Commit: 19e27160562b653cfdea00430edca2cb7b4d2e09
Parents: 345c206
Author: Eric Avdey <ei...@eiri.ca>
Authored: Fri Sep 25 12:19:54 2015 -0300
Committer: Eric Avdey <ei...@eiri.ca>
Committed: Fri Sep 25 12:19:54 2015 -0300

----------------------------------------------------------------------
 src/couch_log.erl        |  37 +++++++++-----
 test/couch_log_eunit.erl | 114 ------------------------------------------
 2 files changed, 24 insertions(+), 127 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-log/blob/19e27160/src/couch_log.erl
----------------------------------------------------------------------
diff --git a/src/couch_log.erl b/src/couch_log.erl
index eaa887f..7bdb476 100644
--- a/src/couch_log.erl
+++ b/src/couch_log.erl
@@ -93,35 +93,46 @@ callbacks_test_() ->
         [
             ?_assertEqual({ok, couch_log_eunit}, get_backend()),
             ?_assertEqual(ok, couch_log:debug("debug", [])),
-            ?_assertEqual("debug", couch_log_eunit:debug()),
+            ?_assertEqual({debug, ["debug", []]}, last_meck_call()),
             ?_assertEqual(ok, couch_log:info("info", [])),
-            ?_assertEqual("info", couch_log_eunit:info()),
+            ?_assertEqual({info, ["info", []]}, last_meck_call()),
             ?_assertEqual(ok, couch_log:notice("notice", [])),
-            ?_assertEqual("notice", couch_log_eunit:notice()),
+            ?_assertEqual({notice, ["notice", []]}, last_meck_call()),
             ?_assertEqual(ok, couch_log:warning("warning", [])),
-            ?_assertEqual("warning", couch_log_eunit:warning()),
+            ?_assertEqual({warning, ["warning", []]}, last_meck_call()),
             ?_assertEqual(ok, couch_log:error("error", [])),
-            ?_assertEqual("error", couch_log_eunit:error()),
+            ?_assertEqual({error, ["error", []]}, last_meck_call()),
             ?_assertEqual(ok, couch_log:critical("critical", [])),
-            ?_assertEqual("critical", couch_log_eunit:critical()),
+            ?_assertEqual({critical, ["critical", []]}, last_meck_call()),
             ?_assertEqual(ok, couch_log:alert("alert", [])),
-            ?_assertEqual("alert", couch_log_eunit:alert()),
+            ?_assertEqual({alert, ["alert", []]}, last_meck_call()),
             ?_assertEqual(ok, couch_log:emergency("emergency", [])),
-            ?_assertEqual("emergency", couch_log_eunit:emergency()),
+            ?_assertEqual({emergency, ["emergency", []]}, last_meck_call()),
             ?_assertEqual(ok, couch_log:set_level(info)),
-            ?_assertEqual(info, couch_log_eunit:get_level())
+            ?_assertEqual({set_level, [info]}, last_meck_call())
         ]
     }.
 
 setup() ->
-    meck:new([couch_stats]),
+    meck:new([couch_stats, couch_log_eunit], [non_strict]),
     meck:expect(couch_stats, increment_counter, fun(_) -> ok end),
-    couch_log_eunit:setup(),
+    setup_couch_log_eunit(),
     application:load(?MODULE),
     application:set_env(?MODULE, backend, couch_log_eunit).
 
 cleanup(_) ->
-    meck:unload([couch_stats]),
-    couch_log_eunit:cleanup().
+    meck:unload([couch_stats, couch_log_eunit]).
+
+setup_couch_log_eunit() ->
+    meck:expect(couch_log_eunit, set_level, 1, ok),
+    Levels = [debug, info, notice, warning, error, critical, alert, emergency],
+    lists:foreach(fun(Fun) ->
+        meck:expect(couch_log_eunit, Fun, 2, ok)
+    end, Levels).
+
+last_meck_call() ->
+    History = meck:history(couch_log_eunit, self()),
+    {_, {couch_log_eunit, M, A}, _} = hd(lists:reverse(History)),
+    {M, A}.
 
 -endif.

http://git-wip-us.apache.org/repos/asf/couchdb-couch-log/blob/19e27160/test/couch_log_eunit.erl
----------------------------------------------------------------------
diff --git a/test/couch_log_eunit.erl b/test/couch_log_eunit.erl
deleted file mode 100644
index f5af18c..0000000
--- a/test/couch_log_eunit.erl
+++ /dev/null
@@ -1,114 +0,0 @@
-% Licensed under the Apache License, Version 2.0 (the "License"); you may not
-% use this file except in compliance with the License. You may obtain a copy of
-% the License at
-%
-%   http://www.apache.org/licenses/LICENSE-2.0
-%
-% Unless required by applicable law or agreed to in writing, software
-% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-% License for the specific language governing permissions and limitations under
-% the License.
-
--module(couch_log_eunit).
-
--behaviour(couch_log).
-
--export([
-    debug/2,
-    info/2,
-    notice/2,
-    warning/2,
-    error/2,
-    critical/2,
-    alert/2,
-    emergency/2,
-    set_level/1
-]).
-
--export([
-    setup/0,
-    cleanup/0,
-    debug/0,
-    info/0,
-    notice/0,
-    warning/0,
-    error/0,
-    critical/0,
-    alert/0,
-    emergency/0,
-    get_level/0
-]).
-
-debug() ->
-    read_log(debug).
-
-debug(Fmt, Args) ->
-    write_log(debug, Fmt, Args).
-
-info() ->
-    read_log(info).
-
-info(Fmt, Args) ->
-    write_log(info, Fmt, Args).
-
-notice() ->
-    read_log(notice).
-
-notice(Fmt, Args) ->
-    write_log(notice, Fmt, Args).
-
-warning() ->
-    read_log(warning).
-
-warning(Fmt, Args) ->
-    write_log(warning, Fmt, Args).
-
-error() ->
-    read_log(error).
-
-error(Fmt, Args) ->
-    write_log(error, Fmt, Args).
-
-critical() ->
-    read_log(critical).
-
-critical(Fmt, Args) ->
-    write_log(critical, Fmt, Args).
-
-alert() ->
-    read_log(alert).
-
-alert(Fmt, Args) ->
-    write_log(alert, Fmt, Args).
-
-emergency() ->
-    read_log(emergency).
-
-emergency(Fmt, Args) ->
-    write_log(emergency, Fmt, Args).
-
-get_level() ->
-    read_log(level).
-
-set_level(Level) ->
-    true = ets:insert(?MODULE, {level, Level}),
-    ok.
-
-
-setup() ->
-    ets:new(?MODULE, [public, named_table]).
-
-cleanup() ->
-    ets:delete(?MODULE).
-
-write_log(Key, Fmt, Args) ->
-    Msg = io_lib:format(Fmt, Args),
-    true = ets:insert(?MODULE, {Key, Msg}),
-    ok.
-
-read_log(Key) ->
-    case ets:lookup(?MODULE, Key) of
-        [] -> undefined;
-        [{Key, Value}] -> Value
-    end.
\ No newline at end of file