gitweb: Add optional output caching
[git/jnareb-git.git] / t / t9502-gitweb-standalone-parse-output.sh
blobbc8cb9220bc24b844bec8ee7351abe62a39a9dde
1 #!/bin/sh
3 # Copyright (c) 2009 Mark Rada
6 test_description='gitweb as standalone script (parsing script output).
8 This test runs gitweb (git web interface) as a CGI script from the
9 commandline, and checks that it produces the correct output, either
10 in the HTTP header or the actual script output.'
13 . ./gitweb-lib.sh
15 # ----------------------------------------------------------------------
16 # snapshot file name and prefix
18 cat >>gitweb_config.perl <<\EOF
20 $known_snapshot_formats{'tar'} = {
21 'display' => 'tar',
22 'type' => 'application/x-tar',
23 'suffix' => '.tar',
24 'format' => 'tar',
27 $feature{'snapshot'}{'default'} = ['tar'];
28 EOF
30 # Call check_snapshot with the arguments "<basename> [<prefix>]"
32 # This will check that gitweb HTTP header contains proposed filename
33 # as <basename> with '.tar' suffix added, and that generated tarfile
34 # (gitweb message body) has <prefix> as prefix for al files in tarfile
36 # <prefix> default to <basename>
37 check_snapshot () {
38 basename=$1
39 prefix=${2:-"$1"}
40 echo "basename=$basename"
41 grep "filename=.*$basename.tar" gitweb.headers >/dev/null 2>&1 &&
42 "$TAR" tf gitweb.body >file_list &&
43 ! grep -v "^$prefix/" file_list
46 test_expect_success setup '
47 test_commit first foo &&
48 git branch xx/test &&
49 FULL_ID=$(git rev-parse --verify HEAD) &&
50 SHORT_ID=$(git rev-parse --verify --short=7 HEAD)
52 test_debug '
53 echo "FULL_ID = $FULL_ID"
54 echo "SHORT_ID = $SHORT_ID"
57 test_expect_success 'snapshot: full sha1' '
58 gitweb_run "p=.git;a=snapshot;h=$FULL_ID;sf=tar" &&
59 check_snapshot ".git-$SHORT_ID"
61 test_debug 'cat gitweb.headers && cat file_list'
63 test_expect_success 'snapshot: shortened sha1' '
64 gitweb_run "p=.git;a=snapshot;h=$SHORT_ID;sf=tar" &&
65 check_snapshot ".git-$SHORT_ID"
67 test_debug 'cat gitweb.headers && cat file_list'
69 test_expect_success 'snapshot: almost full sha1' '
70 ID=$(git rev-parse --short=30 HEAD) &&
71 gitweb_run "p=.git;a=snapshot;h=$ID;sf=tar" &&
72 check_snapshot ".git-$SHORT_ID"
74 test_debug 'cat gitweb.headers && cat file_list'
76 test_expect_success 'snapshot: HEAD' '
77 gitweb_run "p=.git;a=snapshot;h=HEAD;sf=tar" &&
78 check_snapshot ".git-HEAD-$SHORT_ID"
80 test_debug 'cat gitweb.headers && cat file_list'
82 test_expect_success 'snapshot: short branch name (master)' '
83 gitweb_run "p=.git;a=snapshot;h=master;sf=tar" &&
84 ID=$(git rev-parse --verify --short=7 master) &&
85 check_snapshot ".git-master-$ID"
87 test_debug 'cat gitweb.headers && cat file_list'
89 test_expect_success 'snapshot: short tag name (first)' '
90 gitweb_run "p=.git;a=snapshot;h=first;sf=tar" &&
91 ID=$(git rev-parse --verify --short=7 first) &&
92 check_snapshot ".git-first-$ID"
94 test_debug 'cat gitweb.headers && cat file_list'
96 test_expect_success 'snapshot: full branch name (refs/heads/master)' '
97 gitweb_run "p=.git;a=snapshot;h=refs/heads/master;sf=tar" &&
98 ID=$(git rev-parse --verify --short=7 master) &&
99 check_snapshot ".git-master-$ID"
101 test_debug 'cat gitweb.headers && cat file_list'
103 test_expect_success 'snapshot: full tag name (refs/tags/first)' '
104 gitweb_run "p=.git;a=snapshot;h=refs/tags/first;sf=tar" &&
105 check_snapshot ".git-first"
107 test_debug 'cat gitweb.headers && cat file_list'
109 test_expect_success 'snapshot: hierarchical branch name (xx/test)' '
110 gitweb_run "p=.git;a=snapshot;h=xx/test;sf=tar" &&
111 ! grep "filename=.*/" gitweb.headers
113 test_debug 'cat gitweb.headers'
116 # ----------------------------------------------------------------------
117 # whether gitweb with caching enabled produces the same output
119 test_expect_success 'setup for caching tests (utf8 commit, binary file)' '
120 . "$TEST_DIRECTORY"/t3901-utf8.txt &&
121 cp "$TEST_DIRECTORY"/test9200a.png image.png &&
122 git add image.png &&
123 git commit -F "$TEST_DIRECTORY"/t3900/1-UTF-8.txt &&
124 gitweb_run "p=.git;a=patch" &&
125 mv gitweb.body no_cache.html &&
126 gitweb_run "p=.git;a=blob_plain;f=image.png" &&
127 mv gitweb.body no_cache.png
130 gitweb_enable_caching
132 for desc in 'generating cache' 'cached version'; do
133 test_expect_success "caching enabled, HTML output, $desc" '
134 gitweb_run "p=.git;a=patch" &&
135 mv gitweb.body cache.html &&
136 test_cmp no_cache.html cache.html
138 done
140 for desc in 'generating cache' 'cached version'; do
141 test_expect_success "caching enabled, binary output, $desc" '
142 gitweb_run "p=.git;a=blob_plain;f=image.png" &&
143 mv gitweb.body cache.png &&
144 cmp no_cache.png cache.png
146 done
148 test_done