Skip to content

Commit

Permalink
Merge pull request #5411 from os-autoinst/k/group_filters_no_match
Browse files Browse the repository at this point in the history
Handle no job group filter matches gracefully
  • Loading branch information
mergify[bot] committed Dec 22, 2023
2 parents ecad4cb + 220ada2 commit b96c049
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
5 changes: 2 additions & 3 deletions lib/OpenQA/WebAPI/Controller/Test.pm
Expand Up @@ -719,9 +719,8 @@ sub _prepare_job_results ($self, $all_jobs, $limit) {
}

sub _prepare_groupids ($self) {
if (my @groups = $self->groups_for_globs) {
return [map { $_->id } @groups];
}
return [0] unless my $groups = $self->groups_for_globs;
return [map { $_->id } @$groups] if @$groups;

my $v = $self->validation;
$v->optional('groupid')->num(0, undef);
Expand Down
11 changes: 9 additions & 2 deletions lib/OpenQA/WebAPI/Plugin/Helpers.pm
Expand Up @@ -439,7 +439,11 @@ sub _compose_job_overview_search_args ($c) {
@groups = $schema->resultset('JobGroups')->search(\@search_terms)->all;
}

else { @groups = $c->groups_for_globs }
else {
my $groups = $c->groups_for_globs;
if (defined $groups) { @groups = @$groups }
else { $search_args{groupids} = [0] }
}

# add flash message if optional "groupid" parameter is invalid
$c->stash(flash_error => 'Specified "groupid" is invalid and therefore ignored.')
Expand Down Expand Up @@ -503,9 +507,12 @@ sub _groups_for_globs ($c) {
@groups = $c->schema->resultset('JobGroups')->all;
@groups = grep { _match_group(\@inclusive, $_) } @groups if @inclusive;
@groups = grep { !_match_group(\@exclusive, $_) } @groups if @exclusive;

# No matches at all needs to be a special case to be handled gracefully by the caller
return undef unless @groups;
}

return @groups;
return \@groups;
}

sub _match_group ($regexes, $group) {
Expand Down
7 changes: 7 additions & 0 deletions t/ui/02-list-group.t
Expand Up @@ -144,6 +144,13 @@ subtest 'group_glob and not_group_glob' => sub {
is @rows, 1, 'one job';
ok $driver->find_element('#results #job_99953'), '99953 listed';
};

subtest 'filter with glob and no match' => sub {
ok $driver->get('/tests?group_glob=does_not_exist'), 'list jobs';
wait_for_ajax(msg => 'wait for test list');
my @rows = $driver->find_child_elements($driver->find_element('#results tbody'), 'tr');
like $rows[0]->get_text, qr/No data available in table/, 'no results';
};
};

kill_driver;
Expand Down
5 changes: 5 additions & 0 deletions t/ui/10-tests_overview.t
Expand Up @@ -533,6 +533,11 @@ subtest 'filtering by job group' => sub {
my $text = $get_text->('/tests/overview?group_glob=*opensuse*,*SLE*&not_group_glob=*development*');
like $text, qr/Summary of opensuse, opensuse test, SLE 15 SP5 build/, 'job group match';
};

subtest 'filter with glob and no match' => sub {
my $text = $get_text->('/tests/overview?group_glob=does_not_exist');
like $text, qr/Overall Summary of multiple distri\/version/, 'no match';
};
};

subtest "job template names displayed on 'Test result overview' page" => sub {
Expand Down

0 comments on commit b96c049

Please sign in to comment.