api-test.t: make it work under yath

[?]
Apr 28, 2021, 10:24 PM
GLJD3PG2EYSB7EWYWEU57TYJQB6VDP2CJF6OLFEFIWZAY7OBXMMAC

Dependencies

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

Change contents

  • replacement in t/api-test.t at line 1
    [6.36450][6.36451:36471]()
    use LWP::UserAgent;
    [6.36450]
    [6.36471]
    use strict;
    use Setup;
  • replacement in t/api-test.t at line 4
    [6.36481][5.533:563]()
    use Test::Simple tests => 20;
    [6.36481]
    [6.36511]
    use File::Copy;
    my %ctx = test_init(
    hydra_config => q|
    # No caching for PathInput plugin, otherwise we get wrong values
    # (as it has a 30s window where no changes to the file are considered).
    path_input_cache_validity_seconds = 0
    |
    );
    my $jobsetdir = $ctx{tmpdir} . '/jobset';
    mkdir($jobsetdir);
    copy($ctx{jobsdir} . '/api-test.nix', "$jobsetdir/default.nix");
    require Hydra::Schema;
    use HTTP::Request::Common;
    use Test2::V0;
    require Catalyst::Test;
    Catalyst::Test->import('Hydra');
    my $db = Hydra::Model::DB->new;
    hydra_setup($db);
    {
    my $user = $db->resultset('Users')->find({ username => 'root' });
    $user->setPassword('foobar');
    $user->userroles->update_or_create({ role => 'admin' });
    }
  • replacement in t/api-test.t at line 35
    [6.36512][6.36512:36563]()
    my $ua = LWP::UserAgent->new;
    $ua->cookie_jar({});
    [6.36512]
    [6.36563]
    my $cookie = "";
  • replacement in t/api-test.t at line 41
    [6.36682][6.36682:36734]()
    $req->uri("http://localhost:3000$opts->{uri}");
    [6.36682]
    [6.36734]
    $req->uri("http://localhost$opts->{uri}");
  • replacement in t/api-test.t at line 43
    [6.36782][3.0:84]()
    $req->header(Referer => "http://localhost:3000/") if $opts->{method} eq "POST";
    [6.36782]
    [6.36782]
    $req->header(Content_Type => "application/json");
    $req->header(Origin => "http://localhost/") if $opts->{method} eq "POST";
    $req->header(Cookie => $cookie);
  • replacement in t/api-test.t at line 48
    [6.36854][6.36854:36888]()
    my $res = $ua->request($req);
    [6.36854]
    [6.36888]
    my $res = request($req);
  • edit in t/api-test.t at line 62
    [6.2165]
    [6.37244]
    $cookie = $result->header("set-cookie");
  • replacement in t/api-test.t at line 77
    [6.37908][4.142:414]()
    $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"} });
    [6.37908]
    [6.38157]
    $result = request_json({ uri => '/jobset/sample/default', method => 'PUT', data => { nixexprpath => "default.nix", nixexprinput => "my-src", inputs => { "my-src" => { type => "path", value => $jobsetdir } }, enabled => "1", visible => "1", checkinterval => "3600"} });
  • replacement in t/api-test.t at line 84
    [6.229][6.475:597]()
    ok($jobset->{jobsetinputs}->{"my-src"}->{jobsetinputalts}->[0] eq "/run/jobset", "The 'my-src' input is in /run/jobset");
    [6.229]
    [6.244]
    ok($jobset->{jobsetinputs}->{"my-src"}->{"jobsetinputalts"}->[0] eq $jobsetdir, "The 'my-src' input is in $jobsetdir");
  • replacement in t/api-test.t at line 86
    [6.245][2.11572:11616]()
    system("hydra-eval-jobset sample default");
    [6.245]
    [6.38737]
    ok(evalSucceeds($db->resultset('Jobsets')->find({ name => 'default' })), "Evaluating should exit with return code 0");
  • replacement in t/api-test.t at line 94
    [6.39017][2.11617:11694]()
    system("echo >> /run/jobset/default.nix; hydra-eval-jobset sample default");
    [6.39017]
    [6.39299]
    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 107
    [6.39798][6.294:437]()
    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'");
    [6.39798]
    [6.294]
    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 115
    [6.742]
    done_testing;