On Fri, Jan 17, 2020 at 6:47 PM Andrea Bolognani <abologna@redhat.com> wrote:
On Thu, 2020-01-16 at 09:28 +0100, Christian Ehrhardt wrote:
> +VIR_MOCK_IMPL_RET_ARGS(virFileMakePath, int,
> +                       const char *, path)
> +{
> +    const char *home;
> +
> +    VIR_MOCK_REAL_INIT(virFileMakePath);
> +
> +    /* ignore non-existing homes (e.g. in build environments) */
> +    home = getenv("HOME");
> +    if (strstr(path, home)) {
> +        if (!g_file_test (home, G_FILE_TEST_EXISTS))
> +            return 0;
> +    }
> +    return real_virFileMakePath(path);
> +}

This doesn't look like the correct fix: what will happen is that,
instead of creating the directory the library code expects, we will
not create it and lie to the caller about this fact.
 
Not creating and lying was exactly what I had in mind for this particular case as it was the least invasive change to achieve what was needed for the test.

What we should do instead is create the directory, but make sure it
is prefixed with LIBVIRT_FAKE_ROOT_DIR, in a similar way to what's
done in virpcimock. Of course file access will need to be mocked in
the same way for the tests to work...
 
I was initially adding all sorts of virFileWrapperAddPrefix but it failed me.
Trying again in the style of virpcimock seems like a good idea, but I have to be honest due to a business trip and some other tasks I won't get to it soon.
If that build error with non-existing $HOME bothers anyone else feel free to beat me to it with a v3 of this.


--
Andrea Bolognani / Red Hat / Virtualization



--
Christian Ehrhardt
Staff Engineer, Ubuntu Server
Canonical Ltd