2 # Copyright (C) 2020 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
5 use PublicInbox::TestCommon;
8 use PublicInbox::Import;
10 require_mods('PublicInbox::Gcf2');
11 use_ok 'PublicInbox::Gcf2Client';
12 my ($tmpdir, $for_destroy) = tmpdir();
13 PublicInbox::Import::init_bare($tmpdir);
14 my $fi_data = './t/git.fast-import-data';
16 open $rdr->{0}, '<', $fi_data or BAIL_OUT $!;
17 xsys([qw(git fast-import --quiet)], { GIT_DIR => $tmpdir }, $rdr);
18 is($?, 0, 'fast-import succeeded');
20 my $tree = 'fdbc43725f21f485051c17463b50185f4c3cf88c';
23 local $ENV{PATH} = getcwd()."/blib/script:$ENV{PATH}";
24 my $gcf2c = PublicInbox::Gcf2Client->new;
25 $gcf2c->add_git_dir($tmpdir);
26 $gcf2c->cat_async($tree, sub {
27 my ($bref, $oid, $type, $size, $arg) = @_;
28 is($oid, $tree, 'got expected OID');
29 is($size, 30, 'got expected length');
30 is($type, 'tree', 'got tree type');
31 is(length($$bref), 30, 'got a tree');
32 is($arg, 'hi', 'arg passed');
35 my $trunc = substr($tree, 0, 39);
36 $gcf2c->cat_async($trunc, sub {
37 my ($bref, $oid, $type, $size, $arg) = @_;
38 is(undef, $bref, 'missing bref is undef');
39 is($oid, $trunc, 'truncated OID printed');
40 is($type, 'missing', 'type is "missing"');
41 is($size, undef, 'size is undef');
42 is($arg, 'bye', 'arg passed when missing');
46 is($called, 2, 'cat_async callbacks hit');