From fe218a455fefd9d23686d85c403cf2041e30fb24 Mon Sep 17 00:00:00 2001 From: Sebastian Riedel Date: Fri, 22 Dec 2023 14:33:05 +0100 Subject: [PATCH] Hanlde no job group filter matches gracefully This is a followup for #5388 and #5401. When there were no matches for job group globs, no query condition would be generated previously. Giving the false impression that all job groups were matching. So now we just generate an impossible query that cannot match anything with the group id `0`. Progress: https://progress.opensuse.org/issues/134933 --- lib/OpenQA/WebAPI/Controller/Test.pm | 5 ++--- lib/OpenQA/WebAPI/Plugin/Helpers.pm | 11 +++++++++-- t/ui/02-list-group.t | 7 +++++++ t/ui/10-tests_overview.t | 5 +++++ 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/lib/OpenQA/WebAPI/Controller/Test.pm b/lib/OpenQA/WebAPI/Controller/Test.pm index beeca2a8a654..26619aae2a23 100644 --- a/lib/OpenQA/WebAPI/Controller/Test.pm +++ b/lib/OpenQA/WebAPI/Controller/Test.pm @@ -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); diff --git a/lib/OpenQA/WebAPI/Plugin/Helpers.pm b/lib/OpenQA/WebAPI/Plugin/Helpers.pm index 1555163326e9..971d3bcf800f 100644 --- a/lib/OpenQA/WebAPI/Plugin/Helpers.pm +++ b/lib/OpenQA/WebAPI/Plugin/Helpers.pm @@ -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.') @@ -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) { diff --git a/t/ui/02-list-group.t b/t/ui/02-list-group.t index f68551436838..467147adff88 100644 --- a/t/ui/02-list-group.t +++ b/t/ui/02-list-group.t @@ -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; diff --git a/t/ui/10-tests_overview.t b/t/ui/10-tests_overview.t index 4b64f8dc9afb..1753cf44c6b9 100644 --- a/t/ui/10-tests_overview.t +++ b/t/ui/10-tests_overview.t @@ -533,6 +533,11 @@ subtest 'filtering by job group' => sub { my $text = $get_text->('/tests/overview?group_glob=*opensuse*,*SLE*¬_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 {