]> xenbits.xensource.com Git - libvirt.git/commitdiff
tests: switch to compact empty JSON object formatting
authorJán Tomko <jtomko@redhat.com>
Wed, 14 Feb 2024 11:51:36 +0000 (12:51 +0100)
committerJán Tomko <jtomko@redhat.com>
Tue, 24 Sep 2024 06:24:00 +0000 (08:24 +0200)
Some earlier versions of json-c format empty elements differently.
Run the tests who use the pretty formatting for readability and
diffability through a function that unifies the output.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
tests/qemublocktest.c
tests/qemublocktestdata/backupmerge/empty-out.json
tests/qemumigparamsdata/empty.json
tests/qemumigparamstest.c
tests/virmacmaptest.c
tests/virmacmaptestdata/empty.json

index c581bd174879a44f9b85db37c5fa954a8d271fcc..6c4e735466b35f9709c6f16da842bba708846139 100644 (file)
@@ -720,6 +720,7 @@ testQemuBackupIncrementalBitmapCalculate(const void *opaque)
     g_autofree char *expectpath = NULL;
     g_autoptr(virStorageSource) target = NULL;
     g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
+    g_autofree char *actual = NULL;
 
     expectpath = g_strdup_printf("%s/%s%s-out.json", abs_srcdir,
                                  backupDataPrefix, data->name);
@@ -748,7 +749,9 @@ testQemuBackupIncrementalBitmapCalculate(const void *opaque)
         virBufferAddLit(&buf, "NULL\n");
     }
 
-    return virTestCompareToFile(virBufferCurrentContent(&buf), expectpath);
+    actual = virJSONStringPrettifyBlanks(virBufferCurrentContent(&buf));
+
+    return virTestCompareToFile(actual, expectpath);
 }
 
 
index 41b42e677b97324ff33450d619b6812449bc3abe..fe51488c7066f6687ef680d6bfaa4f7768ef205c 100644 (file)
@@ -1,3 +1 @@
-[
-
-]
+[]
index 0db3279e44b0dc4fb7e694b6cb10210a96ba6ba5..0967ef424bce6791893e9a57bb952f80fd536e93 100644 (file)
@@ -1,3 +1 @@
-{
-
-}
+{}
index 5d45a9dd58fc7198aede3f9937f03861c699a2bf..67cc14d9489d3a62fd7a5ba446c723772c9b3552 100644 (file)
@@ -137,6 +137,7 @@ qemuMigParamsTestJSON(const void *opaque)
     g_autoptr(virJSONValue) paramsIn = NULL;
     g_autoptr(virJSONValue) paramsOut = NULL;
     g_autoptr(qemuMigrationParams) migParams = NULL;
+    g_autofree char *formattedJSON = NULL;
     g_autofree char *actualJSON = NULL;
     g_auto(virBuffer) debug = VIR_BUFFER_INITIALIZER;
 
@@ -156,9 +157,11 @@ qemuMigParamsTestJSON(const void *opaque)
         return -1;
 
     if (!(paramsOut = qemuMigrationParamsToJSON(migParams, false)) ||
-        !(actualJSON = virJSONValueToString(paramsOut, true)))
+        !(formattedJSON = virJSONValueToString(paramsOut, true)))
         return -1;
 
+    actualJSON = virJSONStringPrettifyBlanks(formattedJSON);
+
     if (testQEMUSchemaValidateCommand("migrate-set-parameters",
                                       paramsOut,
                                       data->qmpschema,
index 9a28c1bed00c953a55cdb95a129bc823df8f3803..074bc8f65971beaf52c07a646594408dccf6ff4a 100644 (file)
@@ -118,13 +118,16 @@ testMACFlush(const void *opaque)
     const struct testData *data = opaque;
     g_autofree char *file = NULL;
     g_autofree char *str = NULL;
+    g_autofree char *actual = NULL;
 
     file = g_strdup_printf("%s/virmacmaptestdata/%s.json", abs_srcdir, data->file);
 
     if (virMacMapDumpStr(data->mgr, &str) < 0)
         return -1;
 
-    if (virTestCompareToFile(str, file) < 0)
+    actual = virJSONStringPrettifyBlanks(str);
+
+    if (virTestCompareToFile(actual, file) < 0)
         return -1;
 
     return 0;
index 41b42e677b97324ff33450d619b6812449bc3abe..fe51488c7066f6687ef680d6bfaa4f7768ef205c 100644 (file)
@@ -1,3 +1 @@
-[
-
-]
+[]