Skip to content

Commit

Permalink
testing output file presence is enough
Browse files Browse the repository at this point in the history
  • Loading branch information
guillomovitch committed Jul 18, 2012
1 parent c10491c commit 49dad45
Showing 1 changed file with 17 additions and 25 deletions.
42 changes: 17 additions & 25 deletions t/apps/agent.t
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use XML::TreePP;

use FusionInventory::Agent::Tools;

use Test::More tests => 32;
use Test::More tests => 31;

my ($content, $out, $err, $rc);

Expand All @@ -32,24 +32,6 @@ like(
'--version stdout'
);

my $tmpFile = tmpnam();
($out, $err, $rc) = run_agent('--local '. $tmpFile);
ok($rc == 0, '--local exit status');
like(
$err,
qr/Inventory saved in $tmpFile/,
'--local /tmp/somefile'
);
$content = XML::TreePP->new()->parsefile($tmpFile);
ok($content, 'file output is valid XML');
unlink($tmpFile);

($out, $err, $rc) = run_agent('--local '. '-');
ok($rc == 0, '--local exit status');
$content = XML::TreePP->new()->parse($out);
ok($content, 'STDOUT output is valid XML');
unlink($tmpFile);


($out, $err, $rc) = run_agent();
ok($rc == 1, 'no target exit status');
Expand All @@ -60,11 +42,11 @@ like(
);
is($out, '', 'no target stdout');

my $base_options = "--stdout --debug --no-task ocsdeploy,wakeonlan,snmpquery,netdiscovery";
my $base_options = "--debug --no-task ocsdeploy,wakeonlan,snmpquery,netdiscovery";

# first inventory
($out, $err, $rc) = run_agent(
"$base_options --no-category printer"
"$base_options --local - --no-category printer"
);

subtest "first inventory" => sub {
Expand All @@ -83,7 +65,7 @@ ok(

# second inventory, without software
($out, $err, $rc) = run_agent(
"$base_options --no-category printer,software"
"$base_options --local - --no-category printer,software"
);

subtest "first inventory" => sub {
Expand Down Expand Up @@ -117,7 +99,7 @@ EOF
close($file);

($out, $err, $rc) = run_agent(
"$base_options --no-category printer,software --additional-content $file"
"$base_options --local - --no-category printer,software --additional-content $file"
);
subtest "first inventory" => sub {
check_execution_ok($out, $err, $rc);
Expand Down Expand Up @@ -150,7 +132,7 @@ my $name = $OSNAME eq 'MSWin32' ? 'PATHEXT' : 'PATH';
my $value = $ENV{$name};

($out, $err, $rc) = run_agent(
"$base_options --no-category printer,software"
"$base_options --local - --no-category printer,software"
);

subtest "first inventory" => sub {
Expand All @@ -176,7 +158,7 @@ ok(
);

($out, $err, $rc) = run_agent(
"$base_options --no-category printer,software,environment"
"$base_options --local - --no-category printer,software,environment"
);

subtest "first inventory" => sub {
Expand All @@ -193,6 +175,16 @@ ok(
"inventory doesn't have any environment variables"
);

# output location tests
my $dir = File::Temp->newdir(CLEANUP => 1);
($out, $err, $rc) = run_agent("$base_options --local $dir");
ok($rc == 0, '--local <directory> exit status');
ok(<$dir/*.ocs>, '--local <directory> result file presence');

($out, $err, $rc) = run_agent("$base_options --local $dir/foo");
ok($rc == 0, '--local <file> exit status');
ok(-f "$dir/foo", '--local <file> result file presence');

sub run_agent {
my ($args) = @_;
my @args = $args ? split(/\s+/, $args) : ();
Expand Down

0 comments on commit 49dad45

Please sign in to comment.