]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
vmx2xmltest: Drop custom file name parse function
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 14 Nov 2025 09:35:14 +0000 (10:35 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 20 Nov 2025 14:09:14 +0000 (15:09 +0100)
Having a custom file name parsing function in vmx2xml that's
different to the one used in production (esxParseVMXFileName())
might have served us well, but it also defeats the point of
having a unit test. More specifically, if there's a bug in
esxParseVMXFileName() then our unit test would not catch it.

But now that we have vmx2xmlmock the custom parsing function can
be dropped and the test can use the real one.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
tests/meson.build
tests/vmx2xmltest.c

index 9adf172b7f6cbb344fce5b60a19c6b5fbf39083b..cd53e48aa47733840ca4814720f1169452e9b10c 100644 (file)
@@ -550,7 +550,7 @@ endif
 
 if conf.has('WITH_VMX')
   tests += [
-    { 'name': 'vmx2xmltest' },
+    { 'name': 'vmx2xmltest', 'include': [ esx_inc_dir ], 'link_with': [ esx_lib ] },
     { 'name': 'xml2vmxtest' },
   ]
   mock_libs += [
index bcd95ed87dcc0a9adcc9fae82196c33e53dd7625..cb8e04af0d1ea3d2729bc8e00bbf90ae9fef2f9c 100644 (file)
@@ -8,6 +8,8 @@
 
 # include "internal.h"
 # include "vmx/vmx.h"
+# define LIBVIRT_ESX_DRIVERPRIV_H_ALLOW
+# include "esx_driverpriv.h"
 
 # define VIR_FROM_THIS VIR_FROM_VMWARE
 
@@ -104,60 +106,12 @@ testCompareHelper(const void *data)
     return ret;
 }
 
-static int
-testParseVMXFileName(const char *fileName,
-                     void *opaque G_GNUC_UNUSED,
-                     char **src,
-                     bool allow_missing)
-{
-    g_autofree char *copyOfFileName = NULL;
-    char *tmp = NULL;
-    char *saveptr = NULL;
-    char *datastoreName = NULL;
-    char *directoryAndFileName = NULL;
-
-    *src = NULL;
-
-    if (STRPREFIX(fileName, "/vmfs/volumes/")) {
-        /* Found absolute path referencing a file inside a datastore */
-        copyOfFileName = g_strdup(fileName);
-
-        /* Expected format: '/vmfs/volumes/<datastore>/<path>' */
-        if ((tmp = STRSKIP(copyOfFileName, "/vmfs/volumes/")) == NULL ||
-            (datastoreName = strtok_r(tmp, "/", &saveptr)) == NULL ||
-            (directoryAndFileName = strtok_r(NULL, "", &saveptr)) == NULL) {
-            return -1;
-        }
-
-        if (STREQ(datastoreName, "missing") ||
-            STRPREFIX(directoryAndFileName, "missing")) {
-            if (allow_missing)
-                return 0;
-
-            virReportError(VIR_ERR_INTERNAL_ERROR,
-                           "Referenced missing file '%s'", fileName);
-            return -1;
-        }
-
-        *src = g_strdup_printf("[%s] %s", datastoreName, directoryAndFileName);
-    } else if (STRPREFIX(fileName, "/")) {
-        /* Found absolute path referencing a file outside a datastore */
-        *src = g_strdup(fileName);
-    } else if (strchr(fileName, '/') != NULL) {
-        /* Found relative path, this is not supported */
-        return -1;
-    } else {
-        /* Found single file name referencing a file inside a datastore */
-        *src = g_strdup_printf("[datastore] directory/%s", fileName);
-    }
-
-    return 0;
-}
 
 static int
 mymain(void)
 {
     int ret = 0;
+    esxVMX_Data data = { 0 };
 
 # define DO_TEST_FULL(file, should_fail) \
         do { \
@@ -180,8 +134,10 @@ mymain(void)
     if (!(xmlopt = virVMXDomainXMLConfInit(caps)))
         return EXIT_FAILURE;
 
-    ctx.opaque = NULL;
-    ctx.parseFileName = testParseVMXFileName;
+    data.datastorePathWithoutFileName = (char*) "[datastore] directory";
+
+    ctx.opaque = &data;
+    ctx.parseFileName = esxParseVMXFileName;
     ctx.formatFileName = NULL;
     ctx.autodetectSCSIControllerModel = NULL;
     ctx.datacenterPath = NULL;
@@ -296,7 +252,8 @@ mymain(void)
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
 
-VIR_TEST_MAIN(mymain)
+VIR_TEST_MAIN_PRELOAD(mymain,
+                      VIR_TEST_MOCK("vmx2xml"))
 
 #else