]> git.donarmstrong.com Git - debbugs.git/blob - t/11_blocks.t
merge changes from dla source
[debbugs.git] / t / 11_blocks.t
1 # -*- mode: cperl;-*-
2
3 use Test::More tests => 14;
4
5 use warnings;
6 use strict;
7
8 # Here, we're going to shoot messages through a set of things that can
9 # happen.
10
11 # First, we're going to send mesages to receive.
12 # To do so, we'll first send a message to submit,
13 # then send messages to the newly created bugnumber.
14
15 use IO::File;
16 use File::Temp qw(tempdir);
17 use Cwd qw(getcwd);
18 use Debbugs::MIME qw(create_mime_message);
19 use File::Basename qw(dirname basename);
20 # The test functions are placed here to make things easier
21 use lib qw(t/lib);
22 use DebbugsTest qw(:all);
23 use Data::Dumper;
24
25 # HTTP::Server:::Simple defines a SIG{CHLD} handler that breaks system; undef it here.
26 $SIG{CHLD} = sub {};
27 my %config;
28 eval {
29      %config = create_debbugs_configuration(debug => exists $ENV{DEBUG}?$ENV{DEBUG}:0);
30 };
31 if ($@) {
32      BAIL_OUT($@);
33 }
34
35 my $sendmail_dir = $config{sendmail_dir};
36 my $spool_dir = $config{spool_dir};
37 my $config_dir = $config{config_dir};
38
39 END{
40      if ($ENV{DEBUG}) {
41           diag("spool_dir:   $spool_dir\n");
42           diag("config_dir:   $config_dir\n");
43           diag("sendmail_dir: $sendmail_dir\n");
44      }
45 }
46
47 # We're going to use create mime message to create these messages, and
48 # then just send them to receive.
49
50 for my $bug (1..11) {
51     send_message(to=>'submit@bugs.something',
52                  headers => [To   => 'submit@bugs.something',
53                              From => 'foo@bugs.something',
54                              Subject => 'Submiting a bug '.$bug,
55                             ],
56                  body => <<EOF) or fail('Unable to send message');
57 Package: foo
58 Severity: normal
59
60 This is a silly bug $bug
61 EOF
62 }
63
64 # next, we check to see that (at least) the proper messages have been
65 # sent out. 1) ack to submitter 2) mail to maintainer
66
67 # This keeps track of the previous size of the sendmail directory
68 my $SD_SIZE = 0;
69 $SD_SIZE =
70     num_messages_sent($SD_SIZE,10,
71                       $sendmail_dir,
72                       'submit messages appear to have been sent out properly',
73                      );
74
75
76 # now send a message to the bug
77
78 send_message(to => '1@bugs.something',
79              headers => [To   => '1@bugs.something',
80                          From => 'foo@bugs.something',
81                          Subject => 'Sending a message to a bug',
82                         ],
83              body => <<EOF) or fail('sending message to 1@bugs.someting failed');
84 Package: foo
85 Severity: normal
86
87 This is a silly bug
88 EOF
89
90 $SD_SIZE =
91     num_messages_sent($SD_SIZE,2,
92                       $sendmail_dir,
93                       '1@bugs.something messages appear to have been sent out properly');
94
95 # just check to see that control doesn't explode
96 send_message(to => 'control@bugs.something',
97              headers => [To   => 'control@bugs.something',
98                          From => 'foo@bugs.something',
99                          Subject => 'Munging a bug',
100                         ],
101              body => <<EOF) or fail 'message to control@bugs.something failed';
102 block 10 with 2
103 thanks
104 EOF
105
106 # now we need to check to make sure the control message was processed without errors
107 ok(system('sh','-c','find '.$sendmail_dir.q( -type f | xargs grep -q "Subject: Processed: Munging a bug")) == 0,
108    'control@bugs.something message was parsed without errors');
109 eval "use Debbugs::Status qw(read_bug writebug);";
110 my $status = read_bug(bug=>10);
111 ok($status->{blockedby} eq '2','bug 10 is blocked by 2 (and only 2)');
112 $status = read_bug(bug=>2);
113 ok($status->{blocks} eq '10','bug 2 blocks 10 (and only 10)');
114
115 send_message(to => 'control@bugs.something',
116              headers => [To   => 'control@bugs.something',
117                          From => 'foo@bugs.something',
118                          Subject => 'Munging a bug',
119                         ],
120              body => <<EOF) or fail 'message to control@bugs.something failed';
121 merge 3 4
122 block 10 by 3
123 thanks
124 EOF
125 ok(system('sh','-c','find '.$sendmail_dir.q( -type f | xargs grep -q "Subject: Processed: Munging a bug")) == 0,
126    'control@bugs.something message was parsed without errors');
127 $status = read_bug(bug=>10);
128 ok(is_deeply([sort split /\ /,$status->{blockedby}],[qw(2 3 4)]),'bug 10 is blocked by exactly 2, 3, and 4');
129 send_message(to => 'control@bugs.something',
130              headers => [To   => 'control@bugs.something',
131                          From => 'foo@bugs.something',
132                          Subject => 'Munging a bug',
133                         ],
134              body => <<EOF) or fail 'message to control@bugs.something failed';
135 unblock 10 with 2
136 thanks
137 EOF
138
139 ok(system('sh','-c','find '.$sendmail_dir.q( -type f | xargs grep -q "Subject: Processed: Munging a bug")) == 0,
140    'control@bugs.something message was parsed without errors');
141
142 $status = read_bug(bug=>10);
143 ok(is_deeply([sort split /\ /,$status->{blockedby}],[qw(3 4)]),'bug 10 is blocked by exactly 3 and 4');
144 $status = read_bug(bug=>3);
145 ok($status->{blocks} eq '10','bug 3 blocks exactly 10');
146
147 send_message(to => 'control@bugs.something',
148              headers => [To   => 'control@bugs.something',
149                          From => 'foo@bugs.something',
150                          Subject => 'Munging a bug',
151                         ],
152              body => <<EOF) or fail 'message to control@bugs.something failed';
153 block 3 with 5
154 thanks
155 EOF
156 ok(system('sh','-c','find '.$sendmail_dir.q( -type f | xargs grep -q "Subject: Processed: Munging a bug")) == 0,
157    'control@bugs.something message was parsed without errors');
158
159
160 $status = read_bug(bug=>3);
161 ok($status->{blockedby} eq '5','bug 3 is blocked by exactly 5');