]> git.donarmstrong.com Git - debbugs.git/blob - t/15_rebuild_indexdb.t
a0ca9100dada19424d930c1d11d00398e1177e81
[debbugs.git] / t / 15_rebuild_indexdb.t
1 # -*- mode: cperl;-*-
2
3 use Test::More tests => 9;
4
5 use warnings;
6 use strict;
7
8 use utf8;
9
10 # Here, we're going to shoot messages through a set of things that can
11 # happen.
12
13 # First, we're going to send mesages to receive.
14 # To do so, we'll first send a message to submit,
15 # then send messages to the newly created bugnumber.
16
17 use IO::File;
18 use File::Temp qw(tempdir);
19 use Cwd qw(getcwd);
20 use Debbugs::MIME qw(create_mime_message);
21 use File::Basename qw(dirname basename);
22 # The test functions are placed here to make things easier
23 use lib qw(t/lib);
24 use DebbugsTest qw(:all);
25 use Data::Dumper;
26 use Encode qw(decode encode decode_utf8 encode_utf8);
27
28 # HTTP::Server:::Simple defines a SIG{CHLD} handler that breaks system; undef it here.
29 $SIG{CHLD} = sub {};
30 my %config;
31 eval {
32      %config = create_debbugs_configuration(debug => exists $ENV{DEBUG}?$ENV{DEBUG}:0);
33 };
34 if ($@) {
35      BAIL_OUT($@);
36 }
37
38 my $sendmail_dir = $config{sendmail_dir};
39 my $spool_dir = $config{spool_dir};
40 my $config_dir = $config{config_dir};
41
42 END{
43      if ($ENV{DEBUG}) {
44           diag("spool_dir:   $spool_dir\n");
45           diag("config_dir:   $config_dir\n");
46           diag("sendmail_dir: $sendmail_dir\n");
47      }
48 }
49
50 # We're going to use create mime message to create these messages, and
51 # then just send them to receive.
52
53 send_message(to=>'submit@bugs.something',
54              headers => [To   => 'submit@bugs.something',
55                          From => 'föoff@bugs.something',
56                          Subject => 'Submiting a bug',
57                         ],
58              body => <<EOF,attachments => [{Type=>"text/plain",Charset=>"utf-8",Data=>encode_utf8(<<EOF2)}]) or fail('Unable to send message');
59 Package: foo
60 Severity: normal
61
62 This is a silly bug
63 EOF
64 This is the silly bug's test ütff8 attachment.
65 EOF2
66
67
68
69 # now we check to see that we have a bug, and nextnumber has been incremented
70 ok(-e "$spool_dir/db-h/01/1.log",'log file created');
71 ok(-e "$spool_dir/db-h/01/1.summary",'sumary file created');
72 ok(-e "$spool_dir/db-h/01/1.status",'status file created');
73 ok(-e "$spool_dir/db-h/01/1.report",'report file created');
74 ok(system('sh','-c','[ $(grep "attachment." '.$spool_dir.'/db-h/01/1.log|grep -v "ütff8"|wc -l) -eq 0 ]') == 0,
75    'Everything attachment is escaped properly');
76
77 # next, we check to see that (at least) the proper messages have been
78 # sent out. 1) ack to submitter 2) mail to maintainer
79
80 # This keeps track of the previous size of the sendmail directory
81 my $SD_SIZE = 0;
82 $SD_SIZE =
83     num_messages_sent($SD_SIZE,2,
84                       $sendmail_dir,
85                       'submit messages appear to have been sent out properly',
86                      );
87
88
89 # now send a message to the bug
90
91 send_message(to => '1@bugs.something',
92              headers => [To   => '1@bugs.something',
93                          From => 'föoff@bugs.something',
94                          Subject => 'Sending a message to a bug',
95                         ],
96              body => <<EOF) or fail('sending message to 1@bugs.someting failed');
97 Package: foo
98 Severity: normal
99
100 This is a silly bug
101 EOF
102
103 $SD_SIZE =
104     num_messages_sent($SD_SIZE,2,
105                       $sendmail_dir,
106                       '1@bugs.something messages appear to have been sent out properly');
107
108 # just check to see that control doesn't explode
109 send_message(to => 'control@bugs.something',
110              headers => [To   => 'control@bugs.something',
111                          From => 'föoff@bugs.something',
112                          Subject => 'Munging a bug',
113                         ],
114              body => <<EOF) or fail 'message to control@bugs.something failed';
115 severity 1 wishlist
116 retitle 1 ütff8 title encoding test
117 thanks
118 EOF
119
120 $SD_SIZE =
121    num_messages_sent($SD_SIZE,1,
122                      $sendmail_dir,
123                      'control@bugs.something messages appear to have been sent out properly');
124 # now we need to check to make sure the control message was processed without errors
125 # now we need to check to make sure that the control message actually did anything
126 # This is an eval because $ENV{DEBBUGS_CONFIG_FILE} isn't set at BEGIN{} time
127 eval "use Debbugs::Status qw(read_bug writebug);";
128 ok(system('bin/debbugs-rebuild-index.db')==0,'debbugs-rebuild-index seems to work');