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