Test script to transfer data over GTP without a tracker
[VCS-Git-Torrent.git] / t / 41-peer-references.t
blob28cfb4f26e7416feba76f2bb002bd1f6a6755c03
1 #!/usr/bin/perl
3 use Test::More no_plan;
4 use strict;
5 use warnings;
7 # This test script tests the VCS::Git::Torrent::References class
9 BEGIN { use_ok('t::TestUtils') }
10 BEGIN { use_ok('VCS::Git::Torrent') }
11 BEGIN { use_ok('VCS::Git::Torrent::Reference') }
13 my $path = mk_tmp_repo();
14 my $repo = Git->repository($path);
15 my $tag_id = $repo->command('hash-object', '-w', '-t', 'tag', '../41-peer-references/01-simple.tag');
16 chomp $tag_id;
18 my $t = VCS::Git::Torrent->new(
19 repo_hash => '1415' x 10,
20 git => $repo,
23 my $ref = VCS::Git::Torrent::Reference->new(
24 torrent => $t,
25 tag_id => $tag_id,
28 my $tagged_object = '5e8f6a7807a378259daa3b91314c8c9775fa160e';
29 my $sam = 'Sam Vilain <sam@vilain.net>';
30 my $tagdate = '2008-07-13 15:25:13+1200';
32 is($ref->tag_id, $tag_id, 'tag_id matches');
33 is($ref->tagged_object, $tagged_object, 'tagged_object matches');
34 is($ref->tagger, $sam, 'tagger matches');
35 is($ref->tagdate, $tagdate, 'tagdate matches');
36 is($ref->comment, "Simple tag object\n\n", 'comment matches');
38 #foreach(keys(%{$ref->refs})) {
39 # print $_ . "\t" . $ref->{refs}->{$_} . "\n";
42 is($ref->refs->{'refs/heads/master'}, $tagged_object, 'refs matches');
44 # now the reverse
45 my $tag = VCS::Git::Torrent::Reference->new
46 ( torrent => $t,
47 tagged_object => $tagged_object,
48 tagger => $sam,
49 tagdate => $tagdate,
50 comment => "Created by $0\n\n",
51 refs => { 'refs/heads/master' => $tagged_object },
54 ok($tag->tag_id, "can write tag");
55 $tag_id = $tag->tag_id;
57 my $type = $repo->command_oneline("cat-file", "-t", $tag_id);
58 is($type, "tag", "wrote a tag OK");
59 if ( -t STDOUT ) {
60 my $data = $repo->command("cat-file", "tag", $tag_id);
61 diag($data);