]> git.donarmstrong.com Git - debbugs.git/blobdiff - t/09_soap.t
abstract out create config in tests
[debbugs.git] / t / 09_soap.t
index 2ffd45c2dc15add62f083f3dde3c4facbdca250a..ccd51edc335bd9d254423052919ea9c2889ea19a 100644 (file)
@@ -6,13 +6,6 @@ use Test::More tests => 4;
 use warnings;
 use strict;
 
-# Here, we're going to shoot messages through a set of things that can
-# happen.
-
-# First, we're going to send mesages to receive.
-# To do so, we'll first send a message to submit,
-# then send messages to the newly created bugnumber.
-
 use IO::File;
 use File::Temp qw(tempdir);
 use Cwd qw(getcwd);
@@ -26,21 +19,12 @@ use Cwd;
 
 my %config;
 eval {
-     %config = create_debbugs_configuration(debug => exists $ENV{DEBUG}?$ENV{DEBUG}:0);
+     %config = create_debbugs_configuration();
 };
 if ($@) {
      BAIL_OUT($@);
 }
 
-# Output some debugging information if there's an error
-END{
-     if ($ENV{DEBUG}) {
-         foreach my $key (keys %config) {
-              diag("$key: $config{$key}\n");
-         }
-     }
-}
-
 # create a bug
 send_message(to=>'submit@bugs.something',
             headers => [To   => 'submit@bugs.something',
@@ -55,9 +39,9 @@ This is a silly bug
 EOF
 
 
-# test bugreport.cgi
+# test the soap server
 
-my $port = 11342;
+my $port = 11343;
 
 # We'd like to use soap.cgi here instead of testing the module
 # directly, but I can't quite get it to work with
@@ -69,8 +53,10 @@ our $child_pid = undef;
 
 END{
      if (defined $child_pid) {
+         my $temp_exit = $?;
          kill(15,$child_pid);
          waitpid(-1,0);
+         $? = $temp_exit;
      }
 }
 
@@ -78,28 +64,41 @@ my $pid = fork;
 die "Unable to fork child" if not defined $pid;
 if ($pid) {
      $child_pid = $pid;
-     # Wait for a second to let the child start
-     sleep 1;
+     # Wait for two seconds to let the child start
+     sleep 2;
 }
 else {
      # UGH.
      eval q(
      use Debbugs::SOAP::Server;
      @Debbugs::SOAP::Server::ISA = qw(SOAP::Transport::HTTP::Daemon);
-     Debbugs::SOAP::Server
+     our $warnings = '';
+     eval {
+       # Ignore stupid warning because elements (hashes) can't start with
+       # numbers
+       local $SIG{__WARN__} = sub {$warnings .= $_[0] unless $_[0] =~ /Cannot encode unnamed element/};
+       Debbugs::SOAP::Server
               ->new(LocalAddr => 'localhost', LocalPort => $port)
                    ->dispatch_to('/','Debbugs::SOAP')
                         ->handle;
+      };
+      die $@ if $@;
+      warn $warnings if length $warnings;
+
      );
 }
 
 use SOAP::Lite;
 my $soap = SOAP::Lite->uri('Debbugs/SOAP')->proxy('http://localhost:'.$port.'/');
 #ok($soap->get_soap_version->result == 1,'Version set and got correctly');
-my $bugs = $soap->get_bugs(package => 'foo')->result;
+my $bugs_result = $soap->get_bugs(package => 'foo');
+my $bugs = $bugs_result->result;
 use Data::Dumper;
+#print STDERR Dumper($bugs_result);
 ok(@{$bugs} == 1 && $bugs->[0] == 1, 'get_bugs returns bug number 1') or fail(Dumper($bugs));
-my $status = $soap->get_status(1)->result;
+my $status_result = $soap->get_status(1);
+#print STDERR Dumper($status_result);
+my $status = $status_result->result;
 ok($status->{1}{package} eq 'foo','get_status thinks that bug 1 belongs in foo') or fail(Dumper($status));
 
 # Test the usertags at some point