HydraTestContext: give a helper for creating a project, jobset, evaluating jobs, and optionally building them.

[?]
Dec 15, 2021, 1:25 AM
7DRV4NOZGDUYSKHE5P2WCUD4Z3CYXDZVJWJD2XWSWTF7VGVNZJHQC

Dependencies

  • [2] OSIBECOE Attempt to fix errors during test teardown

Change contents

  • edit in t/lib/HydraTestContext.pm at line 8
    [2.433]
    [2.433]
    use CliRunners;
  • edit in t/lib/HydraTestContext.pm at line 118
    [2.3495]
    [2.3495]
    # Create a jobset, evaluate it, and optionally build the jobs.
    #
    # In return, you get a hash of all the Builds records, keyed
    # by their Nix attribute name.
    #
    # This always uses an `expression` from the `jobsdir` directory.
    #
    # Hash Parameters:
    #
    # * expression: The file in the jobsdir directory to evaluate
    # * build: Bool. Attempt to build all the resulting jobs. Default: false.
    sub makeAndEvaluateJobset {
    my ($self, %opts) = @_;
    my $expression = $opts{'expression'} || die "Mandatory 'expression' option not passed to makeAndEValuateJobset.";
    my $should_build = $opts{'build'} // 0;
    # Create a new project for this test
    my $project = $self->db()->resultset('Projects')->create({
    name => rand_chars(),
    displayname => rand_chars(),
    owner => "root"
    });
    # Create a new jobset for this test and set up the inputs
    my $jobset = $project->jobsets->create({
    name => rand_chars(),
    nixexprinput => "jobs",
    nixexprpath => $expression,
    emailoverride => ""
    });
    my $jobsetinput = $jobset->jobsetinputs->create({name => "jobs", type => "path"});
    $jobsetinput->jobsetinputalts->create({altnr => 0, value => $self->jobsdir});
    evalSucceeds($jobset) or die "Evaluating jobs/$expression should exit with return code 0";
    my $builds = {};
    for my $build ($jobset->builds) {
    if ($should_build) {
    runBuild($build) or die "Build '".$build->job."' from jobs/$expression should exit with return code 0";
    $build->discard_changes();
    }
    $builds->{$build->job} = $build;
    }
    return $builds;
    }
  • edit in t/lib/HydraTestContext.pm at line 184
    [2.3742]
    [2.3742]
    sub rand_chars {
    return sprintf("%08X", rand(0xFFFFFFFF));
    }