On 1/14/22 17:49, Andrea Bolognani wrote:
On Wed, Jan 12, 2022 at 09:47:56AM +0100, Michal Privoznik wrote:
> DISCLAIMER: dnsmasq capabilities are empty as of v8.0.0-rc1~145.
>
> In a real environment the dnsmasq capabilities are constructed
> using dnsmasqCapsNewFromBinary(). We also have
> dnsmasqCapsNewFromBuffer() to bypass checks that real code is
> doing and just get capabilities object. The latter is used from
> test suite.
>
> However, with a little bit of mocking we can test the real life
> code. All that's needed is to simulate dnsmasq's output for
> --version and --help and mock a stat() that's done in
> dnsmasqCapsRefreshInternal().
>
> Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
> ---
> tests/networkmock.c | 16 ++++++++++++++++
> tests/networkxml2conftest.c | 38 ++++++++++++++++++++++++++++++++++++-
> 2 files changed, 53 insertions(+), 1 deletion(-)
This all works, but I wonder if we couldn't just create a trivial
shell script that behaves minimally the way we expect dnsmasq to, and
change our virFindFileInPath() mock so that it returns the absolute
path to it? That way we wouldn't need to implement any additional
mocking and the code would end up being much simpler. Diff below.
I thought that we should avoid shell for new contributions:
https://libvirt.org/programming-languages.html
Also note that there is a pre-existing issue with the test, in that
we don't check that the value returned by dnsmasqCapsNewFrom*() is
non-NULL, and as a result if you change the version number in the
test string to something like 0.1 the test will still pass where it
definitely shouldn't.
Okay, let me address that in v3.
Michal