##// END OF EJS Templates
tests: unify test-archive
Martin Geisler -
r11853:afe19a1b default
parent child Browse files
Show More
@@ -1,143 +1,220 b''
1 #!/bin/sh
1 $ mkdir test
2 $ cd test
3 $ hg init
4 $ echo foo>foo
5 $ hg commit -Am 1 -d '1 0'
6 adding foo
7 $ echo bar>bar
8 $ hg commit -Am 2 -d '2 0'
9 adding bar
10 $ mkdir baz
11 $ echo bletch>baz/bletch
12 $ hg commit -Am 3 -d '1000000000 0'
13 adding baz/bletch
14 $ echo "[web]" >> .hg/hgrc
15 $ echo "name = test-archive" >> .hg/hgrc
16 $ cp .hg/hgrc .hg/hgrc-base
17 > test_archtype() {
18 > echo "allow_archive = $1" >> .hg/hgrc
19 > hg serve -p $HGPORT -d --pid-file=hg.pid -E errors.log
20 > cat hg.pid >> $DAEMON_PIDS
21 > echo % $1 allowed should give 200
22 > "$TESTDIR/get-with-headers.py" localhost:$HGPORT "/archive/tip.$2" | head -n 1
23 > echo % $3 and $4 disallowed should both give 403
24 > "$TESTDIR/get-with-headers.py" localhost:$HGPORT "/archive/tip.$3" | head -n 1
25 > "$TESTDIR/get-with-headers.py" localhost:$HGPORT "/archive/tip.$4" | head -n 1
26 > "$TESTDIR/killdaemons.py"
27 > cat errors.log
28 > cp .hg/hgrc-base .hg/hgrc
29 > }
2
30
3 mkdir test
31 check http return codes
4 cd test
32
5 hg init
6 echo foo>foo
7 hg commit -Am 1 -d '1 0'
8 echo bar>bar
9 hg commit -Am 2 -d '2 0'
10 mkdir baz
11 echo bletch>baz/bletch
12 hg commit -Am 3 -d '1000000000 0'
13 echo "[web]" >> .hg/hgrc
14 echo "name = test-archive" >> .hg/hgrc
15 cp .hg/hgrc .hg/hgrc-base
16
33
17 # check http return codes
34 $ test_archtype gz tar.gz tar.bz2 zip
18 test_archtype() {
35 % gz allowed should give 200
19 echo "allow_archive = $1" >> .hg/hgrc
36 200 Script output follows
20 hg serve -p $HGPORT -d --pid-file=hg.pid -E errors.log
37 % tar.bz2 and zip disallowed should both give 403
21 cat hg.pid >> $DAEMON_PIDS
38 403 Archive type not allowed: bz2
22 echo % $1 allowed should give 200
39 403 Archive type not allowed: zip
23 "$TESTDIR/get-with-headers.py" localhost:$HGPORT "/archive/tip.$2" | head -n 1
40 $ test_archtype bz2 tar.bz2 zip tar.gz
24 echo % $3 and $4 disallowed should both give 403
41 % bz2 allowed should give 200
25 "$TESTDIR/get-with-headers.py" localhost:$HGPORT "/archive/tip.$3" | head -n 1
42 200 Script output follows
26 "$TESTDIR/get-with-headers.py" localhost:$HGPORT "/archive/tip.$4" | head -n 1
43 % zip and tar.gz disallowed should both give 403
27 "$TESTDIR/killdaemons.py"
44 403 Archive type not allowed: zip
28 cat errors.log
45 403 Archive type not allowed: gz
29 cp .hg/hgrc-base .hg/hgrc
46 $ test_archtype zip zip tar.gz tar.bz2
30 }
47 % zip allowed should give 200
48 200 Script output follows
49 % tar.gz and tar.bz2 disallowed should both give 403
50 403 Archive type not allowed: gz
51 403 Archive type not allowed: bz2
31
52
32 echo
53 $ echo "allow_archive = gz bz2 zip" >> .hg/hgrc
33 test_archtype gz tar.gz tar.bz2 zip
54 $ hg serve -p $HGPORT -d --pid-file=hg.pid -E errors.log
34 test_archtype bz2 tar.bz2 zip tar.gz
55 $ cat hg.pid >> $DAEMON_PIDS
35 test_archtype zip zip tar.gz tar.bz2
36
56
37 echo "allow_archive = gz bz2 zip" >> .hg/hgrc
57 invalid arch type should give 404
38 hg serve -p $HGPORT -d --pid-file=hg.pid -E errors.log
39 cat hg.pid >> $DAEMON_PIDS
40
58
41 echo % invalid arch type should give 404
59 $ "$TESTDIR/get-with-headers.py" localhost:$HGPORT "/archive/tip.invalid" | head -n 1
42 "$TESTDIR/get-with-headers.py" localhost:$HGPORT "/archive/tip.invalid" | head -n 1
60 404 Unsupported archive type: None
43 echo
44
61
45 TIP=`hg id -v | cut -f1 -d' '`
62 $ TIP=`hg id -v | cut -f1 -d' '`
46 QTIP=`hg id -q`
63 $ QTIP=`hg id -q`
47 cat > getarchive.py <<EOF
64 $ cat > getarchive.py <<EOF
48 import os, sys, urllib2
65 > import os, sys, urllib2
49 try:
66 > try:
50 # Set stdout to binary mode for win32 platforms
67 > # Set stdout to binary mode for win32 platforms
51 import msvcrt
68 > import msvcrt
52 msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
69 > msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
53 except ImportError:
70 > except ImportError:
54 pass
71 > pass
55
72 > node, archive = sys.argv[1:]
56 node, archive = sys.argv[1:]
73 > f = urllib2.urlopen('http://127.0.0.1:%s/?cmd=archive;node=%s;type=%s'
57 f = urllib2.urlopen('http://127.0.0.1:%s/?cmd=archive;node=%s;type=%s'
74 > % (os.environ['HGPORT'], node, archive))
58 % (os.environ['HGPORT'], node, archive))
75 > sys.stdout.write(f.read())
59 sys.stdout.write(f.read())
76 > EOF
60 EOF
77 $ python getarchive.py "$TIP" gz | gunzip | tar tf - 2>/dev/null | sed "s/$QTIP/TIP/"
61 python getarchive.py "$TIP" gz | gunzip | tar tf - 2>/dev/null | sed "s/$QTIP/TIP/"
78 test-archive-TIP/.hg_archival.txt
62 python getarchive.py "$TIP" bz2 | bunzip2 | tar tf - 2>/dev/null | sed "s/$QTIP/TIP/"
79 test-archive-TIP/bar
63 python getarchive.py "$TIP" zip > archive.zip
80 test-archive-TIP/baz/bletch
64 unzip -t archive.zip | sed "s/$QTIP/TIP/"
81 test-archive-TIP/foo
82 $ python getarchive.py "$TIP" bz2 | bunzip2 | tar tf - 2>/dev/null | sed "s/$QTIP/TIP/"
83 test-archive-TIP/.hg_archival.txt
84 test-archive-TIP/bar
85 test-archive-TIP/baz/bletch
86 test-archive-TIP/foo
87 $ python getarchive.py "$TIP" zip > archive.zip
88 $ unzip -t archive.zip | sed "s/$QTIP/TIP/"
89 Archive: archive.zip
90 testing: test-archive-TIP/.hg_archival.txt OK
91 testing: test-archive-TIP/bar OK
92 testing: test-archive-TIP/baz/bletch OK
93 testing: test-archive-TIP/foo OK
94 No errors detected in compressed data of archive.zip.
65
95
66 "$TESTDIR/killdaemons.py"
96 $ "$TESTDIR/killdaemons.py"
67
97
68 hg archive -t tar test.tar
98 $ hg archive -t tar test.tar
69 tar tf test.tar
99 $ tar tf test.tar
100 test/.hg_archival.txt
101 test/bar
102 test/baz/bletch
103 test/foo
104
105 $ hg archive -t tbz2 -X baz test.tar.bz2
106 $ bunzip2 -dc test.tar.bz2 | tar tf - 2>/dev/null
107 test/.hg_archival.txt
108 test/bar
109 test/foo
70
110
71 hg archive -t tbz2 -X baz test.tar.bz2
111 $ hg archive -t tgz -p %b-%h test-%h.tar.gz
72 bunzip2 -dc test.tar.bz2 | tar tf - 2>/dev/null
112 $ gzip -dc test-$QTIP.tar.gz | tar tf - 2>/dev/null | sed "s/$QTIP/TIP/"
73
113 test-TIP/.hg_archival.txt
74 hg archive -t tgz -p %b-%h test-%h.tar.gz
114 test-TIP/bar
75 gzip -dc test-$QTIP.tar.gz | tar tf - 2>/dev/null | sed "s/$QTIP/TIP/"
115 test-TIP/baz/bletch
116 test-TIP/foo
76
117
77 hg archive autodetected_test.tar
118 $ hg archive autodetected_test.tar
78 tar tf autodetected_test.tar
119 $ tar tf autodetected_test.tar
120 autodetected_test/.hg_archival.txt
121 autodetected_test/bar
122 autodetected_test/baz/bletch
123 autodetected_test/foo
79
124
80 # The '-t' should override autodetection
125 The '-t' should override autodetection
81 hg archive -t tar autodetect_override_test.zip
126
82 tar tf autodetect_override_test.zip
127 $ hg archive -t tar autodetect_override_test.zip
128 $ tar tf autodetect_override_test.zip
129 autodetect_override_test.zip/.hg_archival.txt
130 autodetect_override_test.zip/bar
131 autodetect_override_test.zip/baz/bletch
132 autodetect_override_test.zip/foo
83
133
84 for ext in tar tar.gz tgz tar.bz2 tbz2 zip; do
134 $ for ext in tar tar.gz tgz tar.bz2 tbz2 zip; do
85 hg archive auto_test.$ext
135 > hg archive auto_test.$ext
86 if [ -d auto_test.$ext ]; then
136 > if [ -d auto_test.$ext ]; then
87 echo "extension $ext was not autodetected."
137 > echo "extension $ext was not autodetected."
88 fi
138 > fi
89 done
139 > done
90
140
91 cat > md5comp.py <<EOF
141 $ cat > md5comp.py <<EOF
92 try:
142 > try:
93 from hashlib import md5
143 > from hashlib import md5
94 except ImportError:
144 > except ImportError:
95 from md5 import md5
145 > from md5 import md5
96 import sys
146 > import sys
97 f1, f2 = sys.argv[1:3]
147 > f1, f2 = sys.argv[1:3]
98 h1 = md5(file(f1, 'rb').read()).hexdigest()
148 > h1 = md5(file(f1, 'rb').read()).hexdigest()
99 h2 = md5(file(f2, 'rb').read()).hexdigest()
149 > h2 = md5(file(f2, 'rb').read()).hexdigest()
100 print h1 == h2 or "md5 differ: " + repr((h1, h2))
150 > print h1 == h2 or "md5 differ: " + repr((h1, h2))
101 EOF
151 > EOF
152
153 archive name is stored in the archive, so create similar
154
155 archives and rename them afterwards.
156
157 $ hg archive -t tgz tip.tar.gz
158 $ mv tip.tar.gz tip1.tar.gz
159 $ sleep 1
160 $ hg archive -t tgz tip.tar.gz
161 $ mv tip.tar.gz tip2.tar.gz
162 $ python md5comp.py tip1.tar.gz tip2.tar.gz
163 True
102
164
103 # archive name is stored in the archive, so create similar
165 $ hg archive -t zip -p /illegal test.zip
104 # archives and rename them afterwards.
166 abort: archive prefix contains illegal components
105 hg archive -t tgz tip.tar.gz
167 $ hg archive -t zip -p very/../bad test.zip
106 mv tip.tar.gz tip1.tar.gz
168
107 sleep 1
169 $ hg archive --config ui.archivemeta=false -t zip -r 2 test.zip
108 hg archive -t tgz tip.tar.gz
170 $ unzip -t test.zip
109 mv tip.tar.gz tip2.tar.gz
171 Archive: test.zip
110 python md5comp.py tip1.tar.gz tip2.tar.gz
172 testing: test/bar OK
173 testing: test/baz/bletch OK
174 testing: test/foo OK
175 No errors detected in compressed data of test.zip.
111
176
112 hg archive -t zip -p /illegal test.zip
177 $ hg archive -t tar - | tar tf - 2>/dev/null | sed "s/$QTIP/TIP/"
113 hg archive -t zip -p very/../bad test.zip
178 test-TIP/.hg_archival.txt
179 test-TIP/bar
180 test-TIP/baz/bletch
181 test-TIP/foo
114
182
115 hg archive --config ui.archivemeta=false -t zip -r 2 test.zip
183 $ hg archive -r 0 -t tar rev-%r.tar
116 unzip -t test.zip
184 $ if [ -f rev-0.tar ]; then
185 $ fi
117
186
118 hg archive -t tar - | tar tf - 2>/dev/null | sed "s/$QTIP/TIP/"
187 test .hg_archival.txt
119
188
120 hg archive -r 0 -t tar rev-%r.tar
189 $ hg archive ../test-tags
121 if [ -f rev-0.tar ]; then
190 $ cat ../test-tags/.hg_archival.txt
122 echo 'rev-0.tar created'
191 repo: daa7f7c60e0a224faa4ff77ca41b2760562af264
123 fi
192 node: 2c0277f05ed49d1c8328fb9ba92fba7a5ebcb33e
193 branch: default
194 latesttag: null
195 latesttagdistance: 3
196 $ hg tag -r 2 mytag
197 $ hg tag -r 2 anothertag
198 $ hg archive -r 2 ../test-lasttag
199 $ cat ../test-lasttag/.hg_archival.txt
200 repo: daa7f7c60e0a224faa4ff77ca41b2760562af264
201 node: 2c0277f05ed49d1c8328fb9ba92fba7a5ebcb33e
202 branch: default
203 tag: anothertag
204 tag: mytag
124
205
125 echo '% test .hg_archival.txt'
206 $ hg archive -t bogus test.bogus
126 hg archive ../test-tags
207 abort: unknown archive type 'bogus'
127 cat ../test-tags/.hg_archival.txt
128 hg tag -r 2 mytag
129 hg tag -r 2 anothertag
130 hg archive -r 2 ../test-lasttag
131 cat ../test-lasttag/.hg_archival.txt
132
208
133 hg archive -t bogus test.bogus
209 server errors
210
211 $ cat errors.log
134
212
135 echo % server errors
213 empty repo
136 cat errors.log
137
214
138 echo '% empty repo'
215 $ hg init ../empty
139 hg init ../empty
216 $ cd ../empty
140 cd ../empty
217 $ hg archive ../test-empty
141 hg archive ../test-empty
218 abort: no working directory: please specify a revision
142
219
143 exit 0
220 $ exit 0
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now