[PATCH 2/4] tests: Check error message in virnetdaemontest

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This way we actually check for the proper error, not any error like invalid JSON
format.

Signed-off-by: Martin Kletzander <mkletzan@xxxxxxxxxx>
---
 .../output-data-anon-clients.err              |  1 +
 ...utput-data-client-auth-pending-failure.err |  1 +
 tests/virnetdaemontest.c                      | 19 +++++++++++--------
 3 files changed, 13 insertions(+), 8 deletions(-)
 create mode 100644 tests/virnetdaemondata/output-data-anon-clients.err
 create mode 100644 tests/virnetdaemondata/output-data-client-auth-pending-failure.err

diff --git a/tests/virnetdaemondata/output-data-anon-clients.err b/tests/virnetdaemondata/output-data-anon-clients.err
new file mode 100644
index 000000000000..6d75757bd5e0
--- /dev/null
+++ b/tests/virnetdaemondata/output-data-anon-clients.err
@@ -0,0 +1 @@
+internal error: Server testServer1 was not created
diff --git a/tests/virnetdaemondata/output-data-client-auth-pending-failure.err b/tests/virnetdaemondata/output-data-client-auth-pending-failure.err
new file mode 100644
index 000000000000..d76079f0c94b
--- /dev/null
+++ b/tests/virnetdaemondata/output-data-client-auth-pending-failure.err
@@ -0,0 +1 @@
+internal error: Invalid auth_pending and auth combination in JSON state document
diff --git a/tests/virnetdaemontest.c b/tests/virnetdaemontest.c
index 2a8bc0ec9343..47d0923bdd93 100644
--- a/tests/virnetdaemontest.c
+++ b/tests/virnetdaemontest.c
@@ -303,8 +303,8 @@ static int testExecRestart(const void *opaque)
     infile = g_strdup_printf("%s/virnetdaemondata/input-data-%s.json", abs_srcdir,
                              data->jsonfile);
 
-    outfile = g_strdup_printf("%s/virnetdaemondata/output-data-%s.json",
-                              abs_srcdir, data->jsonfile);
+    outfile = g_strdup_printf("%s/virnetdaemondata/output-data-%s.%s",
+                              abs_srcdir, data->jsonfile, data->pass ? "json" : "err");
 
     if (virFileReadAll(infile, 8192, &injsonstr) < 0)
         goto cleanup;
@@ -331,6 +331,9 @@ static int testExecRestart(const void *opaque)
     if (!(outjson = virNetDaemonPreExecRestart(dmn)))
         goto cleanup;
 
+    if (!data->pass)
+        goto cleanup;
+
     if (!(outjsonstr = virJSONValueToString(outjson, true)))
         goto cleanup;
 
@@ -340,15 +343,15 @@ static int testExecRestart(const void *opaque)
     ret = 0;
  cleanup:
     if (ret < 0) {
-        if (!data->pass) {
-            VIR_TEST_DEBUG("Got expected error: %s",
-                           virGetLastErrorMessage());
+        if (injson && !data->pass) {
+            ret = virTestCompareToFile(virGetLastErrorMessage(), outfile);
+            if (ret < 0)
+                VIR_TEST_DEBUG("Test failed with different error message");
             virResetLastError();
-            ret = 0;
         }
     } else if (!data->pass) {
-            VIR_TEST_DEBUG("Test should have failed");
-            ret = -1;
+        VIR_TEST_DEBUG("Test should have failed");
+        ret = -1;
     }
     virObjectUnref(dmn);
     VIR_FORCE_CLOSE(fdserver[0]);
-- 
2.39.0




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux