]> git.proxmox.com Git - pve-container.git/blob - src/test/run_tests.pl
PVE::LXCCreate, use our own class instead of running extenal lxc-create
[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 print "prepare $testdir\n";
24
25 my $rootfs = "./tmprootfs";
26
27 run_command("rm -rf $rootfs");
28 run_command("cp -a $testdir $rootfs");
29
30 my $config_fn = "$testdir/config";
31
32 my $raw = PVE::Tools::file_get_contents($config_fn);
33
34 my $conf = PVE::LXC::parse_lxc_config("/lxc/100/config", $raw);
35
36 $conf->{'pve.test_mode'} = 1;
37
38 my $lxc_setup = PVE::LXCSetup->new($conf, $rootfs);
39
40 for (my $i = 0; $i < 2; $i++) {
41 # run tests twice, to make sure scripts are idempotent
42
43 $lxc_setup->post_create_hook('$TEST$ABCDEF');
44
45 my @testfiles = qw(/etc/hostname /etc/hosts /etc/inittab /etc/network/interfaces /etc/resolv.conf /etc/passwd /etc/shadow);
46 foreach my $fn (@testfiles) {
47 next if !-f "$testdir/$fn.exp";
48 test_file("$testdir/$fn.exp", "$rootfs/$fn");
49 }
50 }
51
52 print "TEST $testdir => OK\n";
53 }
54
55 if (scalar(@ARGV)) {
56
57 foreach my $testdir (@ARGV) {
58 run_test($testdir);
59 }
60
61 } else {
62
63 foreach my $testdir (<test-*>) {#
64 next if ! -d $testdir;
65 run_test($testdir);
66 }
67 }
68
69 exit(0);