Skip to content

Commit

Permalink
Accept a undef os for matching
Browse files Browse the repository at this point in the history
  • Loading branch information
jrouzierinverse committed Jun 1, 2015
1 parent fc9d04e commit da623ad
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lib/pf/provisioner.pm
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,12 @@ sub matchOS {

get_logger->trace( sub { "Tring to match $os against " . join(",", @oses) });
#if no oses are defined then it will match all the oses
return 1 if @oses == 0;
#if os is undef then fail
return 0 unless defined $os;
local $_;
return @oses == 0 || any { $os eq $_ } @oses;
#verify os matches list
return any { $os =~ /\Q$_\E/ } @oses;
}

=head2 match
Expand Down
11 changes: 9 additions & 2 deletions t/unittest/provisioner.t
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ BEGIN {
use lib qw(/usr/local/pf/t);
use PfFilePaths;
}
use Test::More tests => 9;
use Test::More tests => 11;

use Test::NoWarnings;
use Test::Exception;
Expand All @@ -46,6 +46,8 @@ ok($provisioner->match($TEST_OS,$TEST_NODE_ATTRIBUTE),"Match both os and categor

ok(!$provisioner->match('Generic Android',$TEST_NODE_ATTRIBUTE),"Don't Match os but Matching category");

ok(!$provisioner->match(undef,$TEST_NODE_ATTRIBUTE),"Don't match undef os");

ok(!$provisioner->match('Generic Android','not_matching'),"Don't Match os and category");

$provisioner->category(['not_matching']);
Expand All @@ -58,13 +60,18 @@ ok($provisioner->match($TEST_OS,$TEST_NODE_ATTRIBUTE),"Match os with the any cat

ok(!$provisioner->match('Generic Android',$TEST_NODE_ATTRIBUTE),"Don't match os with the any category");

$provisioner->category([$TEST_CATEGORY]);
$provisioner->oses([]);

ok($provisioner->match($TEST_OS,$TEST_NODE_ATTRIBUTE),"Match both os and category");


1;





=head1 AUTHOR
Inverse inc. <info@inverse.ca>
Expand Down

0 comments on commit da623ad

Please sign in to comment.