public-inbox.git  about / heads / tags
an "archives first" approach to mailing lists
blob e480338de74982dc10b2ed220ad14507413c0624 1793 bytes (raw)
name: t/emergency.t 	 # note: path name is non-authoritative(*)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
 
# Copyright (C) 2016 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
use strict;
use warnings;
use Test::More;
use File::Temp qw/tempdir/;
my $tmpdir = tempdir('emergency-XXXXXX', TMPDIR => 1, CLEANUP => 1);
use_ok 'PublicInbox::Emergency';

{
	my $md = "$tmpdir/a";
	my $em = PublicInbox::Emergency->new($md);
	ok(-d $md, 'Maildir a auto-created');
	my @tmp = <$md/tmp/*>;
	is(scalar @tmp, 0, 'no temporary files exist, yet');
	$em->prepare(\"BLAH");
	@tmp = <$md/tmp/*>;
	is(scalar @tmp, 1, 'globbed one temporary file');
	open my $fh, '<', $tmp[0] or die "failed to open: $!";
	is("BLAH", <$fh>, 'wrote contents to temporary location');
	my @new = <$md/new/*>;
	is(scalar @new, 0, 'no new files exist, yet');
	$em = undef;
	@tmp = <$md/tmp/*>;
	is(scalar @tmp, 0, 'temporary file no longer exists');
	@new = <$md/new/*>;
	is(scalar @new, 1, 'globbed one new file');
	open $fh, '<', $new[0] or die "failed to open: $!";
	is("BLAH", <$fh>, 'wrote contents to new location');
}
{
	my $md = "$tmpdir/b";
	my $em = PublicInbox::Emergency->new($md);
	ok(-d $md, 'Maildir b auto-created');
	my @tmp = <$md/tmp/*>;
	is(scalar @tmp, 0, 'no temporary files exist, yet');
	$em->prepare(\"BLAH");
	@tmp = <$md/tmp/*>;
	is(scalar @tmp, 1, 'globbed one temporary file');
	open my $fh, '<', $tmp[0] or die "failed to open: $!";
	is("BLAH", <$fh>, 'wrote contents to temporary location');
	my @new = <$md/new/*>;
	is(scalar @new, 0, 'no new files exist, yet');
	is(sysread($em->fh, my $buf, 9), 4, 'read file handle exposed');
	is($buf, 'BLAH', 'got expected data');
	$em->abort;
	@tmp = <$md/tmp/*>;
	is(scalar @tmp, 0, 'temporary file no longer exists');
	@new = <$md/new/*>;
	is(scalar @new , 0, 'new file no longer exists');
}

done_testing();

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

git clone https://public-inbox.org/public-inbox.git
git clone http://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/public-inbox.git