Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/fty_common_rest_utils_web.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ typedef std::array<_WSError, _WSErrorsCOUNT> _WSErrors;
// **5** additional empty strings, which fill sefgaults for other formatting specifiers.

#define HTTP_TEAPOT 418 //see RFC2324
// Note: array index of "undefined" is 0 and will be rejected by macros below
static constexpr const _WSErrors _errors = { {
{"undefined", HTTP_TEAPOT, INT_MIN, TRANSLATE_ME_IGNORE_PARAMS ("I'm a teapot!") },
{"internal-error", HTTP_INTERNAL_SERVER_ERROR, 42, TRANSLATE_ME_IGNORE_PARAMS ("Internal Server Error. %s") },
Expand Down
34 changes: 33 additions & 1 deletion src/fty_common_rest_utils_web.cc
Original file line number Diff line number Diff line change
Expand Up @@ -916,9 +916,41 @@ fty_common_rest_utils_web_test (bool verbose)
// Cleanup
utils::config::roots_destroy(roots);
roots.clear();
}

printf ("OK\n");
{
log_debug ("fty-common-rest-utils-web: Test #13");
log_debug ("macro::bios_error_idx");
std::string err, expectation;
int idx;

bios_error_idx(idx, err, "internal-error", "test13");
expectation = "{ \"key\": \"Internal Server Error. {{var1}}\", "
"\"variables\": { \"var1\": \"test13\" } }";
log_debug("Got err_str: %s\n\tat index %i", err.c_str(), idx);
log_debug("Expectation: %s", expectation.c_str());
// Verify that we did get the translated string,
// not the expansion of original printf pattern in
// the errors array from fty_common_rest_utils_web.h :
assert (!streq(err.c_str(), "Internal Server Error. test13"));
assert (streq(err.c_str(), expectation.c_str()));

// This one fails because array index of "undefined" is 0
/*
{
bool passed = false;
try {
bios_error_idx(idx, err, "undefined");
assert (streq(err.c_str(), "I'm a teapot!"));
passed = true;
} catch(std::exception e) {
assert (passed == false);
}
}
*/
}

printf ("OK\n");
}

#ifdef __cplusplus
Expand Down