[Bps-public-commit] SD branch, master, updated. 7ae8e2fed0beefa0446e67b667dd3b4b013e4e83

jesse jesse at bestpractical.com
Mon May 4 16:51:36 EDT 2009


The branch, master has been updated
       via  7ae8e2fed0beefa0446e67b667dd3b4b013e4e83 (commit)
       via  f7f249158237b2619ca33ddd79912ae8d883b33c (commit)
       via  5f6334bec5787d812fa77839f55020efb946dff8 (commit)
       via  0c8ab7ddc99b8b90e91b219500d294a5494ff81e (commit)
       via  7f036cc3c8c24cd7107dc4efcf05fc4c318f7481 (commit)
      from  66994d51da5c274dd3d34e05235f7fb40c164c50 (commit)

Summary of changes:
 bin/git-sd                                    |   22 ++++--
 t/sd-redmine/basic.t                          |   57 +++++++++++++
 t/sd-redmine/net_redmine_test.pl              |   41 ++++++++++
 t/sd-trac/basic.t                             |   71 +++++++++++------
 t/sd-trac/push-new-ticket-to-trac-then-pull.t |  106 +++++++++++++++++++++++++
 5 files changed, 268 insertions(+), 29 deletions(-)
 create mode 100644 t/sd-redmine/basic.t
 create mode 100644 t/sd-redmine/net_redmine_test.pl
 create mode 100644 t/sd-trac/push-new-ticket-to-trac-then-pull.t

- Log -----------------------------------------------------------------
commit 7f036cc3c8c24cd7107dc4efcf05fc4c318f7481
Author: Hans Dieter Pearcey <hdp at weftsoar.net>
Date:   Mon May 4 03:52:25 2009 +0800

    use .git/.. as the default parent for .sd
    
    Signed-off-by: Jesse Vincent <jesse at bestpractical.com>

diff --git a/bin/git-sd b/bin/git-sd
index 6ab3dfe..c9fb0d7 100755
--- a/bin/git-sd
+++ b/bin/git-sd
@@ -1,10 +1,20 @@
 #!/bin/sh
 replica=`git config --get sd.local-replica`
-if [ "fnord$replica" != "fnord" ]; then
-    SD_REPO=$replica exec sd $@
-else 
+if [ "fnord$replica" = "fnord" ]; then
+    # TODO: respect GIT_DIR
+    gitdir=`pwd`
+    while ! [ -e "$gitdir/.git" ]; do
+        if [ "$gitdir" = "/" ]; then
+            echo "Can't find a .git directory anywhere in your current directory"
+            echo "or any higher directories."
+            exit 1;
+        fi
+        gitdir=`dirname $gitdir`
+    done
+    replica=$gitdir/.sd
     echo "You don't appear to have an sd.local-replica defined in your .git/config"
-    echo "To remedy this, you want to run a command like:\n"
-    echo "  git config --add sd.local-replica \"~/.sd-for-this-project\"\n"
-    echo "  (Substituting, of course, the local SD database replica for this project)"
+    echo "Setting it to '$replica':\n"
+    echo "  git config --add sd.local-replica $replica"
+    git config --add sd.local-replica $replica
 fi
+SD_REPO=$replica exec sd $@

commit 0c8ab7ddc99b8b90e91b219500d294a5494ff81e
Author: Hans Dieter Pearcey <hdp at weftsoar.net>
Date:   Mon May 4 03:57:50 2009 +0800

    default to .git/sd instead of .sd
    
    Signed-off-by: Jesse Vincent <jesse at bestpractical.com>

diff --git a/bin/git-sd b/bin/git-sd
index c9fb0d7..f65b9f4 100755
--- a/bin/git-sd
+++ b/bin/git-sd
@@ -11,7 +11,7 @@ if [ "fnord$replica" = "fnord" ]; then
         fi
         gitdir=`dirname $gitdir`
     done
-    replica=$gitdir/.sd
+    replica=$gitdir/.git/sd
     echo "You don't appear to have an sd.local-replica defined in your .git/config"
     echo "Setting it to '$replica':\n"
     echo "  git config --add sd.local-replica $replica"

commit 5f6334bec5787d812fa77839f55020efb946dff8
Author: Kang-min Liu <gugod at gugod.org>
Date:   Sun May 3 16:28:34 2009 +0800

    the draft ot a basic testing program.
    
    Signed-off-by: Jesse Vincent <jesse at bestpractical.com>

