api-test: clean up, use subtests
[?]
Apr 28, 2021, 11:41 PM
XNXX4WCQ7KIP24TIF6KQVZLCHM4R25MSSL4IFLFHNUBW5FQSTPWQCDependencies
- [2]
5ZAU6N4Yfixup: api-test.t expected to pass inputs as inputs - [3]
GLJD3PG2api-test.t: make it work under yath - [4]
XWEWQOHVapi-test: use is for nicer errors - [5]
2DGIP6L4Cleanup build serialization - [6]
MMHOJIGDTest whether incorrect passwords are rejected - [7]
WQ2VQ7H3Use hydra-module.nix in the tests - [8]
LZVO64YGMerge in the first bits of the API work - [9]
TZEDUWFXapi-test: make created project and jobset visible - [10]
MIMHJSZKAdd json output for the search API endpoint - [11]
4VYSDP4IAdd eager fetching of relations and enable that for jobset->jobsetinputs - [12]
UOL7YDDLFix test - [13]
ZIIXICG7Make the outputs' outpaths available via the Build JSON API - [14]
5QYMALGUFix Perl error in tests.api - [15]
YI3BZG5NCleanup Jobset serialization - [16]
4YCF3KBGConcurrent hydra-evaluator - [17]
7ECJWNVXCleanup Project model - [18]
MQYHIUEECleanup eval serialization - [19]
KYSBJAYNAllow dashes in jobset input names - [20]
NP7IOJ4QFlesh out the API a bit - [21]
Q3VTDUSQFix the API test - [22]
SYLVCTT6Start api cleanup with the User model - [23]
KSFJOFICMake PathInput plugin cache validity configurable
Change contents
- replacement in t/api-test.t at line 53
my $result = request_json({ uri => "/login", method => "POST", data => { username => "root", password => "wrong" } });is($result->code(), 403, "Incorrect password rejected.");subtest "login" => sub {subtest "bad password" => sub {my $result = request_json({ uri => "/login", method => "POST", data => { username => "root", password => "wrong" } });is($result->code(), 403, "Incorrect password rejected.");}; - replacement in t/api-test.t at line 59
my $result = request_json({ uri => "/login", method => "POST", data => { username => "root", password => "foobar" } });my $result = request_json({ uri => "/login", method => "POST", data => { username => "root", password => "foobar" } }); - replacement in t/api-test.t at line 61
my $user = decode_json($result->content());my $user = decode_json($result->content()); - replacement in t/api-test.t at line 63
is($user->{username}, "root", "The root user is named root");is($user->{userroles}->[0], "admin", "The root user is an admin");$cookie = $result->header("set-cookie");is($user->{username}, "root", "The root user is named root");is($user->{userroles}->[0], "admin", "The root user is an admin");$cookie = $result->header("set-cookie"); - replacement in t/api-test.t at line 67
$user = decode_json(request_json({ uri => "/current-user" })->content());is($user->{username}, "root", "The current user is named root");is($user->{userroles}->[0], "admin", "The current user is an admin");$user = decode_json(request_json({ uri => "/current-user" })->content());is($user->{username}, "root", "The current user is named root");is($user->{userroles}->[0], "admin", "The current user is an admin");}; - replacement in t/api-test.t at line 72
is(request_json({ uri => '/project/sample' })->code(), 404, "Non-existent projects don't exist");subtest "projects" => sub {is(request_json({ uri => '/project/sample' })->code(), 404, "Non-existent projects don't exist"); - replacement in t/api-test.t at line 75
$result = request_json({ uri => '/project/sample', method => 'PUT', data => { displayname => "Sample", enabled => "1", visible => "1", } });is($result->code(), 201, "PUTting a new project creates it");my $result = request_json({ uri => '/project/sample', method => 'PUT', data => { displayname => "Sample", enabled => "1", visible => "1", } });is($result->code(), 201, "PUTting a new project creates it"); - replacement in t/api-test.t at line 78
my $project = decode_json(request_json({ uri => '/project/sample' })->content());my $project = decode_json(request_json({ uri => '/project/sample' })->content()); - replacement in t/api-test.t at line 80
ok((not @{$project->{jobsets}}), "A new project has no jobsets");ok((not @{$project->{jobsets}}), "A new project has no jobsets");}; - replacement in t/api-test.t at line 83
$result = request_json({ uri => '/jobset/sample/default', method => 'PUT', data => { nixexprpath => "default.nix", nixexprinput => "my-src", jobsetinputs => { "my-src" => { type => "path", value => $jobsetdir } }, enabled => "1", visible => "1", checkinterval => "3600"} });is($result->code(), 201, "PUTting a new jobset creates it");subtest "jobsets" => sub {my $result = request_json({ uri => '/jobset/sample/default', method => 'PUT', data => { nixexprpath => "default.nix", nixexprinput => "my-src", jobsetinputs => { "my-src" => { type => "path", value => $jobsetdir } }, enabled => "1", visible => "1", checkinterval => "3600"} });is($result->code(), 201, "PUTting a new jobset creates it"); - replacement in t/api-test.t at line 87
my $jobset = decode_json(request_json({ uri => '/jobset/sample/default' })->content());my $jobset = decode_json(request_json({ uri => '/jobset/sample/default' })->content()); - replacement in t/api-test.t at line 89
ok(exists $jobset->{jobsetinputs}->{"my-src"}, "The new jobset has a 'my-src' input");ok(exists $jobset->{jobsetinputs}->{"my-src"}, "The new jobset has a 'my-src' input"); - replacement in t/api-test.t at line 91
is($jobset->{jobsetinputs}->{"my-src"}->{"jobsetinputalts"}->[0], $jobsetdir, "The 'my-src' input is in $jobsetdir");is($jobset->{jobsetinputs}->{"my-src"}->{"jobsetinputalts"}->[0], $jobsetdir, "The 'my-src' input is in $jobsetdir");}; - replacement in t/api-test.t at line 94
ok(evalSucceeds($db->resultset('Jobsets')->find({ name => 'default' })), "Evaluating should exit with return code 0");subtest "evaluation" => sub {subtest "initial evaluaton" => sub {ok(evalSucceeds($db->resultset('Jobsets')->find({ name => 'default' })), "Evaluating should exit with return code 0"); - replacement in t/api-test.t at line 98[3.217]→[3.38737:38804](∅→∅),[3.553]→[3.38737:38804](∅→∅),[3.1559]→[3.38737:38804](∅→∅),[3.2360]→[3.38737:38804](∅→∅),[3.11616]→[3.38737:38804](∅→∅),[3.38737]→[3.38737:38804](∅→∅),[3.38804]→[3.668:723](∅→∅),[3.723]→[3.38861:38939](∅→∅),[3.38861]→[3.38861:38939](∅→∅),[3.38939]→[3.724:799](∅→∅)
$result = request_json({ uri => '/jobset/sample/default/evals' });is($result->code(), 200, "Can get evals of a jobset");my $evals = decode_json($result->content())->{evals};my $eval = $evals->[0];is($eval->{hasnewbuilds}, 1, "The first eval of a jobset has new builds");my $result = request_json({ uri => '/jobset/sample/default/evals' });is($result->code(), 200, "Can get evals of a jobset");my $evals = decode_json($result->content())->{evals};my $eval = $evals->[0];is($eval->{hasnewbuilds}, 1, "The first eval of a jobset has new builds");}; - replacement in t/api-test.t at line 105
open(my $fh, ">>", "${jobsetdir}/default.nix") or die "didn't open?";say $fh "\n";close $fh;ok(evalSucceeds($db->resultset('Jobsets')->find({ name => 'default' })), "Evaluating should exit with return code 0");subtest "second evaluation" => sub {open(my $fh, ">>", "${jobsetdir}/default.nix") or die "didn't open?";say $fh "\n";close $fh;ok(evalSucceeds($db->resultset('Jobsets')->find({ name => 'default' })), "Evaluating should exit with return code 0"); - replacement in t/api-test.t at line 111[3.293]→[3.39299:39401](∅→∅),[3.1776]→[3.39299:39401](∅→∅),[3.2529]→[3.39299:39401](∅→∅),[3.11694]→[3.39299:39401](∅→∅),[3.39299]→[3.39299:39401](∅→∅),[3.39401]→[3.800:1051](∅→∅)
my $evals = decode_json(request_json({ uri => '/jobset/sample/default/evals' })->content())->{evals};is(scalar(@$evals), 2, "Changing a jobset source creates the second evaluation");isnt($evals->[0]->{jobsetevalinputs}->{"my-src"}->{revision}, $evals->[1]->{jobsetevalinputs}->{"my-src"}->{revision}, "Changing a jobset source changes its revision");my $evals = decode_json(request_json({ uri => '/jobset/sample/default/evals' })->content())->{evals};is(scalar(@$evals), 2, "Changing a jobset source creates the second evaluation");isnt($evals->[0]->{jobsetevalinputs}->{"my-src"}->{revision}, $evals->[1]->{jobsetevalinputs}->{"my-src"}->{revision}, "Changing a jobset source changes its revision"); - replacement in t/api-test.t at line 115[3.710]→[3.498:599](∅→∅),[3.599]→[3.1052:1168](∅→∅),[3.1168]→[3.1777:1919](∅→∅),[3.39798]→[3.1777:1919](∅→∅)
my $build = decode_json(request_json({ uri => "/build/" . $evals->[0]->{builds}->[0] })->content());is($build->{job}, "job", "The build's job name is job");is($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 $build = decode_json(request_json({ uri => "/build/" . $evals->[0]->{builds}->[0] })->content());is($build->{job}, "job", "The build's job name is job");is($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'"); - edit in t/api-test.t at line 120
subtest "search" => sub {my $search_project = decode_json(request_json({ uri => "/search/?query=sample" })->content());is($search_project->{projects}[0]->{name}, "sample", "Search for project 'sample' works"); - replacement in t/api-test.t at line 124
my $search_project = decode_json(request_json({ uri => "/search/?query=sample" })->content());is($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());is($search_build->{builds}[0]->{buildoutputs}->{out}->{path}, $build->{buildoutputs}->{out}->{path}, "Search for builds work");};};}; - edit in t/api-test.t at line 130
my $search_build = decode_json(request_json({ uri => "/search/?query=" . $build->{buildoutputs}->{out}->{path} })->content());is($search_build->{builds}[0]->{buildoutputs}->{out}->{path}, $build->{buildoutputs}->{out}->{path}, "Search for builds work"); - replacement in t/api-test.t at line 131
done_testing;[3.1921]done_testing;