Skip to content

Commit 158e856

Browse files
committed
Add unit test for get-info build endpoint.
1 parent 8423bff commit 158e856

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

src/lib/Hydra/Controller/Build.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ sub bump : Chained('buildChain') PathPart('bump') {
569569
$c->res->redirect($c->uri_for($self->action_for("build"), $c->req->captures));
570570
}
571571

572-
572+
# This function is reused in the unit test.
573573
sub buildStepToHash {
574574
my ($buildstep) = @_;
575575
return {

t/Hydra/Controller/Build/api.t

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,47 @@ subtest "accessing the constituents API" => sub {
102102
is($buildB->{job}, "b");
103103
};
104104

105+
subtest "accessing the get-info API" => sub {
106+
my $url = $build_url . "/api/get-info";
107+
108+
my $build_info = request(GET $url,
109+
Accept => 'application/json',
110+
);
111+
112+
ok($build_info->is_success, "Getting the build info");
113+
114+
my $data;
115+
my $valid_json = lives { $data = decode_json($build_info->content); };
116+
ok($valid_json, "We get back valid JSON.");
117+
if (!$valid_json) {
118+
use Data::Dumper;
119+
print STDERR Dumper $build_info->content;
120+
}
121+
122+
# Query the build steps from the aggregate build and create the expected list of results.
123+
my @buildsteps = $aggregateBuild->buildsteps->search({}, {order_by => "stepnr asc"});
124+
my @buildsteplist;
125+
push @buildsteplist, Hydra::Controller::Build::buildStepToHash($_) foreach @buildsteps;
126+
127+
# Create the expected output with the build step information in it.
128+
my $expected = {
129+
project => "tests",
130+
jobset => "aggregate",
131+
outPath => $aggregateBuild->buildoutputs->find({ name => "out" })->path,
132+
buildstatus => 0,
133+
drvPath => $aggregateBuild->drvpath,
134+
buildId => $aggregateBuild->id,
135+
priority => undef,
136+
finished => 1,
137+
id => $aggregateBuild->id,
138+
job => "aggregate",
139+
nixname => "aggregate",
140+
timestamp => $aggregateBuild->timestamp,
141+
system => $aggregateBuild->system,
142+
steps => \@buildsteplist,
143+
};
144+
145+
is($data, $expected, "The build's info JSON matches our API.");
146+
};
147+
105148
done_testing;

0 commit comments

Comments
 (0)