tests: add qmp_assert_error_class()

This helper will simplify a bunch of code checking for QMP errors and
can be shared by various tests.  Note that test-qga does check for
error description as well, so don't replace the code there for now.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
This commit is contained in:
Marc-André Lureau 2018-08-30 17:58:07 +02:00 committed by Thomas Huth
parent b8e1f74b0a
commit ebb4d82d88
5 changed files with 46 additions and 61 deletions

View file

@ -1194,3 +1194,14 @@ bool qmp_rsp_is_err(QDict *rsp)
qobject_unref(rsp);
return !!error;
}
void qmp_assert_error_class(QDict *rsp, const char *class)
{
QDict *error = qdict_get_qdict(rsp, "error");
g_assert_cmpstr(qdict_get_try_str(error, "class"), ==, class);
g_assert_nonnull(qdict_get_try_str(error, "desc"));
g_assert(!qdict_haskey(rsp, "return"));
qobject_unref(rsp);
}