]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tests: mock libdbus in networkxml2firewalltest
authorPavel Hrdina <phrdina@redhat.com>
Tue, 15 Sep 2020 11:55:53 +0000 (13:55 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Thu, 17 Sep 2020 16:19:46 +0000 (18:19 +0200)
This test calls into src/util/virfirewalld.c where it uses DBus to
figure out if firewalld is registered. Without the mock it luckily
fails and the test works correctly.

To isolate the tests from host environment we should mock the DBus
calls.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
tests/meson.build
tests/networkxml2firewalltest.c

index 0a204c46e4947963b92198eb8ed14042f7b8911a..f0f3d8c1efd0a18448c46389ff3c507f7e5915ef 100644 (file)
@@ -404,7 +404,7 @@ endif
 if conf.has('WITH_NETWORK')
   tests += [
     { 'name': 'networkxml2conftest', 'link_with': [ network_driver_impl ] },
-    { 'name': 'networkxml2firewalltest', 'link_with': [ network_driver_impl ] },
+    { 'name': 'networkxml2firewalltest', 'link_with': [ network_driver_impl ], 'deps': [ dbus_dep ] },
     { 'name': 'networkxml2xmltest', 'link_with': [ network_driver_impl ] },
   ]
 endif
index 29e7d8bc388e9a4156c24ac99910d1d66d1c597c..80e2d6a035a99ddd13f2309a371d53266d6145fd 100644 (file)
 
 #if defined (__linux__)
 
+# if WITH_DBUS
+#  include <dbus/dbus.h>
+# endif
+
 # include "network/bridge_driver_platform.h"
 # include "virbuffer.h"
+# include "virmock.h"
 
 # define LIBVIRT_VIRFIREWALLPRIV_H_ALLOW
 # include "virfirewallpriv.h"
 #  error "test case not ported to this platform"
 # endif
 
+# if WITH_DBUS
+VIR_MOCK_WRAP_RET_ARGS(dbus_connection_send_with_reply_and_block,
+                       DBusMessage *,
+                       DBusConnection *, connection,
+                       DBusMessage *, message,
+                       int, timeout_milliseconds,
+                       DBusError *, error)
+{
+    VIR_MOCK_REAL_INIT(dbus_connection_send_with_reply_and_block);
+
+    dbus_set_error_const(error, "org.freedesktop.error", "dbus is disabled");
+
+    return NULL;
+}
+# endif
+
 static void
 testCommandDryRun(const char *const*args G_GNUC_UNUSED,
                   const char *const*env G_GNUC_UNUSED,
@@ -176,7 +197,11 @@ mymain(void)
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
 
+# if WITH_DBUS
+VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("virdbus"))
+# else
 VIR_TEST_MAIN(mymain)
+# endif
 
 #else /* ! defined (__linux__) */