Fix a load of links, and fix blob/blame/raw/history actions to (semi) work + tests
[catagits/Gitalist.git] / t / 01app.t
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
4 use Test::More;
5 use FindBin qw/$Bin/;
6
7 BEGIN {
8     $ENV{GITALIST_CONFIG} = $Bin;
9     $ENV{GITALIST_REPO_DIR} = '';
10     use_ok 'Catalyst::Test', 'Gitalist';
11 }
12
13 for my $p ('', qw/ repo1 nodescription bare.git opml /) {
14     my $path = '/' . $p;
15     ok( request($path)->is_success, "$path should succeed");
16 }
17
18 my $response = request('/DoesNotExist');
19 is $response->code, 404, 'invalid repository 404s';
20 like $response->content, qr/Page not found/, 'invalid repository handled correctly';
21
22
23 {
24   # URI tests for repo1
25   local *test = curry_test_uri('repo1');
26   test('');
27   test('shortlog');
28   test('log');
29   test('reflog');
30   test('36c6c6708b8360d7023e8a1649c45bcf9b3bd818');
31   test('36c6c6708b8360d7023e8a1649c45bcf9b3bd818/tree');
32   test('36c6c6708b8360d7023e8a1649c45bcf9b3bd818/diff');
33   test('36c6c6708b8360d7023e8a1649c45bcf9b3bd818/patch');
34   test('36c6c6708b8360d7023e8a1649c45bcf9b3bd818/patches/1');
35   test('36c6c6708b8360d7023e8a1649c45bcf9b3bd818/patches/2');
36   test('36c6c6708b8360d7023e8a1649c45bcf9b3bd818/history/dir1');
37   test('36c6c6708b8360d7023e8a1649c45bcf9b3bd818/blame/file1');
38   test('36c6c6708b8360d7023e8a1649c45bcf9b3bd818/raw/file1');
39   test('36c6c6708b8360d7023e8a1649c45bcf9b3bd818/blob/file1');
40
41   TODO: {
42       local $TODO = "FIXME";
43       test('search', 'type=commit&text=added');
44
45       # FIXME - What's the difference here?
46       #test('patch', 'h=3f7567c7bdf7e7ebf410926493b92d398333116e');
47       #test('patch', 'h=3f7567c7bdf7e7ebf410926493b92d398333116e;hp=3bc0634310b9c62222bb0e724c11ffdfb297b4ac');
48       #test('patches', 'h=3f7567c7bdf7e7ebf410926493b92d398333116e');
49       #test('patches', 'h=3f7567c7bdf7e7ebf410926493b92d398333116e;hp=3bc0634310b9c62222bb0e724c11ffdfb297b4ac');
50   }
51 }
52
53 done_testing;
54
55 sub test_uri {
56     my ($uri, $qs) = @_;
57     $qs ||= '';
58     my $request = "/$uri"; 
59     $request .= "?$qs" if defined $qs;
60     my $response = request($request);
61     ok($response->is_success, "ok $uri - $qs");
62     return $response;
63 }
64
65 sub curry_test_uri {
66     my $prefix = shift;
67     my $to_curry = shift || \&test_uri;
68     sub {
69         my $uri = shift;
70         $to_curry->("$prefix/$uri", @_);
71     };
72 }