Warning fix
[catagits/Gitalist.git] / t / 02git_repo.t
1 use strict;
2 use warnings;
3 use FindBin qw/$Bin/;
4 use Test::More qw/no_plan/;
5 use Test::Exception;
6
7 use Data::Dumper;
8
9 BEGIN { use_ok 'Gitalist::Git::Repo' }
10
11 my $repo_dir = "$Bin/lib/repositories";
12 my $repo = Gitalist::Git::Repo->new( repo_dir => $repo_dir );
13 isa_ok($repo, 'Gitalist::Git::Repo');
14
15 is($repo->repo_dir, $repo_dir, "repo->repo_dir is correct" );
16
17 # 'bare.git' is a bare git repository in the repository dir
18 use Path::Class;
19 my $repoBare = Path::Class::Dir->new('t/lib/repositories/bare.git');
20 ok( $repo->_is_git_repo( $repoBare ), 'is_git_repo true for bare git repo' );
21
22 # 'working' is a working copy w/ git repo in the repository dir
23 my $repoWorking = Path::Class::Dir->new('t/lib/repositories/working');
24
25 # 'empty.git' is an empty directory in the repository dir
26 my $repoEmpty = Path::Class::Dir->new('t/lib/repositories/empty.git');
27 ok( ! $repo->_is_git_repo( $repoEmpty ), 'is_git_repo is false for empty dir' );
28
29 my $project_list = $repo->projects;
30 isa_ok(@$project_list[0], 'Gitalist::Git::Project');
31 ok(scalar @{$project_list} == 3, 'list_projects returns an array with the correct number of members' );
32 is($project_list->[0]->{name}, 'bare.git', 'list_projects has correct name for "bare.git" repo' );
33
34 dies_ok {
35     my $project = $repo->project('NoSuchProject');
36 } 'throws exception for invalid project';
37
38 dies_ok {
39     my $project = $repo->project();
40 } 'throws exception for no project';
41
42 dies_ok {
43     my $project = $repo->project('../../../');
44 } 'throws exception for directory traversal';
45
46 my $project = $repo->project('repo1');
47 isa_ok($project, 'Gitalist::Git::Project');