From dd1e4a92c011bda8dc1684f36ac6ac1c1409e82e Mon Sep 17 00:00:00 2001 From: Antoine Eiche Date: Wed, 31 Oct 2018 18:44:16 +0100 Subject: [PATCH 1/2] api-test: make created project and jobset visible --- tests/api-test.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/api-test.pl b/tests/api-test.pl index 66b4c55c..3bebd621 100644 --- a/tests/api-test.pl +++ b/tests/api-test.pl @@ -34,14 +34,14 @@ ok($user->{userroles}->[0] eq "admin", "The current user is an admin"); ok(request_json({ uri => '/project/sample' })->code() == 404, "Non-existent projects don't exist"); -$result = request_json({ uri => '/project/sample', method => 'PUT', data => { displayname => "Sample", enabled => "1", } }); +$result = request_json({ uri => '/project/sample', method => 'PUT', data => { displayname => "Sample", enabled => "1", visible => "1", } }); ok($result->code() == 201, "PUTting a new project creates it"); my $project = decode_json(request_json({ uri => '/project/sample' })->content()); ok((not @{$project->{jobsets}}), "A new project has no jobsets"); -$result = request_json({ uri => '/jobset/sample/default', method => 'PUT', data => { nixexprpath => "default.nix", nixexprinput => "my-src", inputs => { "my-src" => { type => "path", value => "/run/jobset" } }, enabled => "1", checkinterval => "3600"} }); +$result = request_json({ uri => '/jobset/sample/default', method => 'PUT', data => { nixexprpath => "default.nix", nixexprinput => "my-src", inputs => { "my-src" => { type => "path", value => "/run/jobset" } }, enabled => "1", visible => "1", checkinterval => "3600"} }); ok($result->code() == 201, "PUTting a new jobset creates it"); my $jobset = decode_json(request_json({ uri => '/jobset/sample/default' })->content()); From 0d2a2d8923a418b0bf9660e65c127925a9c9c420 Mon Sep 17 00:00:00 2001 From: Antoine Eiche Date: Wed, 31 Oct 2018 18:46:33 +0100 Subject: [PATCH 2/2] Add json output for the search API endpoint This commit also add a test of this feature. Note the search JSON output doesn't contain any jobs because they can not be exported to JSON yet. The JSON output on a search query matching a build looks like: ``` { "builds": [ { "buildoutputs": { "out": { "path": "/nix/store/wdag3pznrvqk01byk989irg7rq3q2a2c-job" } }, "finished": 0, "releasename": null, "starttime": null, "project": "sample", "buildproducts": {}, "timestamp": 1541007629, "buildstatus": null, "nixname": "job", "drvpath": "/nix/store/n9zqndn7j7nyr6gg3bmxvw26cfmdwv2n-job.drv", "job": "job", "id": 1, "stoptime": null, "priority": 100, "system": "x86_64-linux", "jobsetevals": [ 1 ], "jobset": "default", "buildmetrics": {} } ], "projects": [], "jobsets": [], "buildsdrv": [] } ``` --- src/lib/Hydra/Controller/Root.pm | 5 +++++ tests/api-test.pl | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/lib/Hydra/Controller/Root.pm b/src/lib/Hydra/Controller/Root.pm index 146c37a4..19bb6fa9 100644 --- a/src/lib/Hydra/Controller/Root.pm +++ b/src/lib/Hydra/Controller/Root.pm @@ -419,6 +419,11 @@ sub search :Local Args(0) { $c->stash->{buildsdrv} = [ $c->model('DB::Builds')->search( { "drvpath" => trim($query) }, { order_by => ["id desc"] } ) ]; + + $c->stash->{resource} = { projects => $c->stash->{projects}, + jobsets => $c->stash->{jobsets}, + builds => $c->stash->{builds}, + buildsdrv => $c->stash->{buildsdrv} }; } sub serveLogFile { diff --git a/tests/api-test.pl b/tests/api-test.pl index 3bebd621..b516f736 100644 --- a/tests/api-test.pl +++ b/tests/api-test.pl @@ -1,6 +1,6 @@ use LWP::UserAgent; use JSON; -use Test::Simple tests => 17; +use Test::Simple tests => 19; my $ua = LWP::UserAgent->new; $ua->cookie_jar({}); @@ -65,3 +65,10 @@ my $build = decode_json(request_json({ uri => "/build/" . $evals->[0]->{builds}- ok($build->{job} eq "job", "The build's job name is job"); ok($build->{finished} == 0, "The build isn't finished yet"); ok($build->{buildoutputs}->{out}->{path} =~ /^\/nix\/store\/[a-zA-Z0-9]{32}-job$/, "The build's outpath is in the Nix store and named 'job'"); + + +my $search_project = decode_json(request_json({ uri => "/search/?query=sample" })->content()); +ok($search_project->{projects}[0]->{name} == "sample", "Search for project 'sample' works"); + +my $search_build = decode_json(request_json({ uri => "/search/?query=" . $build->{buildoutputs}->{out}->{path} })->content()); +ok($search_build->{builds}[0]->{buildoutputs}->{out}->{path} == $build->{buildoutputs}->{out}->{path}, "Search for builds work");