[pve-devel] [PATCH container 1/3] use real days in setup tests

Dominik Csapak d.csapak at proxmox.com
Thu Jun 21 14:14:26 CEST 2018


so that we can drop the special case in the real code,
use the real time in the tests

for that we replace the special string '@DAYS@' with
the correct value, and reset the file afterwards

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 src/PVE/LXC/Setup/Base.pm               |  4 ----
 src/test/run_setup_tests.pl             | 11 ++++++++++-
 src/test/test-debian-009/etc/shadow.exp |  2 +-
 src/test/test-debian-014/etc/shadow.exp |  2 +-
 4 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/src/PVE/LXC/Setup/Base.pm b/src/PVE/LXC/Setup/Base.pm
index 62e37b9..5c69959 100644
--- a/src/PVE/LXC/Setup/Base.pm
+++ b/src/PVE/LXC/Setup/Base.pm
@@ -324,10 +324,6 @@ my $replacepw  = sub {
 
 	my $last_change = int(time()/(60*60*24));
 
-	if ($epw =~ m/^\$TEST\$/) { # for regression tests
-	    $last_change = 12345;
-	}
-	
 	while (defined (my $line = <$src>)) {
 	    if ($shadow) {
 		$line =~ s/^${user}:[^:]*:[^:]*:/${user}:${epw}:${last_change}:/;
diff --git a/src/test/run_setup_tests.pl b/src/test/run_setup_tests.pl
index b103cfa..bae94e8 100755
--- a/src/test/run_setup_tests.pl
+++ b/src/test/run_setup_tests.pl
@@ -12,7 +12,16 @@ use PVE::LXC::Setup;
 sub test_file {
     my ($exp_fn, $real_fn) = @_;
 
-    return if system("diff -u '$exp_fn' '$real_fn'") == 0;
+    # replace @DAYS@ with the current correct value
+    if ($exp_fn =~ m/shadow.exp$/) {
+	my $expecteddays = int(time()/(60*60*24));
+	system ("sed -i.bak 's/\@DAYS\@/$expecteddays/' $exp_fn");
+	my $ret = system("diff -u '$exp_fn' '$real_fn'");
+	system("mv '$exp_fn.bak' '$exp_fn'");
+	return if $ret == 0;
+    } else {
+	return if system("diff -u '$exp_fn' '$real_fn'") == 0;
+    }
 
     die "files do not match\n";
 }
diff --git a/src/test/test-debian-009/etc/shadow.exp b/src/test/test-debian-009/etc/shadow.exp
index deb9e2d..34768b5 100644
--- a/src/test/test-debian-009/etc/shadow.exp
+++ b/src/test/test-debian-009/etc/shadow.exp
@@ -1,4 +1,4 @@
-root:$TEST$ABCDEF:12345:0:99999:7:::
+root:$TEST$ABCDEF:@DAYS@:0:99999:7:::
 daemon:*:15908:0:99999:7:::
 bin:*:15908:0:99999:7:::
 sys:*:15908:0:99999:7:::
diff --git a/src/test/test-debian-014/etc/shadow.exp b/src/test/test-debian-014/etc/shadow.exp
index deb9e2d..34768b5 100644
--- a/src/test/test-debian-014/etc/shadow.exp
+++ b/src/test/test-debian-014/etc/shadow.exp
@@ -1,4 +1,4 @@
-root:$TEST$ABCDEF:12345:0:99999:7:::
+root:$TEST$ABCDEF:@DAYS@:0:99999:7:::
 daemon:*:15908:0:99999:7:::
 bin:*:15908:0:99999:7:::
 sys:*:15908:0:99999:7:::
-- 
2.11.0





More information about the pve-devel mailing list