diff --git a/t/sd-redmine/basic.t b/t/sd-redmine/basic.t
new file mode 100644
index 0000000..35afdeb
--- /dev/null
+++ b/t/sd-redmine/basic.t
@@ -0,0 +1,46 @@
+#!/usr/bin/env perl -w
+use strict;
+
+use Prophet::Test;
+use App::SD::Test;
+
+require File::Temp;
+$ENV{'PROPHET_REPO'} = $ENV{'SD_REPO'} = File::Temp::tempdir( CLEANUP => 1 ) . '/_svb';
+diag "export SD_REPO=" . $ENV{'PROPHET_REPO'} . "\n";
+
+use Net::Redmine;
+require 't/sd-redmine/net_redmine_test.pl';
+
+my $r = new_redmine();
+
+plan tests => 1;
+
+note "create 5 new tickets in redmine.";
+my @tickets = new_tickets($r, 5);
+
+note "- created tickets: " . join(",", map { $_->id } @tickets);
+
+note "sd clone them, verify their summary text.";
+my $sd_redmine_url = "redmine:" . $r->connection->url;
+my $user = $r->connection->user;
+my $pass = $r->connection->password;
+$sd_redmine_url =~ s|http://|http://${user}:${pass}@|;
+
+diag "sd clone --from ${sd_redmine_url}";
+
+my ( $ret, $out, $err ) = run_script( 'sd', [ 'clone', '--from', $sd_redmine_url ] );
+is(count_tickets_in_sd(),5, "the total cloned tickets is 5.");
+
+note "close one of them, push it to server.";
+( $ret, $out, $err ) = run_script( 'sd', [ "ticket", "update", $tickets[0]->id, "--", "status=Closed" ] );
+like( $out, qr/^Ticket(.*)updated/ );
+diag($out);
+diag($err);
+
+( $ret, $out, $err ) = run_script( 'sd', [ 'push', '--to', $sd_redmine_url ] );
+diag($out);
+diag($err);
+
+note "verify the update with Net::Redmine";
+my $ticket = $r->lookup(ticket => { id => $tickets[0]->id });
+is($ticket->status, "Closed");
diff --git a/t/sd-redmine/net_redmine_test.pl b/t/sd-redmine/net_redmine_test.pl
new file mode 100644
index 0000000..835bd6d
--- /dev/null
+++ b/t/sd-redmine/net_redmine_test.pl
@@ -0,0 +1,41 @@
+unless ($_ = $ENV{NET_REDMINE_TEST}) {
+    plan skip_all => "Need NET_REDMINE_TEST env var";
+    exit;
+}
+
+sub net_redmine_test {
+    my ($server, $user, $password) = split / /,  $ENV{NET_REDMINE_TEST};
+
+    unless ($server && $user && $password) {
+        plan skip_all => "No server and/or login credentials.";
+        exit;
+    }
+    return ($server, $user, $password);
+}
+
+sub new_redmine {
+    my ($server, $user, $password) = net_redmine_test();
+    return Net::Redmine->new(url => $server,user => $user, password => $password);
+}
+
+use Text::Greeking;
+sub new_tickets {
+    my ($r, $n) = @_;
+    $n ||= 1;
+
+    my $g = Text::Greeking->new;
+    $g->paragraphs(1,1);
+    $g->sentences(1,1);
+    $g->words(8,24);
+
+    return map {
+        $r->create(
+            ticket => {
+                subject => $g->generate,
+                description => $g->generate
+            }
+        );        
+    } (1..$n);
+}
+
+1;

commit f7f249158237b2619ca33ddd79912ae8d883b33c
Author: Kang-min Liu <gugod at gugod.org>
Date:   Sun May 3 16:44:44 2009 +0800

    define the missing sub.
    
    Signed-off-by: Jesse Vincent <jesse at bestpractical.com>

diff --git a/t/sd-redmine/basic.t b/t/sd-redmine/basic.t
index 35afdeb..7d9fe79 100644
--- a/t/sd-redmine/basic.t
+++ b/t/sd-redmine/basic.t
@@ -44,3 +44,14 @@ diag($err);
 note "verify the update with Net::Redmine";
 my $ticket = $r->lookup(ticket => { id => $tickets[0]->id });
 is($ticket->status, "Closed");
