Skip to content

Commit

Permalink
Add unit test for needle version removal
Browse files Browse the repository at this point in the history
  • Loading branch information
sdclarke committed Feb 1, 2024
1 parent a5daac1 commit e6992d7
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions t/14-grutasks.t
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use Test::Output qw(combined_like combined_unlike);
use OpenQA::Test::Case;
use File::Which 'which';
use File::Path ();
use File::Touch ();
use Mojo::Util qw(dumper);
use Date::Format 'time2str';
use Fcntl ':mode';
Expand Down Expand Up @@ -401,6 +402,19 @@ subtest 'limit_results_and_logs gru task cleans up logs' => sub {
ok !-e $log_file_for_groupless_job, 'log file for groupless job got cleaned';
};

subtest 'remove_needle_versions gru task cleans up needle versions' => sub {
# Create a temporary needle file older than the configured expiry time (defaults to 30 minutes)
my $temp_needle_path = '/tmp/needle_dirs/test_repo/branch/needles';
File::Path->make_path($temp_needle_path);
my @needle_files = ($temp_needle_path . 'needle.png', $temp_needle_path . 'needle.json');
my $ref = File::Touch->new(atime => time - (30 * 60 + 1));
$ref->touch(@needle_files);

# Run cleanup
run_gru_job $t->app, 'remove_needle_versions';
ok !-e $_ for @needle_files;
};

subtest 'limit audit events' => sub {
my $app = $t->app;
my $audit_events = $app->schema->resultset('AuditEvents');
Expand Down

0 comments on commit e6992d7

Please sign in to comment.