public-inbox.git  about / heads / tags
an "archives first" approach to mailing lists
blob d113d47904f15e4f23a606c813e4afe89ea39141 1840 bytes (raw)
$ git show HEAD:t/lei-import-http.t	# shows this blob on the CLI

 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
 
#!perl -w
# Copyright (C) 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;
require_mods(qw(lei -httpd));
require_cmd('curl');
my ($ro_home, $cfg_path) = setup_public_inboxes;
my ($tmpdir, $for_destroy) = tmpdir;
my $sock = tcp_server;
my $cmd = [ '-httpd', '-W0', "--stdout=$tmpdir/1", "--stderr=$tmpdir/2" ];
my $env = { PI_CONFIG => $cfg_path };
my $td = start_script($cmd, $env, { 3 => $sock }) or BAIL_OUT("-httpd $?");
my $host_port = tcp_host_port($sock);
undef $sock;
test_lei({ tmpdir => $tmpdir }, sub {
	my $url = "http://$host_port/t2";
	for my $p (qw(bogus@x/t.mbox.gz bogus@x/raw ?q=noresultever)) {
		ok(!lei('import', "$url/$p"), "/$p fails properly");
		like($lei_err, qr/curl.*404/, 'got curl 404');
	}
	for my $p (qw(/ /T/ /t/ /t.atom)) {
		ok(!lei('import', "$url/m\@example$p"), "/$p fails");
		like($lei_err, qr/did you mean/, "gave hint for $p");
	}
	lei_ok 'import', "$url/testmessage\@example.com/raw";
	lei_ok 'q', 'm:testmessage@example.com';
	my $res = json_utf8->decode($lei_out);
	is($res->[0]->{'m'}, 'testmessage@example.com', 'imported raw')
		or diag explain($res);

	lei_ok 'import', "$url/qp\@example.com/t.mbox.gz";
	lei_ok 'q', 'm:qp@example.com';
	$res = json_utf8->decode($lei_out);
	is($res->[0]->{'m'}, 'qp@example.com', 'imported t.mbox.gz')
		or diag explain($res);

	lei_ok 'import', "$url/?q=s:boolean";
	lei_ok 'q', 'm:20180720072141.GA15957@example';
	$res = json_utf8->decode($lei_out);
	is($res->[0]->{'m'}, '20180720072141.GA15957@example',
			'imported search result') or diag explain($res);

	ok(!lei(qw(import --mail-sync), "$url/x\@example.com/raw"),
		'--mail-sync fails on HTTP');
	like($lei_err, qr/--mail-sync/, 'error message notes --mail-sync');
});
done_testing;

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