Make Object aware of its containing repository, and able to return its contents.
[catagits/Gitalist.git] / t / git / object.t
CommitLineData
8c0e3a9c 1use strict;
2use warnings;
3use FindBin qw/$Bin/;
4use Test::More qw/no_plan/;
5
6use Data::Dumper;
7
9bc54ee4 8use Path::Class;
9use Gitalist::Git::Project;
10my $project = Gitalist::Git::Project->new(
11 path => dir("$Bin/../lib/repositories/repo1"),
12);
13
8c0e3a9c 14BEGIN { use_ok 'Gitalist::Git::Object' }
15
16my $object = Gitalist::Git::Object->new(
9bc54ee4 17 project => $project,
8c0e3a9c 18 sha1 => '729a7c3f6ba5453b42d16a43692205f67fb23bc1',
19 type => 'tree',
20 file => 'dir1',
21 mode => 16384,
22);
23isa_ok($object, 'Gitalist::Git::Object');
9bc54ee4 24is($object->sha1,'729a7c3f6ba5453b42d16a43692205f67fb23bc1', 'sha1 is correct');
25is($object->type, 'tree', 'type is correct');
26is($object->file, 'dir1', 'file is correct');
8c0e3a9c 27is($object->mode, 16384, 'mode is correct');
28is($object->modestr, 'd---------', "modestr is correct" );
29
9bc54ee4 30# Create object from hash.
31my $obj2 = Gitalist::Git::Object->new(
32 project => $project,
33 sha1 => '5716ca5987cbf97d6bb54920bea6adde242d87e6',
34 file => 'file1',
35 mode => 33188,
36);
37isa_ok($obj2, 'Gitalist::Git::Object');
38is($obj2->sha1,'5716ca5987cbf97d6bb54920bea6adde242d87e6', 'sha1 is correct');
39is($obj2->type, 'blob', 'type is correct');
40is($obj2->file, 'file1', 'file is correct');
41is($obj2->mode, 33188, 'mode is correct');
42is($obj2->modestr, '-rw-r--r--', "modestr is correct" );
43is($obj2->contents, "bar\n", 'obj2 contents is correct');
44