Skip to content

Commit

Permalink
add apply bag support
Browse files Browse the repository at this point in the history
  • Loading branch information
xdg committed Sep 28, 2012
1 parent 5027063 commit af004aa
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/Pantry/App/Command/apply.pm
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ my %setters = (
default => 'set_default_attribute',
override => 'set_override_attribute',
},
bag => {
default => 'set_attribute',
override => undef,
},
);

sub valid_types {
Expand Down
45 changes: 44 additions & 1 deletion t/app/apply.t
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ my %templates = (
default_attributes => {},
override_attributes => {},
},
bag => {
},
);

my @recipe_role_subtests = (
Expand Down Expand Up @@ -142,6 +144,39 @@ my @deep_attribute_subtests = (
},
);

my @bag_attribute_subtests = (
{
argv => [qw/-d nginx.port=80/],
expected => {
nginx => { port => 80 },
},
},
{
argv => [qw/-d nginx.port=80,8080/],
expected => {
nginx => { port => [ 80, 8080 ] },
},
},
{
argv => [qw/-d nginx\.port=80,8000\,8080/],
expected => {
'nginx.port' => [ 80, '8000,8080' ],
},
},
{
argv => [qw/-d nginx\.enable=false/],
expected => {
'nginx.enable' => JSON::false,
},
},
{
argv => [qw/-d nginx\.enable=true/],
expected => {
'nginx.enable' => JSON::true,
},
},
);

my @env_run_list_subtests = (
{
argv => [qw/-r nginx -E test/],
Expand Down Expand Up @@ -198,6 +233,13 @@ my @cases = (
new => sub { my ( $p, $n ) = @_; $p->environment($n) },
subtests => [ @deep_attribute_subtests ],
},

{
type => "bag",
name => 'user/xdg',
new => sub { my ( $p, $n ) = @_; $p->bag($n) },
subtests => [ @bag_attribute_subtests ],
},
);

for my $c (@cases) {
Expand All @@ -213,7 +255,8 @@ for my $c (@cases) {

my $data = _thaw_file( $obj->path );
my $expected = dclone $st->{expected};
$expected->{name} //= $c->{name};
my $id_field = $c->{type} eq 'bag' ? 'id' : 'name';
$expected->{$id_field} //= $c->{name};
for my $k ( keys %{ $templates{ $c->{type} } } ) {
$expected->{$k} //= $templates{ $c->{type} }{$k};
}
Expand Down

0 comments on commit af004aa

Please sign in to comment.