Skip to content

Commit

Permalink
factorize execution tests
Browse files Browse the repository at this point in the history
  • Loading branch information
guillomovitch committed Jun 1, 2012
1 parent e02c07b commit e03b0b7
Showing 1 changed file with 45 additions and 101 deletions.
146 changes: 45 additions & 101 deletions t/apps/agent.t
Expand Up @@ -10,7 +10,7 @@ use XML::TreePP;

use FusionInventory::Agent::Tools;

use Test::More tests => 46;
use Test::More tests => 27;

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

Expand Down Expand Up @@ -45,32 +45,15 @@ is($out, '', 'no target stdin');
my $base_options = "--stdout --debug --no-task ocsdeploy,wakeonlan,snmpquery,netdiscovery";

my $content;

# first inventory
($out, $err, $rc) = run_agent(
"$base_options --no-category printer"
);
ok($rc == 0, 'exit status');

unlike(
$err,
qr/module \S+ disabled: failure to load/,
'no broken module (loading)'
);

unlike(
$err,
qr/unexpected error in \S+/,
'no broken module (execution)'
);

like(
$out,
qr/^<\?xml version="1.0" encoding="UTF-8" \?>/,
'output has correct encoding'
);

$content = XML::TreePP->new()->parse($out);
ok($content, 'output is valid XML');
subtest "first inventory" => sub {
check_execution_ok($out, $err, $rc);
};

ok(
exists $content->{REQUEST}->{CONTENT}->{SOFTWARES},
Expand All @@ -86,28 +69,10 @@ ok(
($out, $err, $rc) = run_agent(
"$base_options --no-category printer,software"
);
ok($rc == 0, 'exit status');

unlike(
$err,
qr/module \S+ disabled: failure to load/,
'no broken module (loading)'
);

unlike(
$err,
qr/unexpected error in \S+/,
'no broken module (execution)'
);

like(
$out,
qr/^<\?xml version="1.0" encoding="UTF-8" \?>/,
'output has correct encoding'
);

$content = XML::TreePP->new()->parse($out);
ok($content, 'output is valid XML');
subtest "first inventory" => sub {
check_execution_ok($out, $err, $rc);
};

ok(
!exists $content->{REQUEST}->{CONTENT}->{SOFTWARES},
Expand All @@ -134,31 +99,13 @@ print $file <<EOF;
</REQUEST>
EOF
close($file);

($out, $err, $rc) = run_agent(
"$base_options --no-category printer,software --additional-content $file"
);
ok($rc == 0, 'exit status');

unlike(
$err,
qr/module \S+ disabled: failure to load/,
'no broken module (loading)'
);

unlike(
$err,
qr/unexpected error in \S+/,
'no broken module (execution)'
);

like(
$out,
qr/^<\?xml version="1.0" encoding="UTF-8" \?>/,
'output has correct encoding'
);

$content = XML::TreePP->new()->parse($out);
ok($content, 'output is valid XML');
subtest "first inventory" => sub {
check_execution_ok($out, $err, $rc);
};

ok(
exists $content->{REQUEST}->{CONTENT}->{SOFTWARES},
Expand Down Expand Up @@ -189,28 +136,10 @@ my $value = $ENV{$name};
($out, $err, $rc) = run_agent(
"$base_options --no-category printer,software"
);
ok($rc == 0, 'exit status');

unlike(
$err,
qr/module \S+ disabled: failure to load/,
'no broken module (loading)'
);

unlike(
$err,
qr/unexpected error in \S+/,
'no broken module (execution)'
);

like(
$out,
qr/^<\?xml version="1.0" encoding="UTF-8" \?>/,
'output has correct encoding'
);

$content = XML::TreePP->new()->parse($out);
ok($content, 'output is valid XML');
subtest "first inventory" => sub {
check_execution_ok($out, $err, $rc);
};

ok(
!exists $content->{REQUEST}->{CONTENT}->{SOFTWARES},
Expand All @@ -233,22 +162,10 @@ ok(
($out, $err, $rc) = run_agent(
"$base_options --no-category printer,software,environment"
);
ok($rc == 0, 'exit status');

unlike(
$err,
qr/module \S+ disabled: failure to load/,
'no broken module'
);

like(
$out,
qr/^<\?xml version="1.0" encoding="UTF-8" \?>/,
'output has correct encoding'
);

$content = XML::TreePP->new()->parse($out);
ok($content, 'output is valid XML');
subtest "first inventory" => sub {
check_execution_ok($out, $err, $rc);
};

ok(
!exists $content->{REQUEST}->{CONTENT}->{SOFTWARES},
Expand All @@ -269,3 +186,30 @@ sub run_agent {
);
return ($out, $err, $CHILD_ERROR >> 8);
}

sub check_execution_ok {
my ($client, $url) = @_;

ok($rc == 0, 'exit status');

unlike(
$err,
qr/module \S+ disabled: failure to load/,
'no broken module (loading)'
);

unlike(
$err,
qr/unexpected error in \S+/,
'no broken module (execution)'
);

like(
$out,
qr/^<\?xml version="1.0" encoding="UTF-8" \?>/,
'output has correct encoding'
);

$content = XML::TreePP->new()->parse($out);
ok($content, 'output is valid XML');
}

0 comments on commit e03b0b7

Please sign in to comment.