From fe095a56c54623a4bafb2c589e897c5953c04018 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Fri, 14 Jan 2022 13:42:00 -0500 Subject: [PATCH] API: test /nrbuilds and fix jobset / project references --- src/lib/Hydra/Controller/API.pm | 16 +++++++++++++--- t/Hydra/Controller/API/checks.t | 23 +++++++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/lib/Hydra/Controller/API.pm b/src/lib/Hydra/Controller/API.pm index 0a8cfd65..3ddee97a 100644 --- a/src/lib/Hydra/Controller/API.pm +++ b/src/lib/Hydra/Controller/API.pm @@ -160,15 +160,25 @@ sub nrbuilds : Chained('api') PathPart('nrbuilds') Args(0) { my $system = $c->request->params->{system}; my $filter = {finished => 1}; - $filter->{project} = $project if ! $project eq ""; - $filter->{jobset} = $jobset if ! $jobset eq ""; + $filter->{"jobset.project"} = $project if ! $project eq ""; + $filter->{"jobset.name"} = $jobset if ! $jobset eq ""; $filter->{job} = $job if !$job eq ""; $filter->{system} = $system if !$system eq ""; $base = 60*60 if($period eq "hour"); $base = 24*60*60 if($period eq "day"); - my @stats = $c->model('DB::Builds')->search($filter, {select => [{ count => "*" }], as => ["nr"], group_by => ["timestamp - timestamp % $base"], order_by => "timestamp - timestamp % $base DESC", rows => $nr}); + my @stats = $c->model('DB::Builds')->search( + $filter, + { + select => [{ count => "*" }], + as => ["nr"], + group_by => ["timestamp - timestamp % $base"], + order_by => "timestamp - timestamp % $base DESC", + rows => $nr, + join => [ "jobset" ] + } + ); my @arr; push @arr, int($_->get_column("nr")) foreach @stats; @arr = reverse(@arr); diff --git a/t/Hydra/Controller/API/checks.t b/t/Hydra/Controller/API/checks.t index d47f0947..c133f098 100644 --- a/t/Hydra/Controller/API/checks.t +++ b/t/Hydra/Controller/API/checks.t @@ -77,4 +77,27 @@ subtest "/api/latestbuilds" => sub { }; }; +subtest "/api/nrbuilds" => sub { + subtest "with no specific parameters" => sub { + my $response = request(GET '/api/nrbuilds?nr=1&period=hour'); + ok($response->is_success, "The API enpdoint showing the latest builds returns 200."); + + my $data = is_json($response); + is($data, [1]); + }; + + subtest "with very specific parameters" => sub { + my $build = $finishedBuilds->{"one_job"}; + my $projectName = $build->project->name; + my $jobsetName = $build->jobset->name; + my $jobName = $build->job; + my $system = $build->system; + my $response = request(GET "/api/nrbuilds?nr=1&period=hour&project=$projectName&jobset=$jobsetName&job=$jobName&system=$system"); + ok($response->is_success, "The API enpdoint showing the latest builds returns 200."); + + my $data = is_json($response); + is($data, [1]); + }; +}; + done_testing;