tests: esxutils: refactor testParseDatastorePath

Reduce variable scope to match their lifetime,
use g_auto and remove now pointless labels in favor
of direct returns.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
Ján Tomko 2021-09-03 20:15:46 +02:00
parent ff6e806be5
commit 4b4b44d82c

View File

@ -35,21 +35,17 @@ static struct testPath paths[] = {
static int
testParseDatastorePath(const void *data G_GNUC_UNUSED)
{
int result = 0;
size_t i;
char *datastoreName = NULL;
char *directoryName = NULL;
char *directoryAndFileName = NULL;
for (i = 0; i < G_N_ELEMENTS(paths); ++i) {
VIR_FREE(datastoreName);
VIR_FREE(directoryName);
VIR_FREE(directoryAndFileName);
g_autofree char *datastoreName = NULL;
g_autofree char *directoryName = NULL;
g_autofree char *directoryAndFileName = NULL;
if (esxUtil_ParseDatastorePath
(paths[i].datastorePath, &datastoreName, &directoryName,
&directoryAndFileName) != paths[i].result) {
goto failure;
return -1;
}
if (paths[i].result < 0)
@ -57,32 +53,22 @@ testParseDatastorePath(const void *data G_GNUC_UNUSED)
if (STRNEQ(paths[i].datastoreName, datastoreName)) {
virTestDifference(stderr, paths[i].datastoreName, datastoreName);
goto failure;
return -1;
}
if (STRNEQ(paths[i].directoryName, directoryName)) {
virTestDifference(stderr, paths[i].directoryName, directoryName);
goto failure;
return -1;
}
if (STRNEQ(paths[i].directoryAndFileName, directoryAndFileName)) {
virTestDifference(stderr, paths[i].directoryAndFileName,
directoryAndFileName);
goto failure;
return -1;
}
}
cleanup:
VIR_FREE(datastoreName);
VIR_FREE(directoryName);
VIR_FREE(directoryAndFileName);
return result;
failure:
result = -1;
goto cleanup;
return 0;
}