Skip to content

Commit

Permalink
Merge pull request os-autoinst#5857 from perlpunk/tempdir
Browse files Browse the repository at this point in the history
t: Avoid tampering with git checkout
  • Loading branch information
mergify[bot] authored Aug 14, 2024
2 parents 3f88197 + 6fb2c48 commit b24c267
Showing 1 changed file with 14 additions and 6 deletions.
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

0 comments on commit b24c267

Please sign in to comment.