Skip to content

Commit d6d6d54

Browse files
committed
Bug#36262978 dump json-document if test fails
When a one of the rest-pluging related test fails to validate the returned JSON documents it does not show the documented that failed to validate. Change ====== - dump the JSON document on test-fail. Change-Id: I152df27532d60c1abb5beeeafff45184bf895409
1 parent 0a1837e commit d6d6d54

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

router/tests/helpers/rest_api_testutils.cc

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,16 @@
2727
#include <thread>
2828

2929
#include <gmock/gmock.h>
30+
31+
#define RAPIDJSON_HAVE_STDSTRING
32+
3033
#ifdef RAPIDJSON_NO_SIZETYPEDEFINE
3134
#include "my_rapidjson_size_t.h"
3235
#endif
33-
3436
#include <rapidjson/document.h>
3537
#include <rapidjson/error/en.h>
38+
#include <rapidjson/writer.h>
39+
3640
#include "mysqlrouter/rest_client.h"
3741

3842
#include "rest_api_testutils.h"
@@ -369,6 +373,15 @@ static void verify_swagger_content(
369373
}
370374
}
371375

376+
static std::string to_string(const JsonDocument &json_doc) {
377+
rapidjson::StringBuffer buffer;
378+
rapidjson::PrettyWriter writer(buffer);
379+
380+
json_doc.Accept(writer);
381+
382+
return buffer.GetString();
383+
}
384+
372385
void RestApiComponentTest::fetch_and_validate_schema_and_resource(
373386
const RestApiTestParams &test_params, ProcessWrapper &http_server,
374387
const std::string &http_hostname) {
@@ -467,8 +480,8 @@ void RestApiComponentTest::fetch_and_validate_schema_and_resource(
467480
// HEAD does not return a body
468481
if (method != HttpMethod::Head) {
469482
for (const auto &kv : test_params.value_checks) {
470-
ASSERT_NO_FATAL_FAILURE(
471-
validate_value(json_doc, kv.first, kv.second));
483+
ASSERT_NO_FATAL_FAILURE(validate_value(json_doc, kv.first, kv.second))
484+
<< to_string(json_doc);
472485
}
473486
}
474487
}

0 commit comments

Comments
 (0)