mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 05:35:25 +00:00
tests: Introduce helpers for fakerootdir handling
We have this logic open-coded all over the test suite. Provide proper helpers implementing it. Signed-off-by: Andrea Bolognani <abologna@redhat.com> Reviewed-by: Laine Stump <laine@redhat.com>
This commit is contained in:
parent
4b2799fdaa
commit
ef3b22e589
@ -766,6 +766,32 @@ virTestSetEnvPath(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX"
|
||||
|
||||
char*
|
||||
virTestFakeRootDirInit(void)
|
||||
{
|
||||
g_autofree char *fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
|
||||
|
||||
if (!g_mkdtemp(fakerootdir)) {
|
||||
fprintf(stderr, "Cannot create fakerootdir");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
g_setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, TRUE);
|
||||
|
||||
return g_steal_pointer(&fakerootdir);
|
||||
}
|
||||
|
||||
void
|
||||
virTestFakeRootDirCleanup(char *fakerootdir)
|
||||
{
|
||||
g_unsetenv("LIBVIRT_FAKE_ROOT_DIR");
|
||||
|
||||
if (!g_getenv("LIBVIRT_SKIP_CLEANUP"))
|
||||
virFileDeleteTree(fakerootdir);
|
||||
}
|
||||
|
||||
int virTestMain(int argc,
|
||||
char **argv,
|
||||
int (*func)(void),
|
||||
|
@ -101,6 +101,9 @@ void virTestQuiesceLibvirtErrors(bool always);
|
||||
void virTestCounterReset(const char *prefix);
|
||||
const char *virTestCounterNext(void);
|
||||
|
||||
char *virTestFakeRootDirInit(void);
|
||||
void virTestFakeRootDirCleanup(char *fakerootdir);
|
||||
|
||||
/**
|
||||
* The @func shall return EXIT_FAILURE or EXIT_SUCCESS or
|
||||
* EXIT_AM_SKIP or EXIT_AM_HARDFAIL.
|
||||
|
Loading…
Reference in New Issue
Block a user