Skip to content

Commit 3f0094d

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

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-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: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,48 @@ 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+
my $buildstep_length = @buildsteplist;
127+
128+
# Create the expected output with the build step information in it.
129+
my $expected = {
130+
project => "tests",
131+
jobset => "aggregate",
132+
outPath => $aggregateBuild->buildoutputs->find({ name => "out" })->path,
133+
buildstatus => 0,
134+
drvPath => $aggregateBuild->drvpath,
135+
buildId => $aggregateBuild->id,
136+
priority => undef,
137+
finished => 1,
138+
id => $aggregateBuild->id,
139+
job => "aggregate",
140+
nixname => "aggregate",
141+
timestamp => $aggregateBuild->timestamp,
142+
system => $aggregateBuild->system,
143+
steps => \@buildsteplist,
144+
};
145+
146+
is($data, $expected, "The build's info JSON matches our API.");
147+
};
148+
105149
done_testing;

0 commit comments

Comments
 (0)