Patchwork [7,of,7,flagprocessor,v7] tests: test-flagprocessor.t

login
register
mail settings
Submitter Remi Chaintron
Date Jan. 2, 2017, 5:51 p.m.
Message ID <49eef591aa30f65223c4.1483379477@remi-mbp2>
Download mbox | patch
Permalink /patch/18074/
State Superseded
Delegated to: Pierre-Yves David
Headers show

Comments

Remi Chaintron - Jan. 2, 2017, 5:51 p.m.
# HG changeset patch
# User Remi Chaintron <remi@fb.com>
# Date 1483377654 18000
#      Mon Jan 02 12:20:54 2017 -0500
# Node ID 49eef591aa30f65223c4d5a1cd252840296ca983
# Parent  d4aaac74e17118d59373b8380fcd98b7bb0419d8
tests: test-flagprocessor.t

This patch introduces a test to check the behavior of the revlog flag processor.
- Introduces three extensions in tests/: base64, gzip and usr0:
  - the base64 extension encodes/decodes filelog contents.
  - the gzip extension compresses/decompresses filelog contents.
  - the usr0 extension simply registers None transforms on flag REVIDX_USR0.
- Tests that several extensions cannot register on the same flag (base64 + usr0)
- Tests the composition of base64 and gzip.

Patch

