Merge branch 'master' of mathias-kettner.de:omd
[omd.git] / t / 04-package_files.t
blob56115749c500f410f26d2462d1d247b477d3c2d4
1 #!/usr/bin/env perl
3 use warnings;
4 use strict;
5 use Test::More;
7 plan skip_all => 'you need to specify OMD_PACKAGE for this test' unless defined $ENV{'OMD_PACKAGE'};
9 my $file = $ENV{'OMD_PACKAGE'};
10 ok(-f $file, "file: $file exists");
12 # debian packages
13 if($file =~ m/\.deb/gmx) {
14 my $content = `dpkg -c $file 2>&1`;
15 is($?, 0, 'got package content');
16 my @files = split("\n", $content);
17 ok(scalar @files > 0, 'got package '.(scalar @files).' files');
18 for my $e (@files) {
19 my($mode, $usr, $ref, $date, $time, $path) = split(/\s+/mx, $e);
20 next if file_ok($path);
21 fail("pkg contains unusual file: $e");
24 elsif($file =~ m/\.rpm/gmx) {
25 my $content = `rpm -qpl $file 2>&1`;
26 is($?, 0, 'got package content');
27 my @files = split("\n", $content);
28 ok(scalar @files > 0, 'got package '.(scalar @files).' files');
29 for my $e (@files) {
30 next if file_ok($e);
31 fail("pkg contains unusual file: $e");
34 else {
35 fail("unsupported pkg: $file");
38 done_testing();
40 #################################################
41 sub file_ok {
42 my($file) = @_;
43 $file =~ s/^\.//gmx;
44 return 1 if $file =~ m|/opt/|;
45 return 1 if $file =~ m|/usr/share/doc/omd|;
46 return 1 if $file =~ m|/etc/init.d/omd|;
47 return 1 if $file =~ m|/usr/share/man/|;
48 return 1 if $file eq '/';
49 return 1 if $file eq '/etc/';
50 return 1 if $file eq '/etc/init.d/';
51 return 1 if $file eq '/usr/';
52 return 1 if $file eq '/usr/share/';
53 return 1 if $file eq '/usr/share/doc/';
54 return;