]> xenbits.xensource.com Git - libvirt.git/commitdiff
tests: storage: Replace index testing in testStorageLookup
authorPeter Krempa <pkrempa@redhat.com>
Mon, 25 Jan 2021 14:15:02 +0000 (15:15 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 27 Jan 2021 06:49:58 +0000 (07:49 +0100)
Test the actual index in the returned virStorageSource rather than the
parsed one. Some tests need to be adapted as they were on failed lookup.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
tests/virstoragetest.c

index c976a1c0d03b11476b0fdf68387ad481af807395..762328df9a3a0c580341fd580039b11b24d0da79 100644 (file)
@@ -353,17 +353,6 @@ testStorageLookup(const void *args)
     int ret = 0;
     virStorageSourcePtr result;
     virStorageSourcePtr actualParent;
-    unsigned int idx;
-
-    if (virStorageFileParseChainIndex(data->target, data->name, &idx) < 0 &&
-        data->expIndex) {
-        fprintf(stderr, "call should not have failed\n");
-        ret = -1;
-    }
-    if (idx != data->expIndex) {
-        fprintf(stderr, "index: expected %u, got %u\n", data->expIndex, idx);
-        ret = -1;
-    }
 
     result = virStorageSourceChainLookup(data->chain, data->from,
                                          data->name, data->target, &actualParent);
@@ -386,6 +375,17 @@ testStorageLookup(const void *args)
                 data->expMeta, result);
         ret = -1;
     }
+    if (data->expIndex > 0) {
+        if (!result) {
+            fprintf(stderr, "index: resulting lookup is empty, can't match index\n");
+            ret = -1;
+        } else {
+            if (result->id != data->expIndex) {
+                fprintf(stderr, "index: expected %u, got %u\n", data->expIndex, result->id);
+                ret = -1;
+            }
+        }
+    }
     if (data->expParent != actualParent) {
         fprintf(stderr, "parent: expected %s, got %s\n",
                 NULLSTR(data->expParent ? data->expParent->path : NULL),
@@ -1077,13 +1077,13 @@ mymain(void)
     TEST_LOOKUP_TARGET(72, "vda", NULL, "vda[0]", 0, NULL, NULL, NULL);
     TEST_LOOKUP_TARGET(73, "vda", NULL, "vda[1]", 1, chain2->path, chain2, chain);
     TEST_LOOKUP_TARGET(74, "vda", chain, "vda[1]", 1, chain2->path, chain2, chain);
-    TEST_LOOKUP_TARGET(75, "vda", chain2, "vda[1]", 1, NULL, NULL, NULL);
-    TEST_LOOKUP_TARGET(76, "vda", chain3, "vda[1]", 1, NULL, NULL, NULL);
+    TEST_LOOKUP_TARGET(75, "vda", chain2, "vda[1]", 0, NULL, NULL, NULL);
+    TEST_LOOKUP_TARGET(76, "vda", chain3, "vda[1]", 0, NULL, NULL, NULL);
     TEST_LOOKUP_TARGET(77, "vda", NULL, "vda[2]", 2, chain3->path, chain3, chain2);
     TEST_LOOKUP_TARGET(78, "vda", chain, "vda[2]", 2, chain3->path, chain3, chain2);
     TEST_LOOKUP_TARGET(79, "vda", chain2, "vda[2]", 2, chain3->path, chain3, chain2);
-    TEST_LOOKUP_TARGET(80, "vda", chain3, "vda[2]", 2, NULL, NULL, NULL);
-    TEST_LOOKUP_TARGET(81, "vda", NULL, "vda[3]", 3, NULL, NULL, NULL);
+    TEST_LOOKUP_TARGET(80, "vda", chain3, "vda[2]", 0, NULL, NULL, NULL);
+    TEST_LOOKUP_TARGET(81, "vda", NULL, "vda[3]", 0, NULL, NULL, NULL);
 
 #define TEST_PATH_CANONICALIZE(id, PATH, EXPECT) \
     do { \