summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGarren Smith <garren.smith@gmail.com>2019-01-15 15:12:24 +0200
committergarren smith <garren.smith@gmail.com>2019-01-22 12:56:59 +0200
commit4904e4c829cfeacd2af5d11e9143e72343cac749 (patch)
treeb39f0016514312ec45ff94a5588a61928c84547d
parent841de8c6a917a24fcbbc72e1ef694076e8eac82b (diff)
downloadcouchdb-4904e4c829cfeacd2af5d11e9143e72343cac749.tar.gz
Add ability to feature flag partitioned db's
-rw-r--r--src/chttpd/src/chttpd_db.erl63
-rw-r--r--src/couch/test/couch_flags_tests.erl6
2 files changed, 68 insertions, 1 deletions
diff --git a/src/chttpd/src/chttpd_db.erl b/src/chttpd/src/chttpd_db.erl
index bcd082448..6eda451e0 100644
--- a/src/chttpd/src/chttpd_db.erl
+++ b/src/chttpd/src/chttpd_db.erl
@@ -1630,6 +1630,7 @@ parse_partitioned_opt(Req) ->
"false" ->
[];
"true" ->
+ ok = validate_partitioned_db_enabled(Req),
[
{partitioned, true},
{hash, [couch_partition, hash, []]}
@@ -1639,6 +1640,15 @@ parse_partitioned_opt(Req) ->
end.
+validate_partitioned_db_enabled(Req) ->
+ case couch_flags:is_enabled(partitioned, Req) of
+ true ->
+ ok;
+ false ->
+ throw({bad_request, <<"Partitioned feature is not enabled.">>})
+ end.
+
+
parse_doc_query({Key, Value}, Args) ->
case {Key, Value} of
{"attachments", "true"} ->
@@ -1982,4 +1992,57 @@ monitor_attachments_test_() ->
end
}.
+parse_partitioned_opt_test_() ->
+ {
+ foreach,
+ fun setup/0,
+ fun teardown/1,
+ [
+ t_should_allow_partitioned_db(),
+ t_should_throw_on_not_allowed_partitioned_db(),
+ t_returns_empty_array_for_partitioned_false(),
+ t_returns_empty_array_for_no_partitioned_qs()
+ ]
+ }.
+
+
+setup() ->
+ ok.
+
+teardown(_) ->
+ meck:unload().
+
+mock_request(Url) ->
+ Headers = mochiweb_headers:make([{"Host", "examples.com"}]),
+ MochiReq = mochiweb_request:new(nil, 'PUT', Url, {1, 1}, Headers),
+ #httpd{mochi_req = MochiReq}.
+
+t_should_allow_partitioned_db() ->
+ ?_test(begin
+ meck:expect(couch_flags, is_enabled, 2, true),
+ Req = mock_request("/all-test21?partitioned=true"),
+ [Partitioned, _] = parse_partitioned_opt(Req),
+ ?assertEqual(Partitioned, {partitioned, true})
+ end).
+
+t_should_throw_on_not_allowed_partitioned_db() ->
+ ?_test(begin
+ meck:expect(couch_flags, is_enabled, 2, false),
+ Req = mock_request("/all-test21?partitioned=true"),
+ Throw = {bad_request, <<"Partitioned feature is not enabled.">>},
+ ?assertThrow(Throw, parse_partitioned_opt(Req))
+ end).
+
+t_returns_empty_array_for_partitioned_false() ->
+ ?_test(begin
+ Req = mock_request("/all-test21?partitioned=false"),
+ ?assertEqual(parse_partitioned_opt(Req), [])
+ end).
+
+t_returns_empty_array_for_no_partitioned_qs() ->
+ ?_test(begin
+ Req = mock_request("/all-test21"),
+ ?assertEqual(parse_partitioned_opt(Req), [])
+ end).
+
-endif.
diff --git a/src/couch/test/couch_flags_tests.erl b/src/couch/test/couch_flags_tests.erl
index cda7639bf..32ec57b77 100644
--- a/src/couch/test/couch_flags_tests.erl
+++ b/src/couch/test/couch_flags_tests.erl
@@ -60,12 +60,16 @@ setup() ->
application:load(couch_epi),
application:set_env(couch_epi, plugins, [couch_db_epi, ?MODULE]),
- test_util:start_couch([couch_epi]).
+ meck:expect(config, get, 1, []),
+
+ Ctx = test_util:start_couch([couch_epi]),
+ Ctx.
teardown(Ctx) ->
test_util:stop_couch(Ctx),
ok = application:unload(couch_epi),
+ meck:unload(),
ok.
couch_flags_test_() ->