]> git.donarmstrong.com Git - debbugs.git/blob - t/10_expire.t
abstract out create config in tests
[debbugs.git] / t / 10_expire.t
1 # -*- mode: cperl;-*-
2 #
3
4 use Test::More tests => 21;
5
6 use warnings;
7 use strict;
8
9 # Here, we're going to shoot messages through a set of things that can
10 # happen.
11
12 # First, we're going to send mesages to receive.
13 # To do so, we'll first send a message to submit,
14 # then send messages to the newly created bugnumber.
15
16 use IO::File;
17 use File::Temp qw(tempdir);
18 use Cwd qw(getcwd);
19 use Debbugs::MIME qw(create_mime_message);
20 use File::Basename qw(dirname basename);
21 # The test functions are placed here to make things easier
22 use lib qw(t/lib);
23 use DebbugsTest qw(:all);
24 use Data::Dumper;
25
26 # HTTP::Server:::Simple defines a SIG{CHLD} handler that breaks system; undef it here.
27 $SIG{CHLD} = sub {};
28 my %config;
29 eval {
30      %config = create_debbugs_configuration();
31 };
32 if ($@) {
33      BAIL_OUT($@);
34 }
35
36 my $sendmail_dir = $config{sendmail_dir};
37 my $spool_dir = $config{spool_dir};
38 my $config_dir = $config{config_dir};
39
40
41
42 # We're going to use create mime message to create these messages, and
43 # then just send them to receive.
44
45 send_message(to=>'submit@bugs.something',
46              headers => [To   => 'submit@bugs.something',
47                          From => 'foo@bugs.something',
48                          Subject => 'Submiting a bug',
49                         ],
50              body => <<EOF) or fail('Unable to send message');
51 Package: foo
52 Severity: normal
53
54 This is a silly bug
55 EOF
56
57 # now we check to see that we have a bug, and nextnumber has been incremented
58 ok(-e "$spool_dir/db-h/01/1.log",'log file created');
59 ok(-e "$spool_dir/db-h/01/1.summary",'sumary file created');
60 ok(-e "$spool_dir/db-h/01/1.status",'status file created');
61 ok(-e "$spool_dir/db-h/01/1.report",'report file created');
62
63 # next, we check to see that (at least) the proper messages have been
64 # sent out. 1) ack to submitter 2) mail to maintainer
65
66 # This keeps track of the previous size of the sendmail directory
67 my $SD_SIZE_PREV = 0;
68 my $SD_SIZE_NOW = dirsize($sendmail_dir);
69 ok($SD_SIZE_NOW-$SD_SIZE_PREV >= 2,'submit messages appear to have been sent out properly');
70 $SD_SIZE_PREV=$SD_SIZE_NOW;
71
72 # now send a message to the bug
73
74 send_message(to => '1@bugs.something',
75              headers => [To   => '1@bugs.something',
76                          From => 'foo@bugs.something',
77                          Subject => 'Sending a message to a bug',
78                         ],
79              body => <<EOF) or fail('sending message to 1@bugs.someting failed');
80 Package: foo
81 Severity: normal
82
83 This is a silly bug
84 EOF
85
86 $SD_SIZE_NOW = dirsize($sendmail_dir);
87 ok($SD_SIZE_NOW-$SD_SIZE_PREV >= 2,'1@bugs.something messages appear to have been sent out properly');
88 $SD_SIZE_PREV=$SD_SIZE_NOW;
89
90 # just check to see that control doesn't explode
91 send_message(to => 'control@bugs.something',
92              headers => [To   => 'control@bugs.something',
93                          From => 'foo@bugs.something',
94                          Subject => 'Munging a bug',
95                         ],
96              body => <<EOF) or fail 'message to control@bugs.something failed';
97 severity 1 wishlist
98 retitle 1 new title
99 thanks
100 EOF
101
102 $SD_SIZE_NOW = dirsize($sendmail_dir);
103 ok($SD_SIZE_NOW-$SD_SIZE_PREV >= 1,'control@bugs.something messages appear to have been sent out properly');
104 $SD_SIZE_PREV=$SD_SIZE_NOW;
105 # now we need to check to make sure the control message was processed without errors
106 ok(system('sh','-c','find '.$sendmail_dir.q( -type f | xargs grep -q "Subject: Processed: Munging a bug")) == 0,
107    'control@bugs.something message was parsed without errors');
108 # now we need to check to make sure that the control message actually did anything
109 # This is an eval because $ENV{DEBBUGS_CONFIG_FILE} isn't set at BEGIN{} time
110 eval "use Debbugs::Status qw(read_bug writebug);";
111 my $status = read_bug(bug=>1);
112 ok($status->{subject} eq 'new title','bug 1 retitled');
113 ok($status->{severity} eq 'wishlist','bug 1 wishlisted');
114
115 # now we're going to go through and methododically test all of the control commands.
116 my @control_commands =
117      (close        => {command => 'close',
118                        value   => '',
119                        status_key => 'done',
120                        status_value => 'foo@bugs.something',
121                       },
122       archive      => {command => 'archive',
123                        value   => '',
124                        status_key => 'owner',
125                        status_value => '',
126                        location => 'archive',
127                       },
128       unarchive    => {command => 'unarchive',
129                        value   => '',
130                        status_key => 'owner',
131                        status_value => '',
132                       },
133      );
134
135 # In order for the archive/unarchive to work, we have to munge the summary file slightly
136 $status = read_bug(bug => 1);
137 $status->{unarchived} = time;
138 writebug(1,$status);
139 while (my ($command,$control_command) = splice(@control_commands,0,2)) {
140      # just check to see that control doesn't explode
141      $control_command->{value} = " $control_command->{value}" if length $control_command->{value}
142           and $control_command->{value} !~ /^\s/;
143      send_message(to => 'control@bugs.something',
144                   headers => [To   => 'control@bugs.something',
145                               From => 'foo@bugs.something',
146                               Subject => "Munging a bug with $command",
147                              ],
148                   body => <<EOF) or fail 'message to control@bugs.something failed';
149 debug 10
150 $control_command->{command} 1$control_command->{value}
151 thanks
152 EOF
153                                   ;
154      $SD_SIZE_NOW = dirsize($sendmail_dir);
155      ok($SD_SIZE_NOW-$SD_SIZE_PREV >= 1,'control@bugs.something messages appear to have been sent out properly');
156      $SD_SIZE_PREV=$SD_SIZE_NOW;
157      # now we need to check to make sure the control message was processed without errors
158      ok(system('sh','-c','find '.$sendmail_dir.q( -type f | xargs grep -q "Subject: Processed: Munging a bug with $command")) == 0,
159         'control@bugs.something'. "$command message was parsed without errors");
160      # now we need to check to make sure that the control message actually did anything
161      my $status;
162      $status = read_bug(bug=>1,
163                         exists $control_command->{location}?(location => $control_command->{location}):(),
164                        );
165      is_deeply($status->{$control_command->{status_key}},$control_command->{status_value},"bug 1 $command")
166           or fail(Dumper($status));
167 }
168
169 # now we need to run expire, and make sure that bug is expired
170 # afterwards
171 # we punt and touch to set it to something that is archiveable
172
173 # set the access time to twice the remove age
174 my $old_time = time - 28*2*24*60*60;
175
176 system('touch','-d','@'.$old_time,"$spool_dir/db-h/01/1.log",    );
177 system('touch','-d','@'.$old_time,"$spool_dir/db-h/01/1.summary",);
178 system('touch','-d','@'.$old_time,"$spool_dir/db-h/01/1.status", );
179 system('touch','-d','@'.$old_time,"$spool_dir/db-h/01/1.report", );
180 ok(system('scripts/expire') == 0,'expire completed successfully');
181
182 ok($status = read_bug(bug => 1,location => 'archive'),'read bug from archive correctly');