]> Sergey Matveev's repositories - public-inbox.git/blob - t/emergency.t
www: drop --subject from "git send-email" instructions
[public-inbox.git] / t / emergency.t
1 # Copyright (C) 2016-2021 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3 use strict;
4 use warnings;
5 use Test::More;
6 use PublicInbox::TestCommon;
7 my ($tmpdir, $for_destroy) = tmpdir();
8 use_ok 'PublicInbox::Emergency';
9
10 {
11         my $md = "$tmpdir/a";
12         my $em = PublicInbox::Emergency->new($md);
13         ok(-d $md, 'Maildir a auto-created');
14         my @tmp = <$md/tmp/*>;
15         is(scalar @tmp, 0, 'no temporary files exist, yet');
16         $em->prepare(\"BLAH");
17         @tmp = <$md/tmp/*>;
18         is(scalar @tmp, 1, 'globbed one temporary file');
19         open my $fh, '<', $tmp[0] or die "failed to open: $!";
20         is("BLAH", <$fh>, 'wrote contents to temporary location');
21         my @new = <$md/new/*>;
22         is(scalar @new, 0, 'no new files exist, yet');
23         $em = undef;
24         @tmp = <$md/tmp/*>;
25         is(scalar @tmp, 0, 'temporary file no longer exists');
26         @new = <$md/new/*>;
27         is(scalar @new, 1, 'globbed one new file');
28         open $fh, '<', $new[0] or die "failed to open: $!";
29         is("BLAH", <$fh>, 'wrote contents to new location');
30 }
31 {
32         my $md = "$tmpdir/b";
33         my $em = PublicInbox::Emergency->new($md);
34         ok(-d $md, 'Maildir b auto-created');
35         my @tmp = <$md/tmp/*>;
36         is(scalar @tmp, 0, 'no temporary files exist, yet');
37         $em->prepare(\"BLAH");
38         @tmp = <$md/tmp/*>;
39         is(scalar @tmp, 1, 'globbed one temporary file');
40         open my $fh, '<', $tmp[0] or die "failed to open: $!";
41         is("BLAH", <$fh>, 'wrote contents to temporary location');
42         my @new = <$md/new/*>;
43         is(scalar @new, 0, 'no new files exist, yet');
44         is(sysread($em->fh, my $buf, 9), 4, 'read file handle exposed');
45         is($buf, 'BLAH', 'got expected data');
46         $em->abort;
47         @tmp = <$md/tmp/*>;
48         is(scalar @tmp, 0, 'temporary file no longer exists');
49         @new = <$md/new/*>;
50         is(scalar @new , 0, 'new file no longer exists');
51 }
52
53 done_testing();