Fix and simplify fedora_release test

Also simplify os_release a bit thanks to the improved spell_
version_number.

Signed-off-by: Adam Williamson <awilliam@redhat.com>
This commit is contained in:
Adam Williamson 2019-08-21 12:15:59 -07:00
parent 23552c777d
commit bf5691e69d
3 changed files with 14 additions and 36 deletions

View File

@ -1034,6 +1034,8 @@ sub check_version {
sub spell_version_number { sub spell_version_number {
my $version = shift; my $version = shift;
# spelt version of Rawhide is...Rawhide
return "Rawhide" if ($version eq 'Rawhide');
my %ones = ( my %ones = (
"0" => "Zero", "0" => "Zero",
"1" => "One", "1" => "One",
@ -1070,7 +1072,8 @@ sub spell_version_number {
} }
sub rec_log { sub rec_log {
my ($line, $condition, $failref) = @_; my ($line, $condition, $failref, $filename) = @_;
$filename ||= '/tmp/os-release.log';
if ($condition) { if ($condition) {
$line = "${line} - SUCCEEDED\n"; $line = "${line} - SUCCEEDED\n";
} }
@ -1078,8 +1081,7 @@ sub rec_log {
push @$failref, $line; push @$failref, $line;
$line = "${line} - FAILED\n"; $line = "${line} - FAILED\n";
} }
my $file = "/tmp/os-release.log"; script_run "echo \"$line\" >> $filename";
script_run "echo \"$line\" >> $file";
} }

View File

@ -10,44 +10,21 @@ use utils;
# Before branching, the parenthesis contain the word "Rawhide". # Before branching, the parenthesis contain the word "Rawhide".
sub run { sub run {
# First, let us define some variables needed to run the program.
my $self = shift; my $self = shift;
# The file to be checked # Version as defined in the VERSION variable.
my $filename = '/etc/fedora-release';
# Version as defined in the RAWREL and VERSION variables. We need both values, because the release
# string can be a combination of those two.
my $version = get_var('VERSION'); my $version = get_var('VERSION');
my $raw_version = get_var('RAWREL');
# Read the content of the file to compare.
my $line = script_output('cat /etc/fedora-release');
chomp $line;
# Create a spelt form of the version number. # Create a spelt form of the version number.
my $speltnum = "undefined"; my $speltnum = spell_version_number($version);
if ($version eq "Rawhide") { if ($version eq "Rawhide") {
$speltnum = "Rawhide"; # this is the Rawhide release number, which we expect to see.
$version = $raw_version; $version = get_var('RAWREL');
}
else {
$speltnum = spell_version_number($version);
} }
# Create the ideal content of the release file # Create the expected content of the release file
# and compare it with its real counterpart. # and compare it with its real counterpart.
# Everything is ok, when that matches, otherwise my $expected = "Fedora release $version ($speltnum)";
# the script fails. validate_script_output 'cat /etc/fedora-release', sub { $_ eq $expected };
my $releasenote = "Fedora release $version ($speltnum)";
my $log = "fedora-release.log";
if ($releasenote eq $line) {
rec_log $log, "The content in /etc/fedora-release should be $releasenote and is $line: PASSED";
upload_logs "/tmp/fedora-release.log", failok=> 1;
}
else {
rec_log $log, "The content in /etc/fedora-release should be $releasenote but is $line: FAILED";
upload_logs "/tmp/fedora-release.log", failok=> 1;
die "The content in /etc/fedora-release should be $releasenote but is $line.";
}
} }
sub test_flags { sub test_flags {

View File

@ -36,6 +36,7 @@ sub run {
my $id = get_var("DISTRI"); # Should be "fedora" my $id = get_var("DISTRI"); # Should be "fedora"
my $name = ucfirst($id); my $name = ucfirst($id);
my $version_id = get_var("VERSION"); # Should be the version number or Rawhide. my $version_id = get_var("VERSION"); # Should be the version number or Rawhide.
my $varstr = spell_version_number($version_id);
my $target = lc($version_id); my $target = lc($version_id);
if ($version_id eq "Rawhide") { if ($version_id eq "Rawhide") {
$version_id = get_var("RAWREL"); $version_id = get_var("RAWREL");
@ -48,8 +49,6 @@ sub run {
# Everything image. # Everything image.
my $variant_id = ""; my $variant_id = "";
my $variant = "generic"; my $variant = "generic";
my $varstr = "Rawhide";
$varstr = spell_version_number($version_id) unless ($target eq 'rawhide');
# now replace the values with the correct ones if we are testing a # now replace the values with the correct ones if we are testing a
# subvariant that maps to a known variant # subvariant that maps to a known variant