Repository: couchdb-couch Updated Branches: refs/heads/master 05b40a8ef -> 79c98d8ce
Revert "Merge remote branch 'github/pr/158'" This reverts commit 05b40a8ef7e544b1313018d000f0c6d3d6255f1a, reversing changes made to c256ef5d098dce5b9624e117dab912205334c327. Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/79c98d8c Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/79c98d8c Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/79c98d8c Branch: refs/heads/master Commit: 79c98d8ceef2004350c6c3086c083ee021f3a854 Parents: 05b40a8 Author: ILYA Khlopotov <iil...@ca.ibm.com> Authored: Thu Apr 7 10:50:54 2016 -0700 Committer: ILYA Khlopotov <iil...@ca.ibm.com> Committed: Thu Apr 7 10:50:54 2016 -0700 ---------------------------------------------------------------------- src/couch_db.erl | 80 ++------------------------------------------------- 1 file changed, 3 insertions(+), 77 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/79c98d8c/src/couch_db.erl ---------------------------------------------------------------------- diff --git a/src/couch_db.erl b/src/couch_db.erl index c34d59a..1a9f669 100644 --- a/src/couch_db.erl +++ b/src/couch_db.erl @@ -1513,8 +1513,10 @@ select_gt(V1, _V2) -> V1. select_lt(V1, V2) when V1 > V2 -> V2; select_lt(V1, _V2) -> V1. +normalize_dbname(<<"shards/", _/binary>> = Path) -> + lists:last(binary:split(mem3:dbname(Path), <<"/">>, [global])); normalize_dbname(DbName) -> - mem3:dbname(DbName). + DbName. validate_dbname(DbName) when is_list(DbName) -> validate_dbname(?l2b(DbName)); @@ -1544,79 +1546,3 @@ is_systemdb(<<"shards/", _/binary>> = Path) when is_binary(Path) -> is_systemdb(normalize_dbname(Path)); is_systemdb(DbName) when is_binary(DbName) -> lists:member(DbName, ?SYSTEM_DATABASES). - --ifdef(TEST). --include_lib("eunit/include/eunit.hrl"). - -setup() -> - ok = meck:new(couch_db_plugin, [passthrough]), - ok = meck:expect(couch_db_plugin, validate_dbname, fun(_, _) -> false end), - ok. - -teardown(_) -> - (catch meck:unload(couch_db_plugin)). - -validate_dbname_success_test_() -> - Cases = - generate_cases_with_shards("long/co$mplex-/path+/_something") - ++ generate_cases_with_shards("something") - ++ lists:append( - [generate_cases_with_shards(?b2l(SystemDb)) - || SystemDb <- ?SYSTEM_DATABASES]), - { - foreach, fun setup/0, fun teardown/1, - [{test_name(A), fun() -> should_pass_validate_dbname(A) end} || {_, A} <- Cases] - }. - -validate_dbname_fail_test_() -> - Cases = generate_cases("_long/co$mplex-/path+/_something") - ++ generate_cases("_something") - ++ generate_cases_with_shards("long/co$mplex-/path+/_something#") - ++ generate_cases_with_shards("long/co$mplex-/path+/some.thing"), - { - foreach, fun setup/0, fun teardown/1, - [{test_name(A), fun() -> should_fail_validate_dbname(A) end} || {_, A} <- Cases] - }. - -validate_normalize_dbname_test_() -> - Cases = generate_cases_with_shards("long/co$mplex-/path+/_something") - ++ generate_cases_with_shards("something"), - [{test_name(B), fun() -> should_normalize_dbname(A, B) end} || {A, B} <- Cases]. - - -should_pass_validate_dbname(DbName) -> - {test_name(DbName), ?_assertEqual(ok, validate_dbname(DbName))}. - -should_fail_validate_dbname(DbName) -> - {test_name(DbName), ?_test(begin - Result = validate_dbname(DbName), - ?assertMatch({error, {illegal_database_name, _}}, Result), - {error, {illegal_database_name, FailedDbName}} = Result, - ?assertEqual(to_binary(DbName), FailedDbName), - ok - end)}. - -should_normalize_dbname(Arg, DbName) -> - Result = ?l2b(filename:rootname(Arg)), - {test_name(DbName), ?_assertEqual(Result, normalize_dbname(DbName))}. - -to_binary(DbName) when is_list(DbName) -> - ?l2b(DbName); -to_binary(DbName) when is_binary(DbName) -> - DbName. - -test_name(DbName) -> - lists:flatten(io_lib:format("~p", [DbName])). - -generate_cases_with_shards(DbName) -> - DbNameWithShard = add_shard(DbName), - Cases = [DbName, ?l2b(DbName), DbNameWithShard, ?l2b(DbNameWithShard)], - [{DbName, Case} || Case <- Cases]. - -add_shard(DbName) -> - "shards/00000000-3fffffff/" ++ DbName ++ ".1415960794". - -generate_cases(DbName) -> - [{DbName, DbName}, {DbName, ?l2b(DbName)}]. - --endif.