[Bps-public-commit] SD - A distributed issue tracker branch, master, updated. 8a68a5f9a68b2fce26793b87565e300c5a101c75
jesse
jesse at bestpractical.com
Mon Feb 16 21:32:11 EST 2009
The branch, master has been updated
via 8a68a5f9a68b2fce26793b87565e300c5a101c75 (commit)
from ba375d4f466053e4aae8e83e7f118244b8dbfd4a (commit)
Summary of changes:
Makefile.PL | 5 ++-
t/sd-trac/basic.t | 79 +++++++++++++++++++++++++++
t/sd-trac/setup_trac.pl | 135 +++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 218 insertions(+), 1 deletions(-)
create mode 100644 t/sd-trac/basic.t
create mode 100644 t/sd-trac/setup_trac.pl
- Log -----------------------------------------------------------------
commit 8a68a5f9a68b2fce26793b87565e300c5a101c75
Author: Jesse Vincent <jesse at bestpractical.com>
Date: Mon Feb 16 21:30:53 2009 -0500
First pass of 'pull' tests for sd/trac
diff --git a/Makefile.PL b/Makefile.PL
index 8785915..f922c15 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -24,7 +24,10 @@ feature 'Hiveminder sync' =>
-default => 0,
'Net::Jifty' => 0.09,
'Email::Address' => 0;
-
+feature 'Trac sync' =>
+ -default => 0,
+ 'Net::Trac' => 0.06,
+ 'LWP::Simple' => 0;
install_script('bin/sd');
install_script('bin/git-sd');
install_share('share');
diff --git a/t/sd-trac/basic.t b/t/sd-trac/basic.t
new file mode 100644
index 0000000..da886ef
--- /dev/null
+++ b/t/sd-trac/basic.t
@@ -0,0 +1,79 @@
+use warnings; use strict;
+use Prophet::Test;
+
+use App::SD::Test;
+
+
+
+BEGIN {
+ require File::Temp;
+ $ENV{'PROPHET_REPO'} = $ENV{'SD_REPO'}
+ = File::Temp::tempdir( CLEANUP => 1 ) . '/_svb';
+ diag "export SD_REPO=" . $ENV{'PROPHET_REPO'} . "\n";
+}
+
+
+unless (`which trac-admin`) { plan skip_all => 'You need trac installed to run the tests'; }
+unless (eval { require Net::Trac} ) { plan skip_all => 'You need Net::Trac installed to run the tests'; }
+plan tests => 18;
+
+
+use_ok('Net::Trac::Connection');
+use_ok('Net::Trac::Ticket');
+require 't/sd-trac/setup_trac.pl';
+
+
+my $tr = Net::Trac::TestHarness->new();
+
+ok($tr->start_test_server(), "The server started!");
+
+
+my $trac = Net::Trac::Connection->new(
+ url => $tr->url,
+ user => 'hiro',
+ password => 'yatta'
+);
+
+
+
+
+my $sd_trac_url = "trac:".$tr->url;
+$sd_trac_url =~ s|http://|http://hiro:yatta@|;
+
+
+isa_ok( $trac, "Net::Trac::Connection" );
+is($trac->url, $tr->url);
+my $ticket = Net::Trac::Ticket->new( connection => $trac);
+isa_ok($ticket, 'Net::Trac::Ticket');
+
+ok($ticket->create(summary => 'This product has only a moose, not a pony'));
+is($ticket->id, 1);
+
+can_ok($ticket, 'load');
+ok($ticket->load(1));
+like($ticket->state->{'summary'}, qr/pony/);
+like($ticket->summary, qr/moose/, "The summary looks like a moose");
+ok( $ticket->update( summary => 'The product does not contain a pony' ), "updated!");
+unlike($ticket->summary, qr/moose/, "The summary does not look like a moose");
+
+my $history = $ticket->history;
+ok($history, "The ticket has some history");
+my @entries = @{$history->entries};
+my $first = shift @entries;
+is($entries[0], undef, "there is only one history entry. no create txn");
+is ($first->category, 'Ticket');
+
+my ( $ret, $out, $err );
+( $ret, $out, $err ) = run_script( 'sd', [ 'clone', '--from', $sd_trac_url ] );
+
+diag($out);
+diag($err);
+my $pony_id;
+
+run_output_matches('sd',
+ [ 'ticket', 'list', '--regex', '.' ],
+ [qr/(.*?)(?{ $pony_id = $1 }) The product does not contain a pony new/]
+);
+
+
+diag("The pony is $pony_id");
diff --git a/t/sd-trac/setup_trac.pl b/t/sd-trac/setup_trac.pl
new file mode 100644
index 0000000..5facace
--- /dev/null
+++ b/t/sd-trac/setup_trac.pl
@@ -0,0 +1,135 @@
+#!/usr/bin/perl
+
+package Net::Trac::TestHarness;
+use warnings;
+use strict;
+
+use Test::More;
+use File::Temp qw/tempdir/;
+use LWP::Simple qw/get/;
+use Time::HiRes qw/usleep/;
+
+#my $x = __PACKAGE__->new(); $x->start_test_server(); warn $x->url; sleep 999;
+sub new {
+ my $class = shift;
+ my $self = {};
+ bless $self, $class;
+ return $self;
+}
+
+sub start_test_server {
+my $self = shift;
+
+$self->port( int(60000 + rand(2000)));
+$self->dir(tempdir( CLEANUP => 1));
+$self->init;
+$self->daemonize;
+return $self->_did_server_start;
+}
+
+sub _did_server_start {
+ my $self = shift;
+ for ( 1 .. 200 ) {
+ return 1 if eval { get( $self->url ) };
+ usleep 5000;
+ }
+ die "Server didn't start";
+}
+
+sub port {
+ my $self = shift;
+ if (@_) {
+ $self->{_port} = shift;
+ }
+ return $self->{_port};
+}
+
+sub dir {
+ my $self = shift;
+ if (@_) {
+ $self->{_dir} = shift;
+ }
+ return $self->{_dir};
+}
+
+sub pid {
+ my $self = shift;
+ if (@_) {
+ $self->{_pid} = shift;
+ }
+ return $self->{_pid};
+}
+
+sub url {
+ my $self = shift;
+ if (@_) {
+ $self->{_url} = shift;
+ }
+ return $self->{_url};
+}
+
+sub init {
+ my $self = shift;
+ my $dir = $self->dir;
+ my $port = $self->port;
+ open( my $sys,
+ "trac-admin $dir/trac initenv proj sqlite:db/trac.db svn ''|" );
+ my @content = <$sys>;
+ my ($url) = grep { defined $_ }
+ map { /Then point your browser to (.*)\./ ? $1 : undef } @content;
+ close($sys);
+ $url =~ s/8000/$port/;
+ $self->url($url);
+
+ $self->_grant_hiro();
+
+}
+
+sub _grant_hiro {
+ my $self = shift;
+ my $dir = $self->dir;
+open (my $sysadm, "trac-admin $dir/trac permission add hiro TRAC_ADMIN|");
+my @results = <$sysadm>;
+close ($sysadm);
+
+open(my $htpasswd, ">$dir/trac/conf/htpasswd") || die $!;
+# hiro / yatta
+print $htpasswd "hiro:trac:98aef54bbd280226ac74b6bc500ff70e\n";
+close $htpasswd;
+
+};
+
+
+sub kill_trac {
+ my $self = shift;
+ return unless $self->pid;
+ kill 1, $self->pid;
+
+}
+ sub daemonize {
+ my $self = shift;
+ my $dir = $self->dir;
+ my $port = $self->port;
+ my $orig_dir = `pwd`;
+ chomp $orig_dir;
+ chdir $dir."/trac";
+ open STDIN, '/dev/null' or die "Can't read /dev/null: $!";
+ open STDOUT, '>/dev/null' or die "Can't write to /dev/null: $!";
+ defined(my $pid = fork) or die "Can't fork: $!";
+ if ( $pid ) {
+ $self->pid($pid);
+ chdir($orig_dir) || die $!;
+ return $pid;
+ } else {
+ open STDERR, '>&STDOUT' or die "Can't dup stdout: $!";
+ exec("tracd -p $port -a trac,$dir/trac/conf/htpasswd,trac $dir/trac") || die "Tracd";
+ }
+ }
+
+
+sub DESTROY {
+ my $self = shift;
+ $self->kill_trac;
+}
+
+ 1;
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list