From bf5691e69d40c9dde911acb7a6429f7d7f80b17d Mon Sep 17 00:00:00 2001 From: Adam Williamson Date: Wed, 21 Aug 2019 12:15:59 -0700 Subject: [PATCH] Fix and simplify fedora_release test Also simplify os_release a bit thanks to the improved spell_ version_number. Signed-off-by: Adam Williamson --- lib/utils.pm | 8 +++++--- tests/fedora_release.pm | 39 ++++++++------------------------------- tests/os_release.pm | 3 +-- 3 files changed, 14 insertions(+), 36 deletions(-) diff --git a/lib/utils.pm b/lib/utils.pm index 7f095f25..d00adb0e 100644 --- a/lib/utils.pm +++ b/lib/utils.pm @@ -1034,6 +1034,8 @@ sub check_version { sub spell_version_number { my $version = shift; + # spelt version of Rawhide is...Rawhide + return "Rawhide" if ($version eq 'Rawhide'); my %ones = ( "0" => "Zero", "1" => "One", @@ -1070,7 +1072,8 @@ sub spell_version_number { } sub rec_log { - my ($line, $condition, $failref) = @_; + my ($line, $condition, $failref, $filename) = @_; + $filename ||= '/tmp/os-release.log'; if ($condition) { $line = "${line} - SUCCEEDED\n"; } @@ -1078,8 +1081,7 @@ sub rec_log { push @$failref, $line; $line = "${line} - FAILED\n"; } - my $file = "/tmp/os-release.log"; - script_run "echo \"$line\" >> $file"; + script_run "echo \"$line\" >> $filename"; } diff --git a/tests/fedora_release.pm b/tests/fedora_release.pm index eff6cd96..d3888ecf 100644 --- a/tests/fedora_release.pm +++ b/tests/fedora_release.pm @@ -10,44 +10,21 @@ use utils; # Before branching, the parenthesis contain the word "Rawhide". sub run { - # First, let us define some variables needed to run the program. my $self = shift; - # The file to be checked - 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. + # Version as defined in the VERSION variable. 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. - my $speltnum = "undefined"; + my $speltnum = spell_version_number($version); + if ($version eq "Rawhide") { - $speltnum = "Rawhide"; - $version = $raw_version; - } - else { - $speltnum = spell_version_number($version); + # this is the Rawhide release number, which we expect to see. + $version = get_var('RAWREL'); } - # Create the ideal content of the release file + # Create the expected content of the release file # and compare it with its real counterpart. - # Everything is ok, when that matches, otherwise - # the script fails. - 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."; - } + my $expected = "Fedora release $version ($speltnum)"; + validate_script_output 'cat /etc/fedora-release', sub { $_ eq $expected }; } sub test_flags { diff --git a/tests/os_release.pm b/tests/os_release.pm index 3da1f344..0c571013 100644 --- a/tests/os_release.pm +++ b/tests/os_release.pm @@ -36,6 +36,7 @@ sub run { my $id = get_var("DISTRI"); # Should be "fedora" my $name = ucfirst($id); 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); if ($version_id eq "Rawhide") { $version_id = get_var("RAWREL"); @@ -48,8 +49,6 @@ sub run { # Everything image. my $variant_id = ""; 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 # subvariant that maps to a known variant