summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Avdey <eiri@eiri.ca>2017-08-23 11:59:31 -0300
committerGitHub <noreply@github.com>2017-08-23 11:59:31 -0300
commit4796ea75d20cda1eb8b2eea2e08fb57152e88fc4 (patch)
treeb58705b9b489028e222145d63a6eb939abd7098d
parent6e57c43a5ce6ac8fa9a0691a2bdce21116ee5507 (diff)
downloadcouchdb-4796ea75d20cda1eb8b2eea2e08fb57152e88fc4.tar.gz
Fix chttpd's tests warnings (#771)
* Remove unused variable from db_doc_size tests * Assert error message in open_revs_error tests * Don't discard tests in db_doc_size instantinators EUnit's foreach takes a list of tests or instantinators that return tests. Some instantinators in db_doc_size tests generate tests with ?_assert, but then return only last one. This fix makes instantinators return and consequently run all the expected assertions. * Fix formatting in the tests * Use pattern matching instead of lists:nth/1
-rw-r--r--src/chttpd/test/chttpd_db_doc_size_tests.erl75
-rw-r--r--src/chttpd/test/chttpd_open_revs_error_test.erl12
2 files changed, 47 insertions, 40 deletions
diff --git a/src/chttpd/test/chttpd_db_doc_size_tests.erl b/src/chttpd/test/chttpd_db_doc_size_tests.erl
index c4706af4a..489a83c1b 100644
--- a/src/chttpd/test/chttpd_db_doc_size_tests.erl
+++ b/src/chttpd/test/chttpd_db_doc_size_tests.erl
@@ -46,7 +46,7 @@ create_db(Url) ->
case Status of
201 -> ok;
202 -> ok;
- Else -> io:format(user, "~n HTTP Status Code: ~p~n", [Status])
+ _ -> io:format(user, "~n HTTP Status Code: ~p~n", [Status])
end,
?assert(Status =:= 201 orelse Status =:= 202).
@@ -58,7 +58,8 @@ all_test_() ->
"chttpd db max_document_size tests",
{
setup,
- fun chttpd_test_util:start_couch/0, fun chttpd_test_util:stop_couch/1,
+ fun chttpd_test_util:start_couch/0,
+ fun chttpd_test_util:stop_couch/1,
{
foreach,
fun setup/0, fun teardown/1,
@@ -75,26 +76,20 @@ all_test_() ->
}.
post_single_doc(Url) ->
- ?_assertEqual({<<"error">>, <<"document_too_large">>},
- begin
- NewDoc = "{\"post_single_doc\": \"some_doc\",
- \"_id\": \"testdoc\", \"should_be\" : \"too_large\"}",
- {ok, _, _, ResultBody} = test_request:post(Url,
- [?CONTENT_JSON, ?AUTH], NewDoc),
- {ErrorMsg} = ?JSON_DECODE(ResultBody),
- lists:nth(1, ErrorMsg)
- end).
+ NewDoc = "{\"post_single_doc\": \"some_doc\",
+ \"_id\": \"testdoc\", \"should_be\" : \"too_large\"}",
+ {ok, _, _, ResultBody} = test_request:post(Url,
+ [?CONTENT_JSON, ?AUTH], NewDoc),
+ {[ErrorMsg | _]} = ?JSON_DECODE(ResultBody),
+ ?_assertEqual({<<"error">>, <<"document_too_large">>}, ErrorMsg).
put_single_doc(Url) ->
- ?_assertEqual({<<"error">>, <<"document_too_large">>},
- begin
- NewDoc = "{\"post_single_doc\": \"some_doc\",
- \"_id\": \"testdoc\", \"should_be\" : \"too_large\"}",
- {ok, _, _, ResultBody} = test_request:put(Url ++ "/" ++ "testid",
- [?CONTENT_JSON, ?AUTH], NewDoc),
- {ErrorMsg} = ?JSON_DECODE(ResultBody),
- lists:nth(1, ErrorMsg)
- end).
+ NewDoc = "{\"post_single_doc\": \"some_doc\",
+ \"_id\": \"testdoc\", \"should_be\" : \"too_large\"}",
+ {ok, _, _, ResultBody} = test_request:put(Url ++ "/" ++ "testid",
+ [?CONTENT_JSON, ?AUTH], NewDoc),
+ {[ErrorMsg | _]} = ?JSON_DECODE(ResultBody),
+ ?_assertEqual({<<"error">>, <<"document_too_large">>}, ErrorMsg).
bulk_doc(Url) ->
NewDoc = "{\"docs\": [{\"doc1\": 1}, {\"errordoc\":
@@ -117,21 +112,23 @@ put_post_doc_attach_inline(Url) ->
{ok, _, _, ResultBody} = test_request:post(Url,
[?CONTENT_JSON, ?AUTH], Doc1),
- {Msg} = ?JSON_DECODE(ResultBody),
- ?_assertEqual({<<"ok">>, true}, lists:nth(1, Msg)),
- {ok, _, _, ResultBody1} = test_request:post(Url,
+ {[Msg | _]} = ?JSON_DECODE(ResultBody),
+ {ok, _, _, ResultBody1} = test_request:post(Url,
[?CONTENT_JSON, ?AUTH], Doc2),
- {Msg1} = ?JSON_DECODE(ResultBody1),
- ?_assertEqual({<<"error">>, <<"document_too_large">>}, lists:nth(1, Msg1)),
+ {[Msg1 | _]} = ?JSON_DECODE(ResultBody1),
{ok, _, _, ResultBody2} = test_request:put(Url ++ "/" ++ "accept",
[?CONTENT_JSON, ?AUTH], Doc1),
- {Msg2} = ?JSON_DECODE(ResultBody2),
- ?_assertEqual({<<"ok">>, true}, lists:nth(1, Msg2)),
+ {[Msg2 | _]} = ?JSON_DECODE(ResultBody2),
{ok, _, _, ResultBody3} = test_request:put(Url ++ "/" ++ "fail",
[?CONTENT_JSON, ?AUTH], Doc2),
- {Msg3} = ?JSON_DECODE(ResultBody3),
- ?_assertEqual({<<"error">>, <<"document_too_large">>}, lists:nth(1, Msg3)).
+ {[Msg3 | _]} = ?JSON_DECODE(ResultBody3),
+ [
+ ?_assertEqual({<<"ok">>, true}, Msg),
+ ?_assertEqual({<<"error">>, <<"document_too_large">>}, Msg1),
+ ?_assertEqual({<<"ok">>, true}, Msg2),
+ ?_assertEqual({<<"error">>, <<"document_too_large">>}, Msg3)
+ ].
put_multi_part_related(Url) ->
Body1 = "{\"body\":\"This is a body.\",",
@@ -147,12 +144,14 @@ put_multi_part_related(Url) ->
Doc2 = lists:concat([DocBeg, Body2, DocRest]),
{ok, _, _, ResultBody} = test_request:put(Url ++ "/" ++ "accept",
[?CONTENT_MULTI_RELATED, ?AUTH], Doc1),
- {Msg} = ?JSON_DECODE(ResultBody),
- ?_assertEqual({<<"ok">>, true}, lists:nth(1, Msg)),
+ {[Msg | _]} = ?JSON_DECODE(ResultBody),
{ok, _, _, ResultBody1} = test_request:put(Url ++ "/" ++ "faildoc",
[?CONTENT_MULTI_RELATED, ?AUTH], Doc2),
- {Msg1} = ?JSON_DECODE(ResultBody1),
- ?_assertEqual({<<"error">>, <<"document_too_large">>}, lists:nth(1, Msg1)).
+ {[Msg1 | _]} = ?JSON_DECODE(ResultBody1),
+ [
+ ?_assertEqual({<<"ok">>, true}, Msg),
+ ?_assertEqual({<<"error">>, <<"document_too_large">>}, Msg1)
+ ].
post_multi_part_form(Url) ->
Port = mochiweb_socket_server:get(chttpd, port),
@@ -170,9 +169,11 @@ post_multi_part_form(Url) ->
Doc2 = lists:concat([DocBeg, Body2, DocRest]),
{ok, _, _, ResultBody} = test_request:post(Url ++ "/" ++ "accept",
[?CONTENT_MULTI_FORM, ?AUTH, Referer], Doc1),
- {Msg} = ?JSON_DECODE(ResultBody),
- ?_assertEqual({<<"ok">>, true}, lists:nth(1, Msg)),
+ {[Msg | _]} = ?JSON_DECODE(ResultBody),
{ok, _, _, ResultBody1} = test_request:post(Url ++ "/" ++ "fail",
[?CONTENT_MULTI_FORM, ?AUTH, Referer], Doc2),
- {Msg1} = ?JSON_DECODE(ResultBody1),
- ?_assertEqual({<<"error">>, <<"document_too_large">>}, lists:nth(1, Msg1)).
+ {[Msg1 | _]} = ?JSON_DECODE(ResultBody1),
+ [
+ ?_assertEqual({<<"ok">>, true}, Msg),
+ ?_assertEqual({<<"error">>, <<"document_too_large">>}, Msg1)
+ ].
diff --git a/src/chttpd/test/chttpd_open_revs_error_test.erl b/src/chttpd/test/chttpd_open_revs_error_test.erl
index 72b45f741..d53d370f8 100644
--- a/src/chttpd/test/chttpd_open_revs_error_test.erl
+++ b/src/chttpd/test/chttpd_open_revs_error_test.erl
@@ -55,7 +55,8 @@ open_revs_error_test_() ->
"open revs error tests",
{
setup,
- fun chttpd_test_util:start_couch/0, fun chttpd_test_util:stop_couch/1,
+ fun chttpd_test_util:start_couch/0,
+ fun chttpd_test_util:stop_couch/1,
{
foreach,
fun setup/0, fun teardown/1,
@@ -74,7 +75,7 @@ should_return_503_error_for_open_revs_get(Url) ->
mock_open_revs({error, all_workers_died}),
{ok, Code, _, _} = test_request:get(Url ++
"/testdoc?rev=" ++ ?b2l(Ref), [?AUTH]),
- ?_assertEqual(503, Code).
+ ?_assertEqual(503, Code).
should_return_503_error_for_open_revs_post_form(Url) ->
Port = mochiweb_socket_server:get(chttpd, port),
@@ -97,7 +98,12 @@ should_return_503_error_for_open_revs_post_form(Url) ->
mock_open_revs({error, all_workers_died}),
{ok, Code, _, ResultBody1} = test_request:post(Url ++ "/" ++ "RevDoc",
[?CONTENT_MULTI_FORM, ?AUTH, Referer], Doc2),
- ?_assertEqual(503, Code).
+ {Json1} = ?JSON_DECODE(ResultBody1),
+ ErrorMessage = couch_util:get_value(<<"error">>, Json1),
+ [
+ ?_assertEqual(503, Code),
+ ?_assertEqual(<<"service unvailable">>, ErrorMessage)
+ ].
mock_open_revs(RevsResp) ->
ok = meck:expect(fabric, open_revs, fun(_, _, _, _) -> RevsResp end).