]> git.donarmstrong.com Git - debbugs.git/commitdiff
add submit_but and run_processall utility routines
authorDon Armstrong <don@donarmstrong.com>
Thu, 7 Jun 2018 22:34:00 +0000 (15:34 -0700)
committerDon Armstrong <don@donarmstrong.com>
Thu, 7 Jun 2018 22:34:00 +0000 (15:34 -0700)
t/22_oo_interface.t
t/lib/DebbugsTest.pm

index a14b68574ad5eda56c58444fc2770feac9b33ed8..55a6b527261afc3b68e2941e98046edd74725cf2 100644 (file)
@@ -35,21 +35,13 @@ $tests++;
 
 # create 4 bugs
 for (1..4) {
-    send_message(to=>'submit@bugs.something',
-                headers => [To   => 'submit@bugs.something',
-                            From => 'foo@bugs.something',
-                            Subject => 'Submitting a bug '.$_,
-                           ],
-                run_processall => ($_ == 4 ? 1 : 0),
-                body => <<EOF) or fail('Unable to send message');
-Package: foo
-Severity: normal
-Tags: wontfix moreinfo
-
-This is a silly bug $_
-EOF
+    submit_bug(subject => 'Submitting a bug '.$_,
+              pseudoheaders => {Severity => 'normal',
+                                Tags => 'wontfix moreinfo',
+                               },
+             );
 }
-
+run_processall();
 
 my $bc = Debbugs::Collection::Bug->new(bugs => [1..4]);
 
index c18e86eea278396b5ad6c006712281abe6466a8a..152bd5801fa3afcb80451422835d86f7a9cf477f 100644 (file)
@@ -24,6 +24,8 @@ use strict;
 use vars qw($VERSION $DEBUG %EXPORT_TAGS @EXPORT_OK @EXPORT);
 use base qw(Exporter);
 
+use v5.10;
+
 use IO::File;
 use File::Temp qw(tempdir);
 use Cwd qw(getcwd);
@@ -41,7 +43,8 @@ BEGIN{
      $DEBUG = 0 unless defined $DEBUG;
 
      @EXPORT = ();
-     %EXPORT_TAGS = (configuration => [qw(dirsize create_debbugs_configuration send_message)],
+     %EXPORT_TAGS = (configuration => [qw(dirsize create_debbugs_configuration send_message),
+                                      qw(submit_bug run_processall)],
                     mail          => [qw(num_messages_sent)],
                     control       => [qw(test_control_commands)],
                     database => [qw(create_postgresql_database update_postgresql_database)]
@@ -207,11 +210,15 @@ sub send_message{
      }
      # now we should run processall to see if the message gets processed
      if ($param{run_processall}) {
-         system('scripts/processall') == 0 or die "processall failed";
+        run_processall();
       }
      return 1;
 }
 
+sub run_processall {
+    system('scripts/processall') == 0 or die "processall failed";
+}
+
 =item test_control_commands
 
  test_control_commands(\%config,
@@ -285,6 +292,49 @@ EOF
     }
 }
 
+sub submit_bug {
+    state $spec =
+       {subject => {type => SCALAR,
+                   default => 'Submitting a bug',
+                  },
+       body => {type => SCALAR,
+                default => 'This is a silly bug',
+               },
+       submitter => {type => SCALAR,
+                     default => 'foo@bugs.something',
+                    },
+       pseudoheaders => {type => HASHREF,
+                         default => sub {{}},
+                        },
+       package => {type => SCALAR,
+                   default => 'foo',
+                  },
+       run_processall => {type => SCALAR,
+                          default => 0,
+                         },
+       };
+    my %param =
+       validate_with(params => \@_,
+                     spec => $spec);
+    my $body = 'Package: '.$param{package}."\n";
+    foreach my $key (keys %{$param{pseudoheaders}}) {
+       for my $val (ref($param{pseudoheaders}{$key}) ?
+                    @{$param{pseudoheaders}{$key}} :
+                    $param{pseudoheaders}{$key}) {
+           $body .= $key. ': '.$val."\n";
+       }
+    }
+    $body .="\n".$param{body};
+    send_message(to => 'submit@bugs.something',
+                headers => [To => 'submit@bugs.something',
+                            From => $param{submitter},
+                            Subject => $param{subject},
+                           ],
+                run_processall => $param{run_processall},
+                body => $body
+               );
+}
+
 
 {
      package DebbugsTest::HTTPServer;