From 369b2ef0aa09c59986a75838d93e96e11cc35ce1 Mon Sep 17 00:00:00 2001 From: Rob Vermaas Date: Thu, 17 Mar 2011 08:48:27 +0000 Subject: [PATCH] add tests for scm inputs --- tests/Makefile.am | 10 ++++++-- tests/evaluation-tests.pl.in | 39 ++++++++++++++++++++++++++++--- tests/jobs/basic.nix | 1 - tests/jobs/bzr-checkout-input.nix | 9 +++++++ tests/jobs/bzr-input.nix | 9 +++++++ tests/jobs/git-input.nix | 9 +++++++ tests/jobs/hg-input.nix | 9 +++++++ tests/jobs/scm-builder.sh | 2 ++ tests/jobs/svn-checkout-input.nix | 9 +++++++ tests/jobs/svn-input.nix | 9 +++++++ 10 files changed, 100 insertions(+), 6 deletions(-) create mode 100644 tests/jobs/bzr-checkout-input.nix create mode 100644 tests/jobs/bzr-input.nix create mode 100644 tests/jobs/git-input.nix create mode 100644 tests/jobs/hg-input.nix create mode 100644 tests/jobs/scm-builder.sh create mode 100644 tests/jobs/svn-checkout-input.nix create mode 100644 tests/jobs/svn-input.nix diff --git a/tests/Makefile.am b/tests/Makefile.am index 4e97088d..f61666d1 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 diff --git a/tests/evaluation-tests.pl.in b/tests/evaluation-tests.pl.in index 5817c48e..54b4120d 100755 --- a/tests/evaluation-tests.pl.in +++ b/tests/evaluation-tests.pl.in @@ -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") +} diff --git a/tests/jobs/basic.nix b/tests/jobs/basic.nix index c5343076..da8bf3cd 100644 --- a/tests/jobs/basic.nix +++ b/tests/jobs/basic.nix @@ -1,4 +1,3 @@ -{ input }: { empty_dir = derivation { diff --git a/tests/jobs/bzr-checkout-input.nix b/tests/jobs/bzr-checkout-input.nix new file mode 100644 index 00000000..8f40fd4d --- /dev/null +++ b/tests/jobs/bzr-checkout-input.nix @@ -0,0 +1,9 @@ +{ src }: +{ + copy = + derivation { + name = "bzr-checkout-input"; + system = builtins.currentSystem; + builder = ./scm-builder.sh; + }; +} diff --git a/tests/jobs/bzr-input.nix b/tests/jobs/bzr-input.nix new file mode 100644 index 00000000..6bccd29e --- /dev/null +++ b/tests/jobs/bzr-input.nix @@ -0,0 +1,9 @@ +{ src }: +{ + copy = + derivation { + name = "bzr-input"; + system = builtins.currentSystem; + builder = ./scm-builder.sh; + }; +} diff --git a/tests/jobs/git-input.nix b/tests/jobs/git-input.nix new file mode 100644 index 00000000..55e5b87b --- /dev/null +++ b/tests/jobs/git-input.nix @@ -0,0 +1,9 @@ +{ src }: +{ + copy = + derivation { + name = "git-input"; + system = builtins.currentSystem; + builder = ./scm-builder.sh; + }; +} diff --git a/tests/jobs/hg-input.nix b/tests/jobs/hg-input.nix new file mode 100644 index 00000000..902c876b --- /dev/null +++ b/tests/jobs/hg-input.nix @@ -0,0 +1,9 @@ +{ src }: +{ + copy = + derivation { + name = "hg-input"; + system = builtins.currentSystem; + builder = ./scm-builder.sh; + }; +} diff --git a/tests/jobs/scm-builder.sh b/tests/jobs/scm-builder.sh new file mode 100644 index 00000000..83eefbe8 --- /dev/null +++ b/tests/jobs/scm-builder.sh @@ -0,0 +1,2 @@ +mkdir $out +cp -v $src/* $out/ diff --git a/tests/jobs/svn-checkout-input.nix b/tests/jobs/svn-checkout-input.nix new file mode 100644 index 00000000..8f40fd4d --- /dev/null +++ b/tests/jobs/svn-checkout-input.nix @@ -0,0 +1,9 @@ +{ src }: +{ + copy = + derivation { + name = "bzr-checkout-input"; + system = builtins.currentSystem; + builder = ./scm-builder.sh; + }; +} diff --git a/tests/jobs/svn-input.nix b/tests/jobs/svn-input.nix new file mode 100644 index 00000000..2d2dfb2c --- /dev/null +++ b/tests/jobs/svn-input.nix @@ -0,0 +1,9 @@ +{ src }: +{ + copy = + derivation { + name = "svn-input"; + system = builtins.currentSystem; + builder = ./scm-builder.sh; + }; +}