-
Notifications
You must be signed in to change notification settings - Fork 5
/
list.t
74 lines (67 loc) · 1.82 KB
/
list.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
use v5.14;
use strict;
use warnings;
use autodie;
use Test::More 0.92;
use Test::Deep 0.110 qw/cmp_deeply/;
use lib 't/lib';
use TestHelper;
my @cases = (
{
label => "nodes",
type => "node",
names => ['foo.example.com', 'bar.example.com'],
new => sub { my ($p,$n) = @_; $p->node($n) },
},
{
label => "nodes in specified environment",
type => "node",
args => [qw/-E test/],
names => ['foo.example.com', 'bar.example.com'],
new => sub { my ($p,$n) = @_; $p->node($n, {env => 'test'}) },
},
{
label => "nodes in specified environment",
type => "node",
args => [qw/-E staging/],
env_args => [qw/-E test/],
names => ['foo.example.com', 'bar.example.com'],
expected => [],
new => sub { my ($p,$n) = @_; $p->node($n, {env => 'test'}) },
},
{
label => "roles",
type => "role",
names => ['web', 'db'],
new => sub { my ($p,$n) = @_; $p->role($n) },
},
{
label => "environments",
type => "environment",
names => ['test', 'prod'],
new => sub { my ($p,$n) = @_; $p->environment($n) },
},
{
label => "bags",
type => "bag",
names => ['xdg', 'dag', 'users/egg'],
new => sub { my ($p,$n) = @_; $p->bag($n) },
},
);
for my $c ( @cases ) {
subtest "list $c->{label}" => sub {
my ($wd, $pantry) = _create_pantry();
my @args = @{$c->{args} || []};
my @env_args = @{($c->{env_args} ? $c->{env_args} : $c->{args}) || []};
for my $name ( @{$c->{names}} ) {
_try_command('create', $c->{type}, $name, @env_args);
}
my $result = _try_command('list', $c->{type}, @args);
my $found = [sort split /\n/, $result->output];
my $expected = $c->{expected} || $c->{names};
cmp_deeply( $found, [ sort @$expected ], "saw expected list" )
or diag "OUTPUT:\n" . $result->output;
};
}
done_testing;
# COPYRIGHT