diff --git a/tests/base64ext.py b/tests/base64ext.py
new file mode 100644
--- /dev/null
+++ b/tests/base64ext.py
@@ -0,0 +1,59 @@ 
+# coding=UTF-8
+
+from __future__ import absolute_import
+
+import base64
+
+from mercurial import (
+    changegroup,
+    extensions,
+    filelog,
+    revlog,
+)
+
+def supportedoutgoingversions(orig, repo):
+    versions = orig(repo)
+    versions.discard('01')
+    versions.discard('02')
+    versions.add('03')
+    return versions
+
+def allsupportedversions(orig, ui):
+    versions = orig(ui)
+    versions.add('03')
+    return versions
+
+def bypass(self, text):
+    return (text, False)
+
+def encode(self, text):
+    return (base64.b64encode(text), False)
+
+def decode(self, text):
+    return (base64.b64decode(text), True)
+
+def addrevision(orig, self, text, transaction, link, p1, p2, cachedelta=None,
+                node=None, flags=revlog.REVIDX_DEFAULT_FLAGS):
+    if node is None:
+        node = revlog.hash(text, p1, p2)
+    flags |= revlog.REVIDX_USR0
+    return orig(self, text, transaction, link, p1, p2, cachedelta=cachedelta,
+                node=node, flags=flags)
+
+def extsetup(ui):
+    wrapfunction = extensions.wrapfunction
+
+    wrapfunction(changegroup,
+                 'supportedoutgoingversions',
+                 supportedoutgoingversions)
+    wrapfunction(changegroup,
+                 'allsupportedversions',
+                 allsupportedversions)
+
+    wrapfunction(filelog.filelog, 'addrevision', addrevision)
+
+    transform = (decode, encode, bypass)
+    revlog.addflagtransform(revlog.REVIDX_USR0, transform)
+
+
+
diff --git a/tests/gzipext.py b/tests/gzipext.py
new file mode 100644
--- /dev/null
+++ b/tests/gzipext.py
@@ -0,0 +1,59 @@ 
+# coding=UTF-8
+
+from __future__ import absolute_import
+
+import zlib
+
+from mercurial import (
+    changegroup,
+    extensions,
+    filelog,
+    revlog,
+)
+
+def supportedoutgoingversions(orig, repo):
+    versions = orig(repo)
+    versions.discard('01')
+    versions.discard('02')
+    versions.add('03')
+    return versions
+
+def allsupportedversions(orig, ui):
+    versions = orig(ui)
+    versions.add('03')
+    return versions
+
+def bypass(self, text):
+    return (text, False)
+
+def compress(self, text):
+    return (zlib.compress(text), False)
+
+def decompress(self, text):
+    return (zlib.decompress(text), True)
+
+def addrevision(orig, self, text, transaction, link, p1, p2, cachedelta=None,
+                node=None, flags=revlog.REVIDX_DEFAULT_FLAGS):
+    if node is None:
+        node = revlog.hash(text, p1, p2)
+    flags |= revlog.REVIDX_USR1
+    return orig(self, text, transaction, link, p1, p2, cachedelta=cachedelta,
+                node=node, flags=flags)
+
+def extsetup(ui):
+    wrapfunction = extensions.wrapfunction
+
+    wrapfunction(changegroup,
+                 'supportedoutgoingversions',
+                 supportedoutgoingversions)
+    wrapfunction(changegroup,
+                 'allsupportedversions',
+                 allsupportedversions)
+
+    wrapfunction(filelog.filelog, 'addrevision', addrevision)
+
+    transform = (decompress, compress, bypass)
+    revlog.addflagtransform(revlog.REVIDX_USR1, transform)
+
+
+
diff --git a/tests/test-flagprocessor.t b/tests/test-flagprocessor.t
new file mode 100644
--- /dev/null
+++ b/tests/test-flagprocessor.t
@@ -0,0 +1,81 @@ 
+# TEST 1: test extension composition
+  $ hg init server
+
+# Clone server and enable extensions
+  $ hg clone -q server client
+  $ cd client
+  $ cat >> .hg/hgrc <<EOF
+  > [extensions]
+  > base64=$TESTDIR/base64ext.py
+  > gzip=$TESTDIR/gzipext.py
+  > EOF
+
+# Commit file
+  $ echo contents > file
+  $ hg commit -Aqm 'add file'
+
+# Check base64 of the gzip compressed content is stored
+  $ hg debugdata file 0
+  eJxLzs8rSc0rKeYCABKzA3k= (no-eol)
+
+# Push changes to the server
+  $ hg push --traceback
+  pushing to $TESTTMP/server
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files
+
+# Initialize new client and setup extensions (no cloning)
+# Extensions loading is reversed to ensure flags follow the stable order
+  $ cd ../
+  $ mkdir client2
+  $ cd client2
+  $ hg init
+  $ cat >> .hg/hgrc <<EOF
+  > [paths]
+  > default = $TESTTMP/server
+  > [extensions]
+  > gzip=$TESTDIR/gzipext.py
+  > base64=$TESTDIR/base64ext.py
+  > EOF
+
+# Pull from server and update to the latest version
+  $ hg pull default
+  pulling from $TESTTMP/server
+  requesting all changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files
+  (run 'hg update' to get a working copy)
+  $ hg update --traceback
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+# Check base64 version is fetched and decoded correctly
+  $ hg debugdata file 0
+  eJxLzs8rSc0rKeYCABKzA3k= (no-eol)
+  $ hg cat -r . file
+  contents
+
+# TEST 2: Error on registering multiple transforms on the same flag
+  $ cd ../
+  $ hg init server2
+  $ cd server2
+  $ cat >> .hg/hgrc <<EOF
+  > [extensions]
+  > base64=$TESTDIR/base64ext.py
+  > usr0=$TESTDIR/usr0ext.py
+  > EOF
+
+# Commit file
+  $ echo contents > file
+  $ hg commit -Aqm 'add file'
+  abort: cannot register multiple transforms on flag '8'.
+  [255]
+
+
+
+
+
diff --git a/tests/usr0ext.py b/tests/usr0ext.py
new file mode 100644
--- /dev/null
+++ b/tests/usr0ext.py
@@ -0,0 +1,17 @@ 
+# coding=UTF-8
+
+from __future__ import absolute_import
+
+from mercurial import (
+    revlog,
+)
+
+def donothing(self, text):
+    return (text, True)
+
+def extsetup(ui):
+    transform = (donothing, donothing, donothing)
+    revlog.addflagtransform(revlog.REVIDX_USR0, transform)
+
+
+