public-inbox.git  about / heads / tags
an "archives first" approach to mailing lists
blob de61efe68d858c370849e413eafdf361e63629bd 2012 bytes (raw)
$ git show repobrowse:t/repobrowse_common_git.perl	# 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
 
#!/usr/bin/perl -w
# 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/;
use Cwd qw/getcwd/;
my @mods = qw(HTTP::Request::Common Plack::Test URI::Escape);
foreach my $mod (@mods) {
	eval "require $mod";
	plan skip_all => "$mod missing for $0" if $@;
}

sub dechunk ($) {
	my ($res) = @_;
	my $s = $res->content;
	if (lc($res->header('Transfer-Encoding') || '') eq 'chunked') {
		my $rv = '';
		while ($s =~ s/\A([a-f0-9]+)\r\n//i) { # no comment support :x
			my $n = hex($1) or last;
			$rv .= substr($s, 0, $n);
			$s = substr($s, $n);
			$s =~ s/\A\r\n// or die "broken parsing in $s\n";
		}
		$s =~ s/\A\r\n// or die "broken end parsing in $s\n";
		$s = $rv;
	}
	$s;
}

use_ok $_ foreach @mods;
my $git_dir = tempdir('repobrowse-XXXXXX', CLEANUP => 1, TMPDIR => 1);
my $psgi = "examples/repobrowse.psgi";
my $repobrowse_config = "$git_dir/repobrowse_config";
my $app;
ok(-f $psgi, 'psgi example for repobrowse.psgi found');
{
	is(system(qw(git init -q --bare), $git_dir), 0, 'created git directory');
	my @cmd = ('git', "--git-dir=$git_dir", 'fast-import', '--quiet');
	my $fi_data = getcwd().'/t/git.fast-import-data';
	ok(-r $fi_data, "fast-import data readable (or run test at top level)");
	my $pid = fork;
	defined $pid or die "fork failed: $!\n";
	if ($pid == 0) {
		open STDIN, '<', $fi_data or die "open $fi_data: $!\n";
		exec @cmd;
		die "failed exec: ",join(' ', @cmd),": $!\n";
	}
	waitpid $pid, 0;
	is($?, 0, 'fast-import succeeded');
	my $fh;
	ok((open $fh, '>', $repobrowse_config and
		print $fh '[repo "test.git"]', "\n",
			"\t", "path = $git_dir", "\n" and
		close $fh), 'created repobrowse config');
	local $ENV{REPOBROWSE_CONFIG} = $repobrowse_config;
	ok($app = require $psgi, 'loaded PSGI app');
}

# return value
bless {
	psgi => $psgi,
	git_dir => $git_dir,
	app => $app,
	repobrowse_config => $repobrowse_config,
}, 'Repobrowse::TestGit';

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