test: Add tests for webdir symlinks and walkrepos.
authorEric Hopper <hopper@omnifarious.org>
Fri, 21 Mar 2008 08:46:15 -0700
changeset 6341 63bdfcc3eaaf
parent 6340 949e607ac544
child 6342 92444fa7190b
test: Add tests for webdir symlinks and walkrepos.
tests/test-hgwebdirsym
tests/test-hgwebdirsym.out
tests/test-walkrepo.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-hgwebdirsym	Fri Mar 21 08:46:15 2008 -0700
@@ -0,0 +1,49 @@
+#!/bin/sh
+# Tests whether or not hgwebdir properly handles various symlink topologies.
+
+"$TESTDIR/hghave" symlink || exit 80
+
+hg init a
+echo a > a/a
+hg --cwd a ci -Ama -d'1 0'
+
+mkdir webdir
+cd webdir
+
+hg init b
+echo b > b/b
+hg --cwd b ci -Amb -d'2 0'
+
+hg init c
+echo c > c/c
+hg --cwd c ci -Amc -d'3 0'
+
+ln -s ../a al
+ln -s ../webdir circle
+
+root=`pwd`
+
+cd ..
+
+cat > collections.conf <<EOF
+[collections]
+$root=$root
+EOF
+
+hg serve -p $HGPORT -d --pid-file=hg.pid --webdir-conf collections.conf \
+    -A access-collections.log -E error-collections.log
+cat hg.pid >> $DAEMON_PIDS
+
+echo % should succeed
+"$TESTDIR/get-with-headers.py" localhost:$HGPORT '/?style=raw'
+"$TESTDIR/get-with-headers.py" localhost:$HGPORT '/al/file/tip/a?style=raw'
+"$TESTDIR/get-with-headers.py" localhost:$HGPORT '/b/file/tip/b?style=raw'
+"$TESTDIR/get-with-headers.py" localhost:$HGPORT '/c/file/tip/c?style=raw'
+
+echo % should fail
+"$TESTDIR/get-with-headers.py" localhost:$HGPORT '/circle/al/file/tip/a?style=raw'
+"$TESTDIR/get-with-headers.py" localhost:$HGPORT '/circle/b/file/tip/a?style=raw'
+"$TESTDIR/get-with-headers.py" localhost:$HGPORT '/circle/c/file/tip/a?style=raw'
+
+echo % collections errors
+cat error-collections.log
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-hgwebdirsym.out	Fri Mar 21 08:46:15 2008 -0700
@@ -0,0 +1,34 @@
+adding a
+adding b
+adding c
+% should succeed
+200 Script output follows
+
+
+/al/
+/b/
+/c/
+
+200 Script output follows
+
+a
+200 Script output follows
+
+b
+200 Script output follows
+
+c
+% should fail
+404 Not Found
+
+
+error: repository circle not found
+404 Not Found
+
+
+error: repository circle not found
+404 Not Found
+
+
+error: repository circle not found
+% collections errors
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-walkrepo.py	Fri Mar 21 08:46:15 2008 -0700
@@ -0,0 +1,53 @@
+import os
+import os.path
+from mercurial import hg, ui
+from mercurial.util import walkrepos, set, frozenset
+from os import mkdir, chdir
+from os.path import join as pjoin
+
+u = ui.ui()
+sym = hasattr(os, 'symlink') and hasattr(os.path, 'samestat')
+
+hg.repository(u, 'top1', create=1)
+mkdir('subdir')
+chdir('subdir')
+hg.repository(u, 'sub1', create=1)
+mkdir('subsubdir')
+chdir('subsubdir')
+hg.repository(u, 'subsub1', create=1)
+chdir(os.path.pardir)
+if sym:
+    os.symlink(os.path.pardir, 'circle')
+    os.symlink(pjoin('subsubdir', 'subsub1'), 'subsub1')
+
+def runtest():
+    reposet = frozenset(walkrepos('.', followsym=True))
+    if sym and (len(reposet) != 3):
+        print "reposet = %r" % (reposet,)
+        raise SystemExit(1, "Found %d repositories when I should have found 3" % (len(reposet),))
+    if (not sym) and (len(reposet) != 2):
+        print "reposet = %r" % (reposet,)
+        raise SystemExit(1, "Found %d repositories when I should have found 2" % (len(reposet),))
+    sub1set = frozenset((pjoin('.', 'sub1'),
+                         pjoin('.', 'circle', 'subdir', 'sub1')))
+    if len(sub1set & reposet) != 1:
+        print "sub1set = %r" % (sub1set,)
+        print "reposet = %r" % (reposet,)
+        raise SystemExit(1, "sub1set and reposet should have exactly one path in common.")
+    sub2set = frozenset((pjoin('.', 'subsub1'),
+                         pjoin('.', 'subsubdir', 'subsub1')))
+    if len(sub2set & reposet) != 1:
+        print "sub2set = %r" % (sub2set,)
+        print "reposet = %r" % (reposet,)
+        raise SystemExit(1, "sub1set and reposet should have exactly one path in common.")
+    sub3 = pjoin('.', 'circle', 'top1')
+    if sym and not (sub3 in reposet):
+        print "reposet = %r" % (reposet,)
+        raise SystemExit(1, "Symbolic links are supported and %s is not in reposet" % (sub3,))
+
+runtest()
+if sym:
+    # Simulate not having symlinks.
+    del os.path.samestat
+    sym = False
+    runtest()