]> git.proxmox.com Git - pve-container.git/blob - src/test/run_tests.pl
implement setup_network for debian
[pve-container.git] / src / test / run_tests.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use PVE::Tools qw(run_command);
6
7 use lib qw(..);
8
9 use PVE::LXC;
10 use PVE::LXCSetup;
11
12 sub test_file {
13 my ($exp_fn, $real_fn) = @_;
14
15 return if system("diff -u '$exp_fn' '$real_fn'") == 0;
16
17 die "files does not match\n";
18 }
19
20 sub run_test {
21 my ($testdir) = @_;
22
23 my $rootfs = "./tmprootfs";
24
25 run_command("rm -rf $rootfs");
26 run_command("cp -a $testdir $rootfs");
27
28 my $config_fn = "$testdir/config";
29
30 my $raw = PVE::Tools::file_get_contents($config_fn);
31
32 my $conf = PVE::LXC::parse_lxc_config("/lxc/100/config", $raw);
33
34 $conf->{'lxc.rootfs'} = $rootfs;
35
36 my $lxc_setup = PVE::LXCSetup->new($conf);
37
38 for (my $i = 0; $i < 2; $i++) {
39 # run tests twice, to make sure scripts are idempotent
40
41 $lxc_setup->post_create();
42
43 my @testfiles = qw(/etc/hostname /etc/hosts /etc/network/interfaces);
44 foreach my $fn (@testfiles) {
45 next if !-f "$testdir/$fn.exp";
46 test_file("$testdir/$fn.exp", "$rootfs/$fn");
47 }
48 }
49
50 print "TEST $testdir => OK\n";
51 }
52
53 PVE::Tools::dir_glob_foreach('.', 'test\d+', sub {
54 my ($testdir) = @_;
55 run_test($testdir);
56 });
57
58 exit(0);