apt source loading and tests for Packages::Apt 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 => {
41                     file_name => $source_list,
42                     body => join "", map "$_\n",
43                         "deb http://main.example.com foo",
44                         "deb http://main.example.com bar",
45                 },
46             },
47             sources_list_dir => {
48                 files => {
49                     "other.list" => {
50                         file => {
51                             file_name => "$source_list_dir/other.list",
52                             body => join "", map "$_\n",
53                                 "deb http://other.example.com foo",
54                                 "deb http://other.example.com bar",
55                         },
56                     },
57                 },
58             }
59         },
60     }, 'sources';
61 };
62
63 done_testing;