user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
blob 2373b370dcd81b0d26aa74fbcf7805f699bcaf52 1600 bytes (raw)
name: t/lei-mirror.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
 
#!perl -w
# Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
use strict; use v5.10.1; use PublicInbox::TestCommon;
my $sock = tcp_server();
my ($tmpdir, $for_destroy) = tmpdir();
my $http = 'http://'.$sock->sockhost.':'.$sock->sockport.'/';
my ($ro_home, $cfg_path) = setup_public_inboxes;
my $cmd = [ qw(-httpd -W0), "--stdout=$tmpdir/out", "--stderr=$tmpdir/err" ];
my $td = start_script($cmd, { PI_CONFIG => $cfg_path }, { 3 => $sock });
test_lei({ tmpdir => $tmpdir }, sub {
	my $home = $ENV{HOME};
	my $t1 = "$home/t1-mirror";
	ok($lei->('add-external', $t1, '--mirror', "$http/t1/"), '--mirror v1');
	ok(-f "$t1/public-inbox/msgmap.sqlite3", 't1-mirror indexed');

	ok($lei->('ls-external'), 'ls-external');
	like($lei_out, qr!\Q$t1\E!, 't1 added to ls-externals');

	my $t2 = "$home/t2-mirror";
	ok($lei->('add-external', $t2, '--mirror', "$http/t2/"), '--mirror v2');
	ok(-f "$t2/msgmap.sqlite3", 't2-mirror indexed');

	ok($lei->('ls-external'), 'ls-external');
	like($lei_out, qr!\Q$t2\E!, 't2 added to ls-externals');

	ok(!$lei->('add-external', $t2, '--mirror', "$http/t2/"),
		'--mirror fails if reused');

	ok($lei->('ls-external'), 'ls-external');
	like($lei_out, qr!\Q$t2\E!, 'still in ls-externals');

	ok(!$lei->('add-external', "$t2-fail", '-Lmedium'), '--mirror v2');
	ok(!-d "$t2-fail", 'destination not created on failure');
	ok($lei->('ls-external'), 'ls-external');
	unlike($lei_out, qr!\Q$t2-fail\E!, 'not added to ls-external');
});

ok($td->kill, 'killed -httpd');
$td->join;

done_testing;

debug log:

solving 2373b370 ...
found 2373b370 in https://80x24.org/public-inbox.git

(*) 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.^

Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).