+
+##
+sub count_tickets_in_sd {
+    my $self = shift;
+
+    my ( $ret, $out, $err ) = run_script(
+        'sd' => [ 'ticket', 'list', '--regex', '.' ]
+    );
+    my @lines = split(/\n/,$out);
+    return scalar @lines;
+}

commit 7ae8e2fed0beefa0446e67b667dd3b4b013e4e83
Author: Jesse Vincent <jesse at bestpractical.com>
Date:   Mon May 4 16:51:19 2009 -0400

    break out push new tickets then pull tests for trac sync

diff --git a/t/sd-trac/basic.t b/t/sd-trac/basic.t
index cd1a141..64ed2d1 100644
--- a/t/sd-trac/basic.t
+++ b/t/sd-trac/basic.t
@@ -14,14 +14,13 @@ unless (`which trac-admin`) { plan skip_all => 'You need trac installed to run t
 unless ( eval { require Net::Trac } ) {
     plan skip_all => 'You need Net::Trac installed to run the tests';
 }
-plan tests => 40;
+plan tests => 39;
 
 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(
@@ -38,6 +37,11 @@ is( $trac->url, $tr->url );
 
 is(count_tickets_in_trac(),0);
 
+
+# 
+# Create a ticket in trac
+#
+
 my $ticket = Net::Trac::Ticket->new( connection => $trac );
 isa_ok( $ticket, 'Net::Trac::Ticket' );
 
@@ -45,6 +49,12 @@ ok( $ticket->create( summary => 'This product has only a moose, not a pony' ) );
 is( $ticket->id, 1 );
 
 is(count_tickets_in_trac(),1);
+
+
+#
+# Update a ticket in trac
+#
+
 can_ok( $ticket, 'load' );
 ok( $ticket->load(1) );
 like( $ticket->state->{'summary'}, qr/pony/ );
@@ -59,6 +69,11 @@ my $first   = shift @entries;
 is( $entries[0], undef, "there is only one history entry. no create txn" );
 is( $first->category, 'Ticket' );
 
+
+# 
+# Clone from trac
+#
+
 my ( $ret, $out, $err );
 ( $ret, $out, $err ) = run_script( 'sd', [ 'clone', '--from', $sd_trac_url ] );
 
@@ -68,6 +83,12 @@ diag($out);
 diag($err);
 my $pony_id;
 
+
+#
+# Check our clone from trac
+#
+
+
 run_output_matches(
     'sd',
     [ 'ticket', 'list', '--regex', '.' ],
@@ -76,6 +97,10 @@ run_output_matches(
 
 ok( $pony_id, "I got the ID of a pony - It's $pony_id" );
 
+
+# 
+# Modify the ticket we pulled from trac
+
 ( $ret, $out, $err ) = run_script( 'sd', [ "ticket", "update", $pony_id, "--", "status=closed" ] );
 like( $out, qr/^Ticket(.*)updated/ );
 diag($out);
@@ -83,20 +108,31 @@ diag($err);
 ( $ret, $out, $err ) = run_script( 'sd' => [ "ticket", "basics", $pony_id, "--batch" ] );
 
 like( $out, qr/status: closed/ );
-
 diag("The pony is $pony_id");
 my $new_ticket = Net::Trac::Ticket->new( connection => $trac );
 ok( $new_ticket->load(1) );
 is( $new_ticket->status, 'new', "The ticket is new before we push to trac" );
 
+# 
+# Push the changes to our ticket to trac
+#
+
 ( $ret, $out, $err ) = run_script( 'sd', [ 'push', '--to', $sd_trac_url ] );
 diag($out);
 diag($err);
 
+# 
+# Check the state of our ticket after we push to trac
+
 is(count_tickets_in_trac(),1);
 my $closed_ticket = Net::Trac::Ticket->new( connection => $trac );
 ok( $closed_ticket->load(1) );
 is( $closed_ticket->status, 'resolved', "The ticket is closed after we push to trac" );
+
+# 
+# Push to trac a second time -- this should cause no updates
+#
+
 ( $ret, $out, $err ) = run_script( 'sd', [ 'push', '--to', $sd_trac_url ] );
 diag($out);
 diag($err);
@@ -104,8 +140,9 @@ diag($err);
 is(count_tickets_in_trac(),1);
 is(count_tickets_in_sd(),1);
 
-# create a ticket in sd
-
+#
+# create a second ticket in sd
+#
 my ($yatta_id, $yatta_uuid) = create_ticket_ok( '--summary', 'This ticket originated in SD');
 
 run_output_matches( 'sd', [ 'ticket',
@@ -130,35 +167,23 @@ run_output_matches( 'sd', [ 'ticket', 'basics', '--batch', '--id', $yatta_id ],
 
 is(count_tickets_in_sd(),2);
 
+#
+# create a second ticket in trac
+#
 
-# create a ticket in trac
 my $ticket2 = Net::Trac::Ticket->new( connection => $trac );
 isa_ok( $ticket2, 'Net::Trac::Ticket' );
-
 ok( $ticket2->create( summary => 'This product has only a moose, not a pony' ) );
-
-
 is(count_tickets_in_trac(),2);
 
 
-
-# push to trac
-
-( $ret, $out, $err ) = run_script( 'sd', [ 'push', '--to', $sd_trac_url ] );
-diag($out);
-diag($err);
-
-
-is(count_tickets_in_trac(),3); 
-
-# pull from trac
-
+#
+# pull the second ticket from trac
+#
 ( $ret, $out, $err ) = run_script( 'sd', [ 'pull', '--from', $sd_trac_url ] );
 diag($out);
 diag($err);
 
-
-
 is(count_tickets_in_sd(),3);
 
 
diff --git a/t/sd-trac/push-new-ticket-to-trac-then-pull.t b/t/sd-trac/push-new-ticket-to-trac-then-pull.t
new file mode 100644
index 0000000..f81ad57
--- /dev/null
+++ b/t/sd-trac/push-new-ticket-to-trac-then-pull.t
@@ -0,0 +1,106 @@
+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 => 17;
+
+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 );
+
+is( count_tickets_in_trac(), 0 );
+
+#
+# Clone from trac
+#
+
+my ( $ret, $out, $err ) = run_script( 'sd', [ 'clone', '--from', $sd_trac_url ] );
+is( count_tickets_in_sd(), 0 );
+ok(!($?>>8), $out." ".$err);
+#
+# create a ticket in sd
+#
+my ( $yatta_id, $yatta_uuid ) = create_ticket_ok( '--summary', 'This ticket originated in SD' );
+
+run_output_matches(
+    'sd', [ 'ticket',
+        'list', '--regex', 'This ticket originated in SD' ],
+    [qr/(\d+) This ticket originated in SD new/]
+
+);
+
+run_output_matches(
+    'sd',
+    [ 'ticket', 'basics', '--batch', '--id', $yatta_id ],
+    [   "id: $yatta_id ($yatta_uuid)",
+        'summary: This ticket originated in SD',
+        'status: new',
+        'milestone: alpha',
+        'component: core',
+        qr/^created: \d{4}-\d{2}-\d{2}.+$/,
+        'creator: ' . $ENV{PROPHET_EMAIL},
+        'reporter: ' . $ENV{PROPHET_EMAIL},
+        "original_replica: " . replica_uuid,
+    ]
+);
+
+is( count_tickets_in_sd(),   1 );
+is( count_tickets_in_trac(), 0 );
+
+#
+# push our ticket to trac
+#
+
+($ret,$out,$err) = run_script( 'sd', [ 'push', '--to', $sd_trac_url ] );
+ok(!($?>>8), $err);
+is( count_tickets_in_trac(), 1 );
+
+#
+# pull from trac
+#
+
+($ret, $out, $err) = run_script( 'sd', [ 'pull', '--from', $sd_trac_url ] );
+ok(!($? >> 8) , $err);
+is( count_tickets_in_sd(), 1 );
+
+sub count_tickets_in_sd {
+    my $self = shift;
+    my ( $ret, $out, $err ) = run_script( 'sd' => [ 'ticket', 'list', '--regex', '.' ], );
+    my @lines = split( /\n/, $out );
+    return scalar @lines;
+}
+
+sub count_tickets_in_trac {
+    my $self    = shift;
+    my $tickets = Net::Trac::TicketSearch->new( connection => $trac );
+    my $result  = $tickets->query( summary => { not => 'nonsense' } );
+    my $count   = scalar @{ $tickets->results };
+    return $count;
+}

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list