1
0
mirror of https://pagure.io/fedora-qa/os-autoinst-distri-fedora.git synced 2024-11-29 17:13:09 +00:00
os-autoinst-distri-fedora/tests/dnf5/list.pm
2023-07-18 10:49:06 +02:00

120 lines
4.6 KiB
Perl

use base "installedtest";
use strict;
use testapi;
use utils;
use dnf;
# This script will make sure that DNF5 is able to
# list the packages via dnf list.
# http://fedoraproject.org/wiki/QA:Testcase_DNF_list
sub run {
my $self = shift;
# First, we will look for available packages. This search should result
# in a list of all available packages which is almost 70000 in standard
# Fedora repositories.
# We will list all those packages and count them via wc, then we will
# decide what to do with them.
my $count = script_output("dnf5 list --available | wc -l", timeout => 120);
# Now, if there are more than 60000 packages, we assume that it is correct.
if ($count > 60000) {
record_info("Packages counted", "It seems that the number of available packages is realistic ($count)");
}
elsif ($count > 20000) {
record_info("Warning", "The number of available packages seems a little to low. Check that repositories are correctly enabled.");
}
elsif ($count > 1000) {
record_soft_failure("The number of available packages is critically low, check the repositories.");
}
else {
die("The number of available packages does not meet any expectations, either there are no repositories or the tested command does not work correctly.");
}
# Also list available packages and look for a certain keyword to see that real packages are listed
assert_script_run("dnf5 list --available | grep firefox");
assert_script_run("dnf5 list --available | grep vim");
assert_script_run("dnf5 list --available | grep bash");
assert_script_run("dnf5 list --available | grep python3");
assert_script_run("dnf5 list --available | grep gimp");
# Second, we will list installed packages. The Fedora custom installation has slightly above 400
# packages, if the count matches, we can assume the command worked correctly.
$count = script_output("dnf5 list --installed | wc -l", timeout => 60);
if ($count > 400) {
record_info("Packages counted", "It seems that the number of listed packages is realistic ($count).");
}
else {
die("The number of installed packages is too low, the tested system might be corrupted.");
}
# Third, we will try to list a single package. If grep finds the name, we can assume that the
# package was listed.
assert_script_run("dnf5 list inkscape | grep inkscape");
# The --showduplicates switch shows all available packages. The output is divided into Installed
# and Available packages. With the kernel package, we know that it is installed for sure.
# There will be one installed package and one or more available packages. If more, we know
# the command works as expected.
my $output = script_output("dnf5 list kernel --showduplicates");
my @olist = split("\n", $output);
my ($installed, $available) = (0, 0);
my $a = 0;
# Let's go over the output
foreach (@olist) {
# Switch to installed if the label found.
if ($_ =~ /Installed/) {
$a = 0;
}
# Switch to available if the label found.
elsif ($_ =~ /Available/) {
$a = 1;
}
# When package line found, count it based on
# which mode we are in.
else {
if ($_ =~ /kernel/) {
$installed += 1 if ($a == 0);
$available += 1 if ($a == 1);
}
}
}
# Now, die under certain conditions
if ($installed != 1) {
die("Either no kernel or more kernels are installed which indicates an error in the command.");
}
if ($available == 1) {
record_soft_failure("There is only one available kernel package which is not an error, but we could not test if --showduplicates really work either.");
}
elsif ($available > 1) {
record_info("Argument OK", "The --showduplicates argument works normally.");
}
else {
die("There are problems with the --showduplicates argument.");
}
# Now, we test that we can list packages with --recent, we will grep for the word updates
# because that is the repository where new packages are expected.
assert_script_run("dnf5 list --recent | grep updates");
# And test that we can list new updates with --updates, however we will not know if
# there will be updates, so just running the command successfully will do.
assert_script_run("dnf5 list --updates | grep 'Repositories loaded'");
}
sub test_flags {
return {always_rollback => 1};
}
my $output = `dnf5 search python3-koza`;
print($output);
if ($output =~ /No matches found/) {
print("Package not found.\n");
}
1;
# vim: set sw=4 et: