[Fusioninventory-devel] Simulating complete test systems

Guillaume Rousse guillomovitch at gmail.com
Wed Jan 5 21:05:54 UTC 2011


The new test modules modules allow to emulate the system on which the
code is running, so as to test high-level functions, instead of only the
ones parsing command output, or even the whole programm...

First, FusionInventory::Test::MockSystem modules provides functions
returning ad-hoc wrappers over getFileHandle, can_read and can_run
functions from FusionInventory::Agent::Tools::getFileHandle. They can be
used individually, so as to get lexically scoped overrides, for test
purpose.

use FusionInventory::Test::MockSystem;
{
my $wrapper =
    wrap 'FusionInventory::Agent::Tools::getFileHandle',
    pre => getFileHandleWrapper(
        commands => {
            'ps aux' => 'resources/ps/linux',
            ...
        }
    );
# any attempt to call 'ps aux' in this scope will instead read
'resources/ps/linux' file
}
# any attempt to call 'ps aux' outside of the scope will really call 'ps
aux' command

Second, FusionInventory::Test::MockSystem::* are modules simulating
whole systems, and just loading them is enough to overrides functions
globally

perl -I lib -I t -MFusionInventory::Test::MockSystem::Linux1
./fusioninventory-worker --task inventory

Linux1 is basically my own laptop (mandriva cooker, 64 bits, dell
latitude xt2)
Linux2 is a basic debian distribution, from already available resource
files.

The goal is to extend those two modules, and add more modules, to
simulate various static test configuration. Running an OpenSolaris
inventory on Linux is just a few code lines away...

Of course, any of those usage requires the code to never call `command`
or open(fh, '<', file) directly, but to use the various functions from
FusionInventory::Agent::Tools.
-- 
BOFH excuse #108:

The air conditioning water supply pipe ruptured over the machine room



More information about the Fusioninventory-devel mailing list