]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tests: Check error message in virnetdaemontest
authorMartin Kletzander <mkletzan@redhat.com>
Mon, 2 Jan 2023 15:26:31 +0000 (16:26 +0100)
committerMartin Kletzander <mkletzan@redhat.com>
Mon, 2 Jan 2023 19:39:08 +0000 (20:39 +0100)
This way we actually check for the proper error, not any error like invalid JSON
format.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
tests/virnetdaemondata/output-data-anon-clients.err [new file with mode: 0644]
tests/virnetdaemondata/output-data-client-auth-pending-failure.err [new file with mode: 0644]
tests/virnetdaemontest.c

diff --git a/tests/virnetdaemondata/output-data-anon-clients.err b/tests/virnetdaemondata/output-data-anon-clients.err
new file mode 100644 (file)
index 0000000..6d75757
--- /dev/null
@@ -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 (file)
index 0000000..d76079f
--- /dev/null
@@ -0,0 +1 @@
+internal error: Invalid auth_pending and auth combination in JSON state document
index 2a8bc0ec934355d36eba302f6b0d261eee39e6e3..47d0923bdd9324eec071fa74764cf7e0aa8f2914 100644 (file)
@@ -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]);