App-KGB
view release on metacpan or search on metacpan
t/50-client.t view on Meta::CPAN
use Test::Differences;
use lib 't';
use TestBot;
use POSIX qw(setlocale LC_CTYPE);
BEGIN {
eval { require SVN::Core; 1 }
or plan skip_all => "SVN::Core required for testing the Subversion client";
eval { require SVN::Fs; 1 }
or plan skip_all => "SVN::Fs required for testing the Subversion client";
eval { require SVN::Repos; 1 }
or plan skip_all => "SVN::Repos required for testing the Subversion client";
};
use utf8;
my $builder = Test::More->builder;
binmode $builder->output, ":utf8";
binmode $builder->failure_output, ":utf8";
binmode $builder->todo_output, ":utf8";
my $test_bot = TestBot->start;
diag sprintf( "Test bot started on %s:%d", $test_bot->addr, $test_bot->port );
use File::Temp qw(tempdir);
my $r = tempdir( CLEANUP => not $ENV{TEST_KEEP_TEMP} );
diag "Temporary directory $r will be kept" if $ENV{TEST_KEEP_TEMP};
my $repo = catdir( $r, 'repo' );
my $wd = catdir( $r, 'checkout' );
my $tf = catfile( $wd, 'file' );
sub poke {
my $f;
open $f, ">", $tf;
print $f @_;
close $f;
}
sub in_wd {
system 'sh', '-c', "cd $wd && " . shift;
}
system 'svnadmin', 'create', $repo;
use Cwd;
my $hook_log = catdir( $r, 'hook.log' );
# the real test client
{
my $R = getcwd;
my $client_script = $ENV{KGB_CLIENT_SCRIPT} || "$R/script/kgb-client";
my $ccf = $test_bot->client_config_file;
open my $fh, '>', "$repo/hooks/post-commit";
print $fh <<EOF;
#!/bin/sh
PERL5LIB=$R/lib $^X -- $client_script --conf $ccf \$1 \$2 >> $hook_log 2>&1
EOF
close $fh;
chmod 0755, "$repo/hooks/post-commit";
}
# duplicate, talking to a different bot, connected to IRC
if ( $ENV{TEST_KGB_BOT_RUNNING} ) {
diag "will try to send notifications to locally running bot";
my $R = getcwd;
my $h;
open $h, '>>', "$repo/hooks/post-commit";
print $h <<"EOF";
PERL5LIB=$R/lib $^X -- $R/script/kgb-client --conf $R/eg/test-client.conf --status-dir $r \$1 \$2 >> /dev/null
EOF
close $h;
}
system 'svn', 'checkout', "file://$repo", $wd;
poke('one');
in_wd "svn add $tf";
in_wd "svn ci -m 'add file'";
TestBot->expect(
"dummy/#test 12test/ 1 ${TestBot::COMMIT_USER} 03/file add file * 14http://scm.host.org///?commit=1"
);
poke('two');
in_wd "svn ci -m 'modify file'";
TestBot->expect(
"dummy/#test 12test/ 2 ${TestBot::COMMIT_USER} 10/file modify file * 14http://scm.host.org///?commit=2"
);
in_wd "svn rm file";
poke('three');
in_wd "svn add file";
in_wd "svn ci -m 'replace file'";
TestBot->expect(
"dummy/#test 12test/ 3 ${TestBot::COMMIT_USER} 05/file replace file * 14http://scm.host.org///?commit=3"
);
ok( 1, "Test repository prepared" );
use App::KGB::Client::Subversion;
use App::KGB::Client::ServerRef;
my $port = 7645;
my $password = 'v,sjflir';
my $c = new_ok(
'App::KGB::Client::Subversion' => [
{ repo_id => 'test',
servers => [
App::KGB::Client::ServerRef->new(
{ uri => "http://127.0.0.1:$port/",
password => $password,
}
),
],
#br_mod_re => \@br_mod_re,
( run in 0.460 second using v1.01-cache-2.11-cpan-5735350b133 )