[PATCH v4 10/13] networkxml2conftest: Use dnsmasqCapsNewFromBinary() to construct caps

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

 



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.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 tests/dnsmasqmock.py        | 13 +++++++++++++
 tests/networkxml2conftest.c |  2 +-
 tests/virdnsmasqmock.c      |  2 +-
 3 files changed, 15 insertions(+), 2 deletions(-)
 create mode 100755 tests/dnsmasqmock.py

diff --git a/tests/dnsmasqmock.py b/tests/dnsmasqmock.py
new file mode 100755
index 0000000000..0cfc65a854
--- /dev/null
+++ b/tests/dnsmasqmock.py
@@ -0,0 +1,13 @@
+#!/usr/bin/env python3
+
+import sys
+
+output = {
+    "--version": "Dnsmasq version 2.67",
+}
+
+if len(sys.argv) != 2 or sys.argv[1] not in output:
+    print("invalid usage")
+    sys.exit(1)
+
+print(output[sys.argv[1]])
diff --git a/tests/networkxml2conftest.c b/tests/networkxml2conftest.c
index 13257c749b..f96a92b9f0 100644
--- a/tests/networkxml2conftest.c
+++ b/tests/networkxml2conftest.c
@@ -114,7 +114,7 @@ mymain(void)
     int ret = 0;
     g_autoptr(dnsmasqCaps) full = NULL;
 
-    full = dnsmasqCapsNewFromBuffer("Dnsmasq version 2.67");
+    full = dnsmasqCapsNewFromBinary();
 
 #define DO_TEST(xname, xcaps) \
     do { \
diff --git a/tests/virdnsmasqmock.c b/tests/virdnsmasqmock.c
index 448332ec40..b043c5ceca 100644
--- a/tests/virdnsmasqmock.c
+++ b/tests/virdnsmasqmock.c
@@ -12,7 +12,7 @@ char *
 virFindFileInPath(const char *file)
 {
     if (STREQ_NULLABLE(file, "dnsmasq"))
-        return g_strdup("/usr/sbin/dnsmasq");
+        return g_strdup(abs_srcdir "/dnsmasqmock.py");
 
     /* We should not need any other binaries so return NULL. */
     return NULL;
-- 
2.34.1




[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