On Thu, Nov 20, 2025 at 09:32:51AM +0100, Michal Privoznik via Devel wrote:
From: Michal Privoznik <[email protected]>

If we want vmx2xmltest to use actual file name parser that's used
in production (esxParseVMXFileName()) we need a mock to stop it
from doing any HTTP requests and also to return predictable data.

So far, the function can call three functions that do HTTP
requests: esxVI_LookupDatastoreList(),
esxVI_LookupDatastoreHostMount() and
esxVI_LookupDatastoreByName().

Mock all three of them. And since their implementation uses some
other symbols (like allocators or _AppendToList() helpers) we
need to expose these symbols too.

Signed-off-by: Michal Privoznik <[email protected]>
---
src/libvirt_esx.syms | 10 ++++++
tests/meson.build    |  3 ++
tests/vmx2xmlmock.c  | 79 ++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 92 insertions(+)
create mode 100644 tests/vmx2xmlmock.c

diff --git a/tests/vmx2xmlmock.c b/tests/vmx2xmlmock.c
new file mode 100644
index 0000000000..ce4a9a426b
--- /dev/null
+++ b/tests/vmx2xmlmock.c
@@ -0,0 +1,79 @@
+#include <config.h>
+
+#include "internal.h"
+#include "esx_vi.h"
+
+int
+esxVI_LookupDatastoreList(esxVI_Context *ctx G_GNUC_UNUSED,
+                          esxVI_String *propertyNameList,
+                          esxVI_ObjectContent **datastoreList)
+{
+    esxVI_String *tmp;
+
+    for (tmp = propertyNameList; tmp; tmp = tmp->_next) {
+        esxVI_ObjectContent *obj = NULL;
+
+        if (STREQ(tmp->value, "summary.name")) {
+            esxVI_DynamicProperty *prop = NULL;
+
+            esxVI_ObjectContent_Alloc(&obj);
+
+            esxVI_DynamicProperty_Alloc(&prop);
+            prop->name = g_strdup("summary.name");
+
+            esxVI_AnyType_Alloc(&prop->val);
+            prop->val->type = esxVI_Type_String;
+            prop->val->other = g_strdup("xsd:string");
+            prop->val->value = g_strdup("datastore");
+            prop->val->string = prop->val->value;
+            esxVI_DynamicProperty_AppendToList(&obj->propSet, prop);
+        }
+
+        if (obj) {
+            esxVI_ObjectContent_AppendToList(datastoreList, obj);

This line, along with the declaration of @obj can be inside the previous
body under the condition with STREQ, no need to separate it.

Reviewed-by: Martin Kletzander <[email protected]>

Attachment: signature.asc
Description: PGP signature

Reply via email to