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

Handle no job group filter matches gracefully #5411

Merged
merged 1 commit into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
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
5 changes: 2 additions & 3 deletions lib/OpenQA/WebAPI/Controller/Test.pm
Original file line number Diff line number Diff line change
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;

Comment on lines +722 to 724
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks even cleaner than before, nice! :)

my $v = $self->validation;
$v->optional('groupid')->num(0, undef);
Expand Down
11 changes: 9 additions & 2 deletions lib/OpenQA/WebAPI/Plugin/Helpers.pm
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading