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

t: Avoid tampering with git checkout #5857

Merged
merged 2 commits into from
Aug 14, 2024
Merged
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
20 changes: 14 additions & 6 deletions t/14-grutasks.t
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use Test::Output qw(combined_like combined_unlike);
use OpenQA::Test::Case;
use File::Which 'which';
use File::Path ();
use Mojo::Util qw(dumper);
use Mojo::Util qw(dumper scope_guard);
use Date::Format 'time2str';
use Fcntl ':mode';
use Mojo::File qw(path tempdir);
Expand All @@ -33,15 +33,23 @@ use Mojo::Message::Response;
use Storable qw(store retrieve);
use Mojo::IOLoop;
use Cwd qw(getcwd);
use File::Copy::Recursive qw(dircopy);
use utf8;
use Time::Seconds;

plan skip_all => 'set HEAVY=1 to execute (takes longer)' unless $ENV{HEAVY};

# Avoid tampering with git checkout
my $workdir = tempdir("$FindBin::Script-XXXX", TMPDIR => 1);
my $guard = scope_guard sub { chdir $FindBin::Bin };
chdir $workdir;
mkdir 't';
dircopy "$FindBin::Bin/$_", "$workdir/t/$_" or BAIL_OUT($!) for qw(data testresults fixtures);

# mock asset deletion
# * prevent removing assets from database and file system
# * keep track of calls to OpenQA::Schema::Result::Assets::delete and OpenQA::Schema::Result::Assets::remove_from_disk
my $tempdir = tempdir;
my $tempdir = tempdir("assets-XXXX", TMPDIR => 1);
my $deleted = $tempdir->child('deleted');
my $removed = $tempdir->child('removed');
sub mock_deleted { -e $deleted ? retrieve($deleted) : [] }
Expand Down Expand Up @@ -241,8 +249,8 @@ is(
$assets->update({size => 26 * $gib});
run_gru_job($t->app, 'limit_assets');

is(scalar @{mock_removed()}, 1, "one asset should have been 'removed' at size 26GiB");
is(scalar @{mock_deleted()}, 1, "one asset should have been 'deleted' at size 26GiB");
is(scalar @{mock_removed()}, 1, "asset is 'removed' at size 26GiB");
is(scalar @{mock_deleted()}, 1, "asset is 'deleted' at size 26GiB");

is_deeply(
find_kept_assets_with_last_jobs,
Expand Down Expand Up @@ -275,8 +283,8 @@ reset_mocked_asset_deletions;
$assets->update({size => 34 * $gib});
run_gru_job($t->app, 'limit_assets');

is(scalar @{mock_removed()}, 1, "two assets should have been 'removed' at size 34GiB");
is(scalar @{mock_deleted()}, 1, "two assets should have been 'deleted' at size 34GiB");
is(scalar @{mock_removed()}, 1, "asset is 'removed' at size 34GiB");
is(scalar @{mock_deleted()}, 1, "asset is 'deleted' at size 34GiB");

is_deeply(
find_kept_assets_with_last_jobs,
Expand Down
Loading