hydra/tests/Setup.pm

73 lines
2.1 KiB
Perl
Raw Normal View History

2011-03-16 13:18:12 +00:00
package Setup;
use strict;
use Exporter;
2011-03-17 13:25:27 +00:00
use Hydra::Helper::Nix;
use Hydra::Helper::AddBuilds;
use Cwd;
2011-03-16 13:18:12 +00:00
our @ISA = qw(Exporter);
2011-03-17 13:25:27 +00:00
our @EXPORT = qw(hydra_setup nrBuildsForJobset queuedBuildsForJobset nrQueuedBuildsForJobset createBaseJobset createJobsetWithOneInput evalSucceeds runBuild);
2011-03-16 13:18:12 +00:00
sub hydra_setup {
my ($db) = @_;
$db->resultset('Users')->create({ username => "root", emailaddress => 'root@email.com', password => '' });
}
2011-03-17 11:55:39 +00:00
sub nrBuildsForJobset {
my ($jobset) = @_;
return $jobset->builds->search({},{})->count ;
}
2011-03-17 13:25:27 +00:00
sub queuedBuildsForJobset {
my ($jobset) = @_;
return $jobset->builds->search({},{ join => 'schedulingInfo' });
}
2011-03-17 11:55:39 +00:00
sub nrQueuedBuildsForJobset {
my ($jobset) = @_;
2011-03-17 13:25:27 +00:00
return queuedBuildsForJobset($jobset)->count ;
2011-03-17 11:55:39 +00:00
}
sub createBaseJobset {
my ($jobsetName, $nixexprpath) = @_;
2011-03-17 13:25:27 +00:00
my $project = openHydraDB->resultset('Projects')->update_or_create({name => "tests", displayname => "", owner => "root"});
2011-03-17 11:55:39 +00:00
my $jobset = $project->jobsets->create({name => $jobsetName, nixexprinput => "jobs", nixexprpath => $nixexprpath, emailoverride => ""});
my $jobsetinput;
my $jobsetinputals;
$jobsetinput = $jobset->jobsetinputs->create({name => "jobs", type => "path"});
$jobsetinputals = $jobsetinput->jobsetinputalts->create({altnr => 0, value => getcwd."/jobs"});
return $jobset;
}
sub createJobsetWithOneInput {
my ($jobsetName, $nixexprpath, $name, $type, $uri) = @_;
my $jobset = createBaseJobset($jobsetName, $nixexprpath);
my $jobsetinput;
my $jobsetinputals;
$jobsetinput = $jobset->jobsetinputs->create({name => $name, type => $type});
2011-03-21 12:30:47 +00:00
$jobsetinputals = $jobsetinput->jobsetinputalts->create({altnr => 0, value => $uri});
2011-03-17 11:55:39 +00:00
return $jobset;
}
sub evalSucceeds {
my ($jobset) = @_;
2011-11-30 17:03:50 +00:00
my $res = captureStdoutStderr(60, ("../src/script/hydra-evaluator", $jobset->project->name, $jobset->name));
2011-03-17 11:55:39 +00:00
print STDERR "Evaluation errors for jobset ".$jobset->project->name.":".$jobset->name.": \n".$jobset->errormsg."\n" if $jobset->errormsg;
return $res;
}
2011-03-17 13:25:27 +00:00
sub runBuild {
my ($build) = @_;
2011-11-30 17:03:50 +00:00
return captureStdoutStderr(60, ("../src/script/hydra-build", $build->id));
2011-03-17 13:25:27 +00:00
}
2011-03-16 13:18:12 +00:00
1;