[libvirt] [PATCH 10/24] tests: qemumonitorjson: simplify path handling in testBlockNodeNameDetect

Peter Krempa posted 24 patches 7 years, 9 months ago
[libvirt] [PATCH 10/24] tests: qemumonitorjson: simplify path handling in testBlockNodeNameDetect
Posted by Peter Krempa 7 years, 9 months ago
Extract the test prefix path into a variable and reuse
virTestLoadFileJSON to load the sample json files rather than doing it
manually.
---
 tests/qemumonitorjsontest.c | 19 +++++--------------
 1 file changed, 5 insertions(+), 14 deletions(-)

diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c
index 56a0a25e1..268c15f4b 100644
--- a/tests/qemumonitorjsontest.c
+++ b/tests/qemumonitorjsontest.c
@@ -2736,8 +2736,7 @@ static int
 testBlockNodeNameDetect(const void *opaque)
 {
     const struct testBlockNodeNameDetectData *data = opaque;
-    char *namedNodesFile = NULL;
-    char *namedNodesStr = NULL;
+    const char *pathprefix = "qemumonitorjsondata/qemumonitorjson-nodename-";
     char *resultFile = NULL;
     char *actual = NULL;
     char **nodenames = NULL;
@@ -2747,21 +2746,15 @@ testBlockNodeNameDetect(const void *opaque)
     virBuffer buf = VIR_BUFFER_INITIALIZER;
     int ret = -1;

-    if (virAsprintf(&namedNodesFile,
-                    "%s/qemumonitorjsondata/qemumonitorjson-nodename-%s-named-nodes.json",
-                    abs_srcdir, data->name) < 0 ||
-        virAsprintf(&resultFile,
-                    "%s/qemumonitorjsondata/qemumonitorjson-nodename-%s.result",
-                    abs_srcdir, data->name) < 0)
+    if (virAsprintf(&resultFile, "%s/%s%s.result",
+                    abs_srcdir, pathprefix, data->name) < 0)
         goto cleanup;

     if (!(nodenames = virStringSplit(data->nodenames, ",", 0)))
         goto cleanup;

-    if (virTestLoadFile(namedNodesFile, &namedNodesStr) < 0)
-        goto cleanup;
-
-    if (!(namedNodesJson = virJSONValueFromString(namedNodesStr)))
+    if (!(namedNodesJson = virTestLoadFileJSON(pathprefix, data->name,
+                                               "-named-nodes.json", NULL)))
         goto cleanup;

     if (!(nodedata = qemuBlockNodeNameGetBackingChain(namedNodesJson)))
@@ -2783,9 +2776,7 @@ testBlockNodeNameDetect(const void *opaque)
     ret = 0;

  cleanup:
-    VIR_FREE(namedNodesFile);
     VIR_FREE(resultFile);
-    VIR_FREE(namedNodesStr);
     VIR_FREE(actual);
     virHashFree(nodedata);
     virStringListFree(nodenames);
-- 
2.13.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 10/24] tests: qemumonitorjson: simplify path handling in testBlockNodeNameDetect
Posted by Eric Blake 7 years, 9 months ago
On 07/26/2017 05:00 AM, Peter Krempa wrote:
> Extract the test prefix path into a variable and reuse
> virTestLoadFileJSON to load the sample json files rather than doing it
> manually.
> ---
>  tests/qemumonitorjsontest.c | 19 +++++--------------
>  1 file changed, 5 insertions(+), 14 deletions(-)
> 

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list