1#!/usr/bin/perl -w 2 3# to run: 4# RT_DBA_USER=root RT_DBA_PASSWORD= prove -lv -I/opt/rt3/lib t/race-condition.t 5use strict; 6 7use Prophet::Test; 8 9BEGIN { 10 unless (eval 'use RT::Test tests => "no_declare"; 1') { 11 diag $@ if $ENV{'TEST_VERBOSE'}; 12 plan skip_all => 'requires RT 3.8 or newer to run tests.'; 13 } 14} 15 16plan tests => 8; 17use App::SD::Test; 18 19no warnings 'once'; 20 21RT::Handle->InsertData( $RT::EtcPath . '/initialdata' ); 22 23BEGIN { 24 require File::Temp; 25 $ENV{'PROPHET_REPO'} = $ENV{'SD_REPO'} 26 = File::Temp::tempdir( CLEANUP => 1 ) . '/_svb'; 27 diag "export SD_REPO=" . $ENV{'PROPHET_REPO'} . "\n"; 28} 29 30my $IMAGE_FILE = qw|t/data/bplogo.gif|; 31 32$RT::Test::SKIP_REQUEST_WORK_AROUND = 1; 33 34 35my $reason = <<EOF; 36Before this script started passing, the RT replica type would automatically mark any change that happened before or at the same time as a push as having originated in SD, so it wouldn't pull it back from RT. This includes changes made by scrips after ticket update 37EOF 38 39diag($reason); 40 41 42my ( $url, $m ) = RT::Test->started_ok; 43 44use RT::Client::REST; 45use RT::Client::REST::Ticket; 46my $rt = RT::Client::REST->new( server => $url ); 47$rt->login( username => 'root', password => 'password' ); 48 49$url =~ s|http://|http://root:password@|; 50my $sd_rt_url = "rt:$url|General|Status!='resolved'"; 51 52 53 54# Create a ticket in RT 55my $ticket = RT::Client::REST::Ticket->new( 56 rt => $rt, 57 queue => 'General', 58 status => 'new', 59 subject => 'Fly Man', 60)->store( text => "Initial ticket Comment" ); 61 62my $flyman_rt_id = $ticket->id; 63 64ok($flyman_rt_id, "I created a new ticket in RT"); 65 66 67 68 69# pull to sd 70 71 72my ( $ret, $out, $err ); 73( $ret, $out, $err ) 74 = run_script( 'sd', 75 [ 'clone', '--from', $sd_rt_url, '--non-interactive' ] ); 76my ( $yatta_id, $flyman_id ); 77 78 79# make sure ticket is new 80 81run_output_matches( 'sd', [ 'ticket', 'list', '--regex', '.' ], [qr/(.*?)(?{ $flyman_id = $1 }) Fly Man new/]); 82 83 84 85 86 87# comment on ticket in sd 88 89( $ret, $out, $err ) = run_script( 'sd', [ 'ticket', 'comment', $flyman_id, '--content', 'helium is a noble gas' ] ); 90ok( $ret, $out ); 91like( $out, qr/Created comment/ ); 92 93 94 95 96 97# make sure ticket is new 98 99run_output_matches( 'sd', [ 'ticket', 'list', '--regex', '.' ], ["$flyman_id Fly Man new"]); 100 101diag("About to push to RT"); 102# push to rt 103{ 104 105 my ( $ret, $out, $err ) = run_script( 'sd', [ 'push', '--to', $sd_rt_url ] ); 106 diag($err); 107 108} 109 110 111 112# make sure ticket is open in rt, since after we commented the scrip popped it open. 113{ 114 my $fetched_ticket = RT::Client::REST::Ticket->new( 115 rt => $rt, 116 id => $flyman_rt_id 117 )->retrieve; 118 119 is( $fetched_ticket->status, "open" ); 120 121} 122 123# pull to sd 124( $ret, $out, $err ) = run_script( 'sd', [ 'pull', '--from', $sd_rt_url ] ); 125 126# make sure ticket is open 127run_output_matches_unordered( 128 'sd', 129 [ 'ticket', 'list', '--regex', '.' ], 130 [ "$flyman_id Fly Man open", ] 131); 132 133