summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
Diffstat (limited to 't')
-rw-r--r--t/001_base.t3
-rw-r--r--t/002_index_route.t1
-rw-r--r--t/005_builder.t76
-rw-r--r--t/006_emailer.t153
-rw-r--r--t/data/test.yml30
5 files changed, 261 insertions, 2 deletions
diff --git a/t/001_base.t b/t/001_base.t
index 936ffff..43163e6 100644
--- a/t/001_base.t
+++ b/t/001_base.t
@@ -1,5 +1,6 @@
-use Test::More tests => 1;
+use Test::More tests => 2;
use strict;
use warnings;
use_ok 'jitterbug';
+use_ok 'jitterbug::Builder';
diff --git a/t/002_index_route.t b/t/002_index_route.t
index 5c02d85..f6fe11b 100644
--- a/t/002_index_route.t
+++ b/t/002_index_route.t
@@ -3,7 +3,6 @@ use strict;
use warnings;
ok 1;
-ok 2;
# the order is important
#use jitterbug;
#use Dancer::Test;
diff --git a/t/005_builder.t b/t/005_builder.t
new file mode 100644
index 0000000..84e13ef
--- /dev/null
+++ b/t/005_builder.t
@@ -0,0 +1,76 @@
+
+use strict;
+use warnings;
+use Test::Most tests => 9;
+use Data::Dumper;
+
+use jitterbug::Builder;
+
+{
+ local @ARGV = qw(-c t/data/test.yml -C);
+ my $b = jitterbug::Builder->new();
+
+ isa_ok($b,'jitterbug::Builder');
+ can_ok($b,qw/run build run_task sleep/);
+
+ is($b->{'configfile'}, 't/data/test.yml');
+ is($b->{'cron'}, 1 );
+}
+
+{
+ local @ARGV = qw(-c blarg.yml -C);
+
+ throws_ok (sub {
+ my $b = jitterbug::Builder->new();
+ }, qr/Does not exist/i, 'nonexistent yaml file throws error');
+}
+
+{
+ local @ARGV = qw(-c t/data/test.yml -C);
+ my $b = jitterbug::Builder->new();
+ isa_ok($b, 'jitterbug::Builder');
+ is($b->{'configfile'}, 't/data/test.yml');
+
+ is($b->run, 0, '->run returns 0 in cron mode');
+ cmp_deeply($b->{'conf'}, {
+ 'engines' => {
+ 'xslate' => {
+ 'type' => 'text',
+ 'path' => '/',
+ 'cache' => '0'
+ }
+ },
+ 'plugins' => {
+ 'DBIC' => {
+ 'schema' => {
+ 'connect_info' => [
+ 'dbi:SQLite:dbname=jitterbug.db'
+ ],
+ 'pckg' => 'jitterbug::Schema',
+ 'skip_automake' => '1'
+ }
+ }
+ },
+ 'jitterbug' => {
+ 'build_process' => {
+ 'on_failure' => './scripts/build-failed.sh',
+ 'builder' => './scripts/capsule.sh'
+ },
+ 'builder' => {},
+ 'reports' => {
+ 'dir' => '/tmp/jitterbug'
+ },
+ 'build' => {
+ 'dir' => '/tmp/build'
+ }
+ },
+ 'template' => 'xslate',
+ 'appname' => 'jitterbug',
+ 'layout' => 'main',
+ 'logger' => 'file',
+ 'builds_per_feed' => '5'
+ });
+
+
+}
+
diff --git a/t/006_emailer.t b/t/006_emailer.t
new file mode 100644
index 0000000..44dd328
--- /dev/null
+++ b/t/006_emailer.t
@@ -0,0 +1,153 @@
+use strict;
+use warnings;
+use Test::Most tests => 9;
+use Data::Dumper;
+use Test::MockObject;
+
+use_ok "jitterbug::Emailer";
+
+sub setup {
+ my $buildconf = {
+ on_failure_from_email => 'bob@example.com',
+ on_failure_cc_email => 'steve@example.com',
+ on_failure_subject_prefix => 'BLARG ',
+ on_failure_header => "Summary:\n%%SUMMARY%%",
+ on_failure_footer => "FOOT",
+ };
+
+ my $conf = { jitterbug => { build_process => $buildconf } };
+ my $commit = Test::MockObject->new;
+ my $project = Test::MockObject->new;
+ my $task = Test::MockObject->new;
+
+ $project->mock('name', sub { 'ponie' });
+
+ $commit->mock('sha256', sub { 'c0decafe' });
+ $commit->mock('content', sub { '{ "message" : "blargly blarg" }' } );
+
+ $task->mock('commit', sub { $commit });
+ $task->mock('project', sub { $project });
+ return ($conf, $commit, $project, $task);
+}
+
+{
+ my ($conf, $commit, $project, $task) = setup();
+ my $tap = "THIS IS TAP";
+ my $e = jitterbug::Emailer->new($conf, $task, $tap);
+
+ isa_ok($e,'jitterbug::Emailer');
+ can_ok($e,qw/new run/);
+
+ $e->run;
+ my $email = $e->{'last_email_sent'}{'email'};
+ like($email->body, qr/THIS IS TAP/, 'email body looks right');
+
+ my $header = $email->{'header'};
+ isa_ok($header, 'Email::MIME::Header');
+
+ is($header->header_raw('cc'), 'steve@example.com', 'cc header');
+ like($header->header_raw('subject'), qr/BLARG ponie @ c0decafe blargly blarg/, 'subject header');
+ is($header->header_raw('from'), 'bob@example.com', 'from header');
+}
+
+{
+ my ($conf, $commit, $project, $task) = setup();
+ my $tap = <<TAP;
+Copying lib/Math/Primality/AKS.pm -> blib/lib/Math/Primality/AKS.pm
+Copying lib/Math/Primality/BigPolynomial.pm -> blib/lib/Math/Primality/BigPolynomial.pm
+Copying lib/Math/Primality.pm -> blib/lib/Math/Primality.pm
+Copying bin/primes.pl -> blib/script/primes.pl
+Copying bin/strong_psuedoprimes.pl -> blib/script/strong_psuedoprimes.pl
+# Testing Math::Primality 0.0401, Perl 5.010001, /usr/bin/perl
+t/00-load.t ......................
+1..1
+ok 1 - use Math::Primality;
+ok
+# Failed test '-1 is not prime'
+# at t/is_prime.t line 16.
+# Looks like you failed 1 test of 573.
+t/is_prime.t .....................
+1..6
+ok 1 - is_prime should handle Math::GMPz objects, three is prime
+ok 2 - 2 is prime
+ok 3 - 1 is not prime
+ok 4 - 0 is not prime
+not ok 5 - -1 is not prime
+ok 6 - blarg
+t/boilerplate.t ..................
+1..3
+ok 1 - README contains no boilerplate text
+ok 2 - Changes contains no boilerplate text
+ok 3 - lib/Math/Primality.pm contains no boilerplate text
+ok
+Test Summary Report
+-------------------
+t/is_prime.t (Wstat: 256 Tests: 573 Failed: 1)
+Failed test: 5
+Non-zero exit status: 1
+Failed 1/11 test programs. 1/2498 subtests failed.
+Files=11, Tests=2498, 3 wallclock secs ( 0.20 usr 0.04 sys + 2.99 cusr 0.18 csys = 3.41 CPU)
+Result: FAIL
+TAP
+ my $e = jitterbug::Emailer->new($conf, $task, $tap);
+ $e->run;
+ my $email = $e->{'last_email_sent'}{'email'};
+ my $body = <<EMAIL;
+Summary:
+Test Summary Report
+-------------------
+t/is_prime.t (Wstat: 256 Tests: 573 Failed: 1)
+Failed test: 5
+Non-zero exit status: 1
+Failed 1/11 test programs. 1/2498 subtests failed.
+Files=11, Tests=2498, 3 wallclock secs ( 0.20 usr 0.04 sys + 2.99 cusr 0.18 csys = 3.41 CPU)
+Result: FAIL
+
+Commit Message:
+blargly blarg
+
+TAP Output:
+Copying lib/Math/Primality/AKS.pm -> blib/lib/Math/Primality/AKS.pm
+Copying lib/Math/Primality/BigPolynomial.pm -> blib/lib/Math/Primality/BigPolynomial.pm
+Copying lib/Math/Primality.pm -> blib/lib/Math/Primality.pm
+Copying bin/primes.pl -> blib/script/primes.pl
+Copying bin/strong_psuedoprimes.pl -> blib/script/strong_psuedoprimes.pl
+# Testing Math::Primality 0.0401, Perl 5.010001, /usr/bin/perl
+t/00-load.t ......................
+1..1
+ok 1 - use Math::Primality;
+ok
+# Failed test '-1 is not prime'
+# at t/is_prime.t line 16.
+# Looks like you failed 1 test of 573.
+t/is_prime.t .....................
+1..6
+ok 1 - is_prime should handle Math::GMPz objects, three is prime
+ok 2 - 2 is prime
+ok 3 - 1 is not prime
+ok 4 - 0 is not prime
+not ok 5 - -1 is not prime
+ok 6 - blarg
+t/boilerplate.t ..................
+1..3
+ok 1 - README contains no boilerplate text
+ok 2 - Changes contains no boilerplate text
+ok 3 - lib/Math/Primality.pm contains no boilerplate text
+ok
+Test Summary Report
+-------------------
+t/is_prime.t (Wstat: 256 Tests: 573 Failed: 1)
+Failed test: 5
+Non-zero exit status: 1
+Failed 1/11 test programs. 1/2498 subtests failed.
+Files=11, Tests=2498, 3 wallclock secs ( 0.20 usr 0.04 sys + 2.99 cusr 0.18 csys = 3.41 CPU)
+Result: FAIL
+
+FOOT
+EMAIL
+
+ my $ebody = $email->body;
+ $ebody =~ s/\r\n/\n/g;
+ eq_or_diff($ebody, $body, 'email body has failure summary');
+
+}
diff --git a/t/data/test.yml b/t/data/test.yml
new file mode 100644
index 0000000..e4144c3
--- /dev/null
+++ b/t/data/test.yml
@@ -0,0 +1,30 @@
+layout: "main"
+logger: "file"
+appname: "jitterbug"
+
+builds_per_feed: 5
+template: "xslate"
+engines:
+ xslate:
+ path: /
+ type: text
+ cache: 0
+
+jitterbug:
+ reports:
+ dir: /tmp/jitterbug
+ build:
+ dir: /tmp/build
+ build_process:
+ builder: ./scripts/capsule.sh
+ on_failure: ./scripts/build-failed.sh
+
+plugins:
+ DBIC:
+ schema:
+ skip_automake: 1
+ pckg: "jitterbug::Schema"
+ connect_info:
+ - dbi:SQLite:dbname=jitterbug.db
+
+