add tests for scm inputs

This commit is contained in:
Rob Vermaas 2011-03-17 08:48:27 +00:00
parent 98c8a86886
commit 369b2ef0aa
10 changed files with 100 additions and 6 deletions

View file

@ -7,6 +7,7 @@ TESTS_ENVIRONMENT = \
NIX_STORE_DIR="$(abs_builddir)/nix/store" \
NIX_LOG_DIR="$(abs_builddir)/nix/var/log/nix" \
PERL5LIB="$(srcdir):$(top_srcdir)/src/lib:$$PERL5LIB" \
PATH=$(abs_top_srcdir)/src/script:$$PATH \
perl -w
EXTRA_DIST = \
@ -20,14 +21,14 @@ TESTS = \
clean :
chmod -R a+w nix
rm -rf db.sqlite data nix git-repo hg-repo svn-repo svn-checkout bzr-repo
rm -rf db.sqlite data nix git-repo hg-repo svn-repo svn-checkout svn-checkout-repo bzr-repo bzr-checkout-repo
$(TESTS) : db.sqlite dirs
db.sqlite : $(top_srcdir)/src/sql/hydra-sqlite.sql
sqlite3 db.sqlite < $(top_srcdir)/src/sql/hydra-sqlite.sql
dirs : git-repo hg-repo svn-repo bzr-repo
dirs : git-repo hg-repo svn-repo svn-checkout-repo bzr-repo bzr-checkout-repo
mkdir -p data
touch data/hydra.conf
mkdir -p nix
@ -58,3 +59,8 @@ bzr-repo :
bzr add bzr-repo/bzr-file
bzr commit -m "add bzr-file" bzr-repo/bzr-file
svn-checkout-repo :
ln -s svn-repo svn-checkout-repo
bzr-checkout-repo :
ln -s bzr-repo bzr-checkout-repo

View file

@ -10,7 +10,7 @@ use Setup;
my $db = openHydraDB;
use Test::Simple tests => 1;
use Test::Simple tests => 14;
hydra_setup($db);
@ -18,14 +18,47 @@ my $res;
my $stdout;
my $stderr;
my $jobsBaseUri = "file://".getcwd;
my $project = $db->resultset('Projects')->create({name => "tests", displayname => "", owner => "root"});
my $jobset = $project->jobsets->create({name => "basic", nixexprinput => "input", nixexprpath => "basic.nix", emailoverride => ""});
my $jobsetinput = $jobset->jobsetinputs->create({name => "input", type => "path"});
sub nrBuildsForJobset {
my ($project, $jobset) = @_;
return $db->resultset('Builds')->search({ project => $project, jobset => $jobset},{})->count ;
}
sub createJobsetWithOneSCMInput {
my ($jobsetName, $nixexprpath, $type, $uri) = @_;
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"});
$jobsetinput = $jobset->jobsetinputs->create({name => "src", type => $type});
$jobsetinputals = $jobsetinput->jobsetinputalts->create({altnr => 0, value => $uri});
}
sub evalSucceeds {
my ($project, $jobset) = @_;
return captureStdoutStderr(60, ("../src/script/hydra_evaluator.pl", $project, $jobset));
}
my $jobset = $project->jobsets->create({name => "basic", nixexprinput => "jobs", nixexprpath => "basic.nix", emailoverride => ""});
my $jobsetinput = $jobset->jobsetinputs->create({name => "jobs", type => "path"});
my $jobsetinputals = $jobsetinput->jobsetinputalts->create({altnr => 0, value => getcwd."/jobs"});
($res, $stdout, $stderr) = captureStdoutStderr(60, ("../src/script/hydra_evaluator.pl", "tests", "basic"));
ok($res, "Evaluating jobs/basic.nix should exit with return code 0");
ok( nrBuildsForJobset("tests", "basic") == 3 , "Evaluating jobs/basic.nix should result in 3 builds");
my @scminputs = ("svn", "svn-checkout", "git", "bzr", "bzr-checkout", "hg");
foreach my $scm (@scminputs) {
createJobsetWithOneSCMInput($scm, "$scm-input.nix", $scm, "$jobsBaseUri/$scm-repo");
ok(evalSucceeds("tests", $scm), "Evaluating jobs/$scm-input.nix should exit with return code 0.");
ok(nrBuildsForJobset("tests", $scm) == 1, "Evaluating jobs/$scm-input.nix should result in 1 build")
}

View file

@ -1,4 +1,3 @@
{ input }:
{
empty_dir =
derivation {

View file

@ -0,0 +1,9 @@
{ src }:
{
copy =
derivation {
name = "bzr-checkout-input";
system = builtins.currentSystem;
builder = ./scm-builder.sh;
};
}

9
tests/jobs/bzr-input.nix Normal file
View file

@ -0,0 +1,9 @@
{ src }:
{
copy =
derivation {
name = "bzr-input";
system = builtins.currentSystem;
builder = ./scm-builder.sh;
};
}

9
tests/jobs/git-input.nix Normal file
View file

@ -0,0 +1,9 @@
{ src }:
{
copy =
derivation {
name = "git-input";
system = builtins.currentSystem;
builder = ./scm-builder.sh;
};
}

9
tests/jobs/hg-input.nix Normal file
View file

@ -0,0 +1,9 @@
{ src }:
{
copy =
derivation {
name = "hg-input";
system = builtins.currentSystem;
builder = ./scm-builder.sh;
};
}

View file

@ -0,0 +1,2 @@
mkdir $out
cp -v $src/* $out/

View file

@ -0,0 +1,9 @@
{ src }:
{
copy =
derivation {
name = "bzr-checkout-input";
system = builtins.currentSystem;
builder = ./scm-builder.sh;
};
}

9
tests/jobs/svn-input.nix Normal file
View file

@ -0,0 +1,9 @@
{ src }:
{
copy =
derivation {
name = "svn-input";
system = builtins.currentSystem;
builder = ./scm-builder.sh;
};
}