use test data for Perls probe
[scpubgit/System-Introspector.git] / t / packages-apt.t
1 use strictures 1;
2 use Test::More;
3 use FindBin;
4
5 use System::Introspector::Probe::Packages::Apt;
6
7 my $probe = System::Introspector::Probe::Packages::Apt->new;
8 my $data  = $probe->gather;
9
10 ok(scalar(keys %$data), 'received packages');
11 ok(
12     not(grep {
13         not exists $_->{version}
14     } values %{$data->{installed}{packages}}),
15     'versions',
16 );
17
18 do {
19     local $ENV{PATH} = join ':', "$FindBin::Bin/bin", $ENV{PATH};
20     my $source_list = "$FindBin::Bin/data/apt/sources.list";
21     my $source_list_dir = "$FindBin::Bin/data/apt/sources.list.d";
22     my $probe = System::Introspector::Probe::Packages::Apt->new(
23         apt_update => 1,
24         apt_update_after => 0,
25         apt_sources => $source_list,
26         apt_sources_dir => $source_list_dir,
27     );
28     my $data = $probe->gather;
29     is_deeply $data->{upgradable}, {
30         actions => {
31             inst => { foo => '(some foo info)' },
32             remv => { baz => '(some baz info)' },
33         },
34     }, 'upgradable packages';
35     ok $data->{update}{last}, 'has last update time';
36     ok $data->{update}{run}, 'has apt run state';
37     is_deeply $data->{sources}, {
38         config => {
39             sources_list => {
40                 file_name => $source_list,
41                 body => join "", map "$_\n",
42                     "deb http://main.example.com foo",
43                     "deb http://main.example.com bar",
44             },
45             sources_list_dir => {
46                 files => {
47                     "other.list" => {
48                         file_name => "$source_list_dir/other.list",
49                         body => join "", map "$_\n",
50                             "deb http://other.example.com foo",
51                             "deb http://other.example.com bar",
52                     },
53                 },
54             }
55         },
56     }, 'sources';
57 };
58
59 done_testing;