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