iilyak closed pull request #1790: Move tests to suite
URL: https://github.com/apache/couchdb/pull/1790
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/src/couch/src/couch_flags_config.erl 
b/src/couch/src/couch_flags_config.erl
index 513a8154f9..104a482579 100644
--- a/src/couch/src/couch_flags_config.erl
+++ b/src/couch/src/couch_flags_config.erl
@@ -20,6 +20,11 @@
     data_provider/0
 ]).
 
+%% for test suite only
+-export([
+    parse_flags_term/1
+]).
+
 -define(DATA_INTERVAL, 1000).
 -define(MAX_FLAG_NAME_LENGTH, 256).
 
@@ -281,94 +286,3 @@ get_config_section(Section) ->
     catch error:badarg ->
             []
     end.
-
-%% ------------------------------------------------------------------
-%% Tests
-%% ------------------------------------------------------------------
-
--ifdef(TEST).
--include_lib("eunit/include/eunit.hrl").
-
-all_combinations_return_same_result_test_() ->
-    Config = [
-         {"foo, bar||*", "true"},
-         {"baz, qux||*", "false"},
-         {"baz||shards/test*", "true"},
-         {"baz||shards/blacklist*", "false"},
-         {"bar||shards/test*", "false"},
-         {"bar||shards/test/blacklist*", "true"}
-    ],
-    Expected = [
-        {{<<"shards/test/blacklist*">>},{<<"shards/test/blacklist*">>,22,[bar, 
foo]}},
-        {{<<"shards/test*">>},{<<"shards/test*">>, 12, [baz, foo]}},
-        {{<<"shards/blacklist*">>},{<<"shards/blacklist*">>, 17, [bar, foo]}},
-        {{<<"*">>},{<<"*">>, 1, [bar, foo]}}
-    ],
-    Combinations = couch_tests_combinatorics:permutations(Config),
-    [{test_id(Items), ?_assertEqual(Expected, data(Items))}
-        || Items <- Combinations].
-
-rules_are_sorted_test() ->
-    Expected = [
-        {{<<"shards/test/exact">>},{<<"shards/test/exact">>, 17, 
[baz,flag_bar,flag_foo]}},
-        
{{<<"shards/test/blacklist*">>},{<<"shards/test/blacklist*">>,22,[flag_foo]}},
-        {{<<"shards/test*">>},{<<"shards/test*">>, 12, 
[baz,flag_bar,flag_foo]}},
-        {{<<"shards/exact">>},{<<"shards/exact">>, 12, [flag_bar,flag_foo]}},
-        {{<<"shards/blacklist*">>},{<<"shards/blacklist*">>, 17, []}},
-        {{<<"*">>},{<<"*">>, 1, [flag_foo]}}
-    ],
-    ?assertEqual(Expected, data(test_config())).
-
-latest_overide_wins_test_() ->
-    Cases = [
-        {[
-            {"flag||*", "false"}, {"flag||a*", "true"},
-            {"flag||ab*", "true"}, {"flag||abc*", "true"}
-        ], true},
-        {[
-            {"flag||*", "true"}, {"flag||a*", "false"},
-            {"flag||ab*", "true"}, {"flag||abc*", "false"}
-        ], false}
-    ],
-    [{test_id(Rules, Expected),
-        ?_assertEqual(Expected, lists:member(flag, flags(hd(data(Rules)))))}
-            || {Rules, Expected} <- Cases].
-
-flags({{_Pattern}, {_Pattern, _Size, Flags}}) ->
-    Flags.
-
-test_id(Items, ExpectedResult) ->
-    lists:flatten(io_lib:format("~p -> ~p", [[P || {P, _} <- Items], 
ExpectedResult])).
-
-
-test_id(Items) ->
-    lists:flatten(io_lib:format("~p", [[P || {P, _} <- Items]])).
-
-test_config() ->
-    [
-        {"flag_foo||*", "true"},
-        {"flag_bar||*", "false"},
-        {"flag_bar||shards/test*", "true"},
-        {"flag_foo||shards/blacklist*", "false"},
-        {"baz||shards/test*", "true"},
-        {"baz||shards/test/blacklist*", "false"},
-        {"flag_bar||shards/exact", "true"},
-        {"flag_bar||shards/test/exact", "true"}
-    ].
-
-parse_flags_term_test_() ->
-    LongBinary = binary:copy(<<"a">>, ?MAX_FLAG_NAME_LENGTH + 1),
-    ExpectedError = {error, {"Cannot parse list of tags: ~n~p",
-       [{too_long, LongBinary}]}},
-    ExpectedUnknownError = {error,{"Cannot parse list of tags: ~n~p",
-       [{invalid_flag,<<"dddddddd">>}]}},
-       [
-               {"empty binary", ?_assertEqual([], parse_flags_term(<<>>))},
-               {"single flag", ?_assertEqual([fff], 
parse_flags_term(<<"fff">>))},
-               {"sorted", ?_assertEqual([aaa,bbb,fff], 
parse_flags_term(<<"fff,aaa,bbb">>))},
-               {"whitespace", ?_assertEqual([aaa,bbb,fff], 
parse_flags_term(<<"fff , aaa, bbb ">>))},
-               {"error", ?_assertEqual(ExpectedError, 
parse_flags_term(LongBinary))},
-               {"unknown_flag", ?_assertEqual(ExpectedUnknownError, 
parse_flags_term(<<"dddddddd">>))}
-       ].
-
--endif.
diff --git a/src/couch/test/couch_flags_config_tests.erl 
b/src/couch/test/couch_flags_config_tests.erl
new file mode 100644
index 0000000000..1a66cdcffa
--- /dev/null
+++ b/src/couch/test/couch_flags_config_tests.erl
@@ -0,0 +1,116 @@
+-module(couch_flags_config_tests).
+-include_lib("eunit/include/eunit.hrl").
+
+%% value copied from couch_flags_config
+-define(MAX_FLAG_NAME_LENGTH, 256).
+
+setup() ->
+    meck:new(couch_log),
+    meck:expect(couch_log, error, ['_', '_'], meck:val(ok)),
+    ok.
+
+teardown(_) ->
+    meck:unload().
+
+couch_flags_config_test_() ->
+    {
+        "test couch_flags_config",
+        {
+            setup, fun setup/0, fun teardown/1,
+            all_combinations_return_same_result()
+                ++ latest_overide_wins()
+                ++ [
+                    {"rules_are_sorted", fun rules_are_sorted/0}
+                ]
+        }
+    }.
+
+all_combinations_return_same_result() ->
+    Config = [
+         {"foo, bar||*", "true"},
+         {"baz, qux||*", "false"},
+         {"baz||shards/test*", "true"},
+         {"baz||shards/blacklist*", "false"},
+         {"bar||shards/test*", "false"},
+         {"bar||shards/test/blacklist*", "true"}
+    ],
+    Expected = [
+        {{<<"shards/test/blacklist*">>},{<<"shards/test/blacklist*">>,22,[bar, 
baz, foo]}},
+        {{<<"shards/test*">>},{<<"shards/test*">>, 12, [baz, foo]}},
+        {{<<"shards/blacklist*">>},{<<"shards/blacklist*">>, 17, [bar, foo]}},
+        {{<<"*">>},{<<"*">>, 1, [bar, foo]}}
+    ],
+    Combinations = couch_tests_combinatorics:permutations(Config),
+    [{test_id(Items), ?_assertEqual(Expected, couch_flags_config:data(Items))}
+        || Items <- Combinations].
+
+rules_are_sorted() ->
+    Expected = [
+        {{<<"shards/test/exact">>},{<<"shards/test/exact">>, 17, 
[baz,flag_bar,flag_foo]}},
+        
{{<<"shards/test/blacklist*">>},{<<"shards/test/blacklist*">>,22,[flag_foo]}},
+        {{<<"shards/test*">>},{<<"shards/test*">>, 12, 
[baz,flag_bar,flag_foo]}},
+        {{<<"shards/exact">>},{<<"shards/exact">>, 12, [flag_bar,flag_foo]}},
+        {{<<"shards/blacklist*">>},{<<"shards/blacklist*">>, 17, []}},
+        {{<<"*">>},{<<"*">>, 1, [flag_foo]}}
+    ],
+    ?assertEqual(Expected, couch_flags_config:data(test_config())).
+
+latest_overide_wins() ->
+    Cases = [
+        {[
+            {"flag||*", "false"}, {"flag||a*", "true"},
+            {"flag||ab*", "true"}, {"flag||abc*", "true"}
+        ], true},
+        {[
+            {"flag||*", "true"}, {"flag||a*", "false"},
+            {"flag||ab*", "true"}, {"flag||abc*", "false"}
+        ], false}
+    ],
+    [{test_id(Rules, Expected),
+        ?_assertEqual(Expected, lists:member(flag,
+            flags(hd(couch_flags_config:data(Rules)))))}
+            || {Rules, Expected} <- Cases].
+
+flags({{_Pattern}, {_Pattern, _Size, Flags}}) ->
+    Flags.
+
+test_id(Items, ExpectedResult) ->
+    lists:flatten(io_lib:format("~p -> ~p", [[P || {P, _} <- Items], 
ExpectedResult])).
+
+
+test_id(Items) ->
+    lists:flatten(io_lib:format("~p", [[P || {P, _} <- Items]])).
+
+test_config() ->
+    [
+        {"flag_foo||*", "true"},
+        {"flag_bar||*", "false"},
+        {"flag_bar||shards/test*", "true"},
+        {"flag_foo||shards/blacklist*", "false"},
+        {"baz||shards/test*", "true"},
+        {"baz||shards/test/blacklist*", "false"},
+        {"flag_bar||shards/exact", "true"},
+        {"flag_bar||shards/test/exact", "true"}
+    ].
+
+parse_flags_term_test_() ->
+    LongBinary = binary:copy(<<"a">>, ?MAX_FLAG_NAME_LENGTH + 1),
+    ExpectedError = {error, {"Cannot parse list of tags: ~n~p",
+       [{too_long, LongBinary}]}},
+    ExpectedUnknownError = {error,{"Cannot parse list of tags: ~n~p",
+       [{invalid_flag,<<"dddddddd">>}]}},
+       [
+               {"empty binary", ?_assertEqual(
+                   [], couch_flags_config:parse_flags_term(<<>>))},
+               {"single flag", ?_assertEqual(
+                   [fff], couch_flags_config:parse_flags_term(<<"fff">>))},
+               {"sorted", ?_assertEqual(
+                   [aaa,bbb,fff], 
couch_flags_config:parse_flags_term(<<"fff,aaa,bbb">>))},
+               {"whitespace", ?_assertEqual(
+                   [aaa,bbb,fff], couch_flags_config:parse_flags_term(<<"fff , 
aaa, bbb ">>))},
+               {"error", ?_assertEqual(
+                   ExpectedError, 
couch_flags_config:parse_flags_term(LongBinary))},
+               {"unknown_flag", ?_assertEqual(
+                   ExpectedUnknownError, 
couch_flags_config:parse_flags_term(<<"dddddddd">>))}
+       ].
+


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to