]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
networkxml2conftest: Use dnsmasqCapsNewFromBinary() to construct caps
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 12 Jan 2022 04:42:41 +0000 (05:42 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 18 Jan 2022 15:18:45 +0000 (16:18 +0100)
DISCLAIMER: dnsmasq capabilities are empty as of v8.0.0-rc1~145.

In a real environment the dnsmasq capabilities are constructed
using dnsmasqCapsNewFromBinary(). We also have
dnsmasqCapsNewFromBuffer() to bypass checks that real code is
doing and just get capabilities object. The latter is used from
test suite.

However, with a little bit of mocking we can test the real life
code. All that's needed is to simulate dnsmasq's output for
--version and --help and mock a stat() that's done in
dnsmasqCapsRefreshInternal().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
tests/networkxml2conftest.c

index 13257c749b2142430e57184d9eac8f2f5f50fbb5..718a031879d8eeb7e93f255752dc908974cf7c4a 100644 (file)
@@ -12,6 +12,8 @@
 #include "viralloc.h"
 #include "network/bridge_driver.h"
 #include "virstring.h"
+#define LIBVIRT_VIRCOMMANDPRIV_H_ALLOW
+#include "vircommandpriv.h"
 
 #define VIR_FROM_THIS VIR_FROM_NONE
 
@@ -108,13 +110,44 @@ testCompareXMLToConfHelper(const void *data)
     return result;
 }
 
+static void
+buildCapsCallback(const char *const*args,
+                  const char *const*env G_GNUC_UNUSED,
+                  const char *input G_GNUC_UNUSED,
+                  char **output,
+                  char **error G_GNUC_UNUSED,
+                  int *status,
+                  void *opaque G_GNUC_UNUSED)
+{
+    if (STREQ(args[0], "/usr/sbin/dnsmasq") && STREQ(args[1], "--version")) {
+        *output = g_strdup("Dnsmasq version 2.67\n");
+        *status = EXIT_SUCCESS;
+    } else {
+        *status = EXIT_FAILURE;
+    }
+}
+
+static dnsmasqCaps *
+buildCaps(void)
+{
+    g_autoptr(dnsmasqCaps) caps = NULL;
+    g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew();
+
+    virCommandSetDryRun(dryRunToken, NULL, true, true, buildCapsCallback, NULL);
+
+    caps = dnsmasqCapsNewFromBinary();
+
+    return g_steal_pointer(&caps);
+}
+
+
 static int
 mymain(void)
 {
     int ret = 0;
     g_autoptr(dnsmasqCaps) full = NULL;
 
-    full = dnsmasqCapsNewFromBuffer("Dnsmasq version 2.67");
+    full = buildCaps();
 
 #define DO_TEST(xname, xcaps) \
     do { \