Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tidy check to the test suite #359

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions script/elevate-cpanel.PL
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tidy only changes.

Original file line number Diff line number Diff line change
Expand Up @@ -625,13 +625,15 @@ of your server before proceeding.
EOS

if ( !$self->getopt('non-interactive') ) {
if ( !IO::Prompt::prompt(
'-one_char',
'-yes_no',
'-tty',
-default => 'n',
"Do you wish to proceed with the upgrade process [y/N]: ",
) ) {
if (
!IO::Prompt::prompt(
'-one_char',
'-yes_no',
'-tty',
-default => 'n',
"Do you wish to proceed with the upgrade process [y/N]: ",
)
) {
INFO("The update process has been canceled");
exit 0;
}
Expand Down
14 changes: 8 additions & 6 deletions t/blocker-DiskSpace.t
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tidy only changes.

Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,12 @@ is $check, 0, "_disk_space_check failure - /usr/local/cpanel 1.4 G";

is(
$blockers->blockers,
[ {
id => q[Elevate::Blockers::DiskSpace::check],
msg => "disk space issue",
} ],
[
{
id => q[Elevate::Blockers::DiskSpace::check],
msg => "disk space issue",
}
],
q{Block if disk space issues.}
);

Expand All @@ -146,8 +148,8 @@ exit;

sub check_blocker (@args) { # helper for test...

my $blockers = cpev->new( @args )->blockers;
my $ds = $blockers->_get_blocker_for('DiskSpace');
my $blockers = cpev->new(@args)->blockers;
my $ds = $blockers->_get_blocker_for('DiskSpace');

return $ds->check;
}
9 changes: 5 additions & 4 deletions t/blocker-Python.t
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tidy only changes.

Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,23 @@ use Test::MockModule qw{strict};
use Elevate::Blockers::Python ();

{

package bogus::cpev;
sub _abort_on_first_blocker { return 0 }
}

my %mocks = map { $_ => Test::MockModule->new($_); } qw{
Cpanel::Pkgr
Elevate::Blockers
Elevate::Blockers::Base
Cpanel::Pkgr
Elevate::Blockers
Elevate::Blockers::Base
};
$mocks{'Cpanel::Pkgr'}->redefine( "what_provides" => '', "is_installed" => 1 );
my $obj = bless {}, 'Elevate::Blockers::Python';
ok( !$obj->check(), "Returns early on no provider of python36" );
$mocks{'Cpanel::Pkgr'}->redefine( "what_provides" => 'python3', "is_installed" => 0 );
ok( !$obj->check(), "Returns early on python36 not installed" );
$mocks{'Cpanel::Pkgr'}->redefine( "is_installed" => 1 );
$mocks{'Elevate::Blockers'}->redefine("new" => sub { return bless {}, $_[0] });
$mocks{'Elevate::Blockers'}->redefine( "new" => sub { return bless {}, $_[0] } );
$mocks{'Elevate::Blockers::Base'}->redefine(
"cpev" => sub { return bless {}, 'bogus::cpev' },
);
Expand Down
11 changes: 5 additions & 6 deletions t/blocker-Repositories.t
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tidy only changes.

Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,15 @@ EOS
$cpev_mock->redefine( get_installed_rpms_in_repo => sub { return () } );

my $mock_json = Test::MockModule->new('Cpanel::JSON');
$mock_json->redefine('Dump' => 'foo');
$mock_json->redefine( 'Dump' => 'foo' );
is $yum->_check_yum_repos() => { $unused_repo_enabled => 1, $unvetted => 1 }, "Using an unknown enabled repo detected";
$cpev_mock->redefine( get_installed_rpms_in_repo => 1 );
is $yum->_check_yum_repos() => { $unvetted => 1, $rpms_from_unvetted => 1 }, "Using an unknown enabled repo with installed packages detected";
is $yum->{_yum_repos_unsupported_with_packages}[0],
{
'json_report' => '{"name":"MyRepo","packages":["1"],"path":"/etc/yum.repos.d/Unknown.repo"}',
'name' => 'MyRepo'
}
,
{
'json_report' => '{"name":"MyRepo","packages":["1"],"path":"/etc/yum.repos.d/Unknown.repo"}',
'name' => 'MyRepo'
},
"Names and JSON data of repos are recorded in object";

$cpev_mock->redefine( get_installed_rpms_in_repo => sub { return () } );
Expand Down
28 changes: 15 additions & 13 deletions t/components-AbsoluteSymlink.t
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tidy only changes.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use Test2::Bundle::Extended;
use Test2::Tools::Explain;
use Test2::Plugin::NoWarnings;
use Test::MockModule qw{strict};
use Test::MockFile qw{strict};
use Test::MockFile qw{strict};

use Elevate::Components::AbsoluteSymlinks ();

Expand All @@ -20,28 +20,30 @@ my %cabinet;
$cabinet{'/smang'} = Test::MockFile->symlink( "/home", "/smang" );

my $obj = bless {}, 'Elevate::Components::AbsoluteSymlinks';
ok(!$obj->post_leapp(), "Nothing to do post leapp" );
is({$obj->get_abs_symlinks()},{'/smang' => '/home'}, "Got expected from get_abs_symlinks");
ok( !$obj->post_leapp(), "Nothing to do post leapp" );
is( { $obj->get_abs_symlinks() }, { '/smang' => '/home' }, "Got expected from get_abs_symlinks" );
SKIP: {
skip "Test::MockFile doesn't yet properly handle symlinks", 1;
$cabinet{'/smang-what_u_mean'} = Test::MockFile->symlink( undef, "/smang-what_u_mean" );

# Test::MockFile doesn't seem to know what to do about overwriting symlinks
# so we need to help out File::Copy here
$mocks{'File::Copy'}->redefine( "move" => sub {
my ( $from, $to ) = @_;
undef $cabinet{$to};
my $tarjeta = $cabinet{$from}->readlink();
$cabinet{$to} = Test::MockFile->symlink( $tarjeta, $to );
undef $cabinet{$from};
return 1;
});
$mocks{'File::Copy'}->redefine(
"move" => sub {
my ( $from, $to ) = @_;
undef $cabinet{$to};
my $tarjeta = $cabinet{$from}->readlink();
$cabinet{$to} = Test::MockFile->symlink( $tarjeta, $to );
undef $cabinet{$from};
return 1;
}
);

# XXX TODO figure out what the heck is needed to make the `symlink` builtin
# in perl react properly to the existence of Test::MockModule->symlink objects
# As it stands, this makes the symlink then bombs out with
# 'readlink is only supported for symlinks'.
$obj->pre_leapp();
is( readlink( "/smang" ), 'home', "Symlink corrected by pre_leapp" );
};
is( readlink("/smang"), 'home', "Symlink corrected by pre_leapp" );
}
done_testing();
1 change: 1 addition & 0 deletions t/cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ on 'test' => sub {
recommends "Devel::Cover";
recommends "Template";
recommends "JSON::MaybeXS";
recommends "Test::PerlTidy";
};
6 changes: 6 additions & 0 deletions t/tidy.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/local/cpanel/3rdparty/bin/perl
# HARNESS-DURATION-LONG

use Test::PerlTidy qw( run_tests );

run_tests();