api-test: clean up, use subtests

[?]
Apr 28, 2021, 11:41 PM
XNXX4WCQ7KIP24TIF6KQVZLCHM4R25MSSL4IFLFHNUBW5FQSTPWQC

Dependencies

  • [2] 5ZAU6N4Y fixup: api-test.t expected to pass inputs as inputs
  • [3] GLJD3PG2 api-test.t: make it work under yath
  • [4] XWEWQOHV api-test: use is for nicer errors
  • [5] 2DGIP6L4 Cleanup build serialization
  • [6] MMHOJIGD Test whether incorrect passwords are rejected
  • [7] WQ2VQ7H3 Use hydra-module.nix in the tests
  • [8] LZVO64YG Merge in the first bits of the API work
  • [9] TZEDUWFX api-test: make created project and jobset visible
  • [10] MIMHJSZK Add json output for the search API endpoint
  • [11] 4VYSDP4I Add eager fetching of relations and enable that for jobset->jobsetinputs
  • [12] UOL7YDDL Fix test
  • [13] ZIIXICG7 Make the outputs' outpaths available via the Build JSON API
  • [14] 5QYMALGU Fix Perl error in tests.api
  • [15] YI3BZG5N Cleanup Jobset serialization
  • [16] 4YCF3KBG Concurrent hydra-evaluator
  • [17] 7ECJWNVX Cleanup Project model
  • [18] MQYHIUEE Cleanup eval serialization
  • [19] KYSBJAYN Allow dashes in jobset input names
  • [20] NP7IOJ4Q Flesh out the API a bit
  • [21] Q3VTDUSQ Fix the API test
  • [22] SYLVCTT6 Start api cleanup with the User model
  • [23] KSFJOFIC Make PathInput plugin cache validity configurable

Change contents

  • replacement in t/api-test.t at line 53
    [3.36937][3.31:150](),[3.150][3.0:58]()
    my $result = request_json({ uri => "/login", method => "POST", data => { username => "root", password => "wrong" } });
    is($result->code(), 403, "Incorrect password rejected.");
    [3.36937]
    [3.210]
    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
    [3.211][3.36937:37057](),[3.36937][3.36937:37057]()
    my $result = request_json({ uri => "/login", method => "POST", data => { username => "root", password => "foobar" } });
    [3.211]
    [3.37057]
    my $result = request_json({ uri => "/login", method => "POST", data => { username => "root", password => "foobar" } });
  • replacement in t/api-test.t at line 61
    [3.37058][3.37058:37102]()
    my $user = decode_json($result->content());
    [3.37058]
    [3.37102]
    my $user = decode_json($result->content());
  • replacement in t/api-test.t at line 63
    [3.37103][3.59:188](),[3.188][3.1006:1047](),[3.2165][3.1006:1047]()
    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");
    [3.37103]
    [3.37244]
    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
    [3.37245][3.37245:37319](),[3.37319][3.189:324]()
    $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");
    [3.37245]
    [3.37466]
    $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
    [3.37467][3.325:423]()
    is(request_json({ uri => '/project/sample' })->code(), 404, "Non-existent projects don't exist");
    [3.37467]
    [3.37567]
    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
    [3.37568][3.0:141](),[3.141][3.424:486]()
    $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");
    [3.37568]
    [3.37757]
    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
    [3.37758][3.37758:37840]()
    my $project = decode_json(request_json({ uri => '/project/sample' })->content());
    [3.37758]
    [3.37840]
    my $project = decode_json(request_json({ uri => '/project/sample' })->content());
  • replacement in t/api-test.t at line 80
    [3.37841][3.37841:37907]()
    ok((not @{$project->{jobsets}}), "A new project has no jobsets");
    [3.37841]
    [3.37907]
    ok((not @{$project->{jobsets}}), "A new project has no jobsets");
    };
  • replacement in t/api-test.t at line 83
    [3.37908][2.0:275](),[2.275][3.487:548](),[3.1317][3.487:548]()
    $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");
    [3.37908]
    [3.38220]
    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
    [3.38221][3.38221:38309]()
    my $jobset = decode_json(request_json({ uri => '/jobset/sample/default' })->content());
    [3.38221]
    [3.38309]
    my $jobset = decode_json(request_json({ uri => '/jobset/sample/default' })->content());
  • replacement in t/api-test.t at line 89
    [3.38310][3.387:474]()
    ok(exists $jobset->{jobsetinputs}->{"my-src"}, "The new jobset has a 'my-src' input");
    [3.38310]
    [3.228]
    ok(exists $jobset->{jobsetinputs}->{"my-src"}, "The new jobset has a 'my-src' input");
  • replacement in t/api-test.t at line 91
    [3.229][3.549:667]()
    is($jobset->{jobsetinputs}->{"my-src"}->{"jobsetinputalts"}->[0], $jobsetdir, "The 'my-src' input is in $jobsetdir");
    [3.229]
    [3.244]
    is($jobset->{jobsetinputs}->{"my-src"}->{"jobsetinputalts"}->[0], $jobsetdir, "The 'my-src' input is in $jobsetdir");
    };
  • replacement in t/api-test.t at line 94
    [3.245][3.1439:1558]()
    ok(evalSucceeds($db->resultset('Jobsets')->find({ name => 'default' })), "Evaluating should exit with return code 0");
    [3.245]
    [3.1558]
    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");
    [3.1559]
    [3.39016]
    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
    [3.39017][3.1560:1775]()
    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");
    [3.39017]
    [3.1775]
    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");
    [3.1776]
    [3.709]
    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'");
    [3.710]
    [3.294]
    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
    [3.295]
    [3.295]
    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
    [3.296][3.296:391](),[3.391][3.1169:1260]()
    my $search_project = decode_json(request_json({ uri => "/search/?query=sample" })->content());
    is($search_project->{projects}[0]->{name}, "sample", "Search for project 'sample' works");
    [3.296]
    [3.484]
    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
    [3.485][3.485:612](),[3.612][3.1261:1389]()
    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
    [3.1921][3.1921:1934]()
    done_testing;
    [3.1921]
    done_testing;