1 # Copyright (C) 2016 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
6 use File::Temp qw/tempdir/;
7 my $tmpdir = tempdir('emergency-XXXXXX', TMPDIR => 1, CLEANUP => 1);
8 use_ok 'PublicInbox::Emergency';
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");
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');
25 is(scalar @tmp, 0, 'temporary file no longer exists');
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');
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");
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');
48 is(scalar @tmp, 0, 'temporary file no longer exists');
50 is(scalar @new , 0, 'new file no longer exists');