Bug 1054112 - Port prevent-uuid-changes hook to .t test; r=edmorley
authorGregory Szorc <gps@mozilla.com>
Thu, 14 Aug 2014 21:21:41 -0700
changeset 921 6f1da8433d97
parent 920 4fbca8878852
child 922 66518e730778
push id129
push usergszorc@mozilla.com
push dateFri, 15 Aug 2014 17:47:15 +0000
treeherderversion-control-tools@6f1da8433d97 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersedmorley
bugs1054112
Bug 1054112 - Port prevent-uuid-changes hook to .t test; r=edmorley runtests.py before and after output: Ran 43 tests in 3.171s Ran 34 tests in 2.583s
hghooks/runtests.py
hghooks/tests/test-prevent-uuid-changes.t
--- a/hghooks/runtests.py
+++ b/hghooks/runtests.py
@@ -582,112 +582,10 @@ class TestCaseOnlyRenameHook(unittest.Te
            join(self.clonedir, "TESTFILE"));
     commit(ui, self.clonerepo, message="checkin 2")
 
     appendFile(join(self.clonedir, "TESTFILE"), "checkin 3")
     commit(ui, self.clonerepo, message="checkin 3")
 
     self.assertRaises(util.Abort, push, ui, self.clonerepo, dest=self.repodir)
 
-class TestPreventUUIDHook(unittest.TestCase):
-  def setUp(self):
-    self.ui = ui.ui()
-    self.ui.quiet = True
-    self.ui.verbose = False
-    self.repodir = mkdtemp(prefix="hg-TestPreventUUIDHook")
-    init(self.ui, dest=self.repodir)
-    addHook(self.repodir, "prevent_uuid_changes.hook")
-    self.repo = hg.repository(self.ui, self.repodir)
-    self.clonedir = mkdtemp(prefix="hg-test")
-    clone(self.ui, self.repo, self.clonedir)
-    self.clonerepo = hg.repository(self.ui, self.clonedir)
-    # Create a pre-existing repo with a file that contains UUID
-    appendFile(join(self.clonedir, "original.idl"), "uuid(abc123)")
-    add(self.ui, self.clonerepo, join(self.clonedir, "original.idl"))
-    commit(self.ui, self.clonerepo, message="original repo commit ba=me")
-    push(self.ui, self.clonerepo, dest=self.repodir)
-    print "===== In method", self._testMethodName, " ======="
-
-  def tearDown(self):
-    shutil.rmtree(self.repodir)
-    shutil.rmtree(self.clonedir)
-
-  def testUUIDEditExistingShouldFail(self):
-    """ Test that editing .idl file with 'uuid(' and no 'ba=' should fail  """
-    u = self.ui
-    editFile(join(self.clonedir, "original.idl"), "uuid(abc123)", "uuid(def456)")
-    commit(u, self.clonerepo, message="checkin 1 bug 12345")
-    self.assertRaises(util.Abort, push, u, self.clonerepo, dest=self.repodir)
-
-  def testUUIDEditExistingShouldPass(self):
-    """ Test that editing .idl file with 'uuid(' with ba=... should pass """
-    u = self.ui
-    editFile(join(self.clonedir, "original.idl"), "uuid(abc123)", "uuid(def456)")
-    commit(u, self.clonerepo, message="checkin 1 bug 12345 ba=me")
-    result = push(u, self.clonerepo, dest=self.repodir)
-    self.assertEqual(result, 0)
-
-  def testUUIDMultiplePushShouldFail(self):
-    """ Test that adding .idl file with uuid with other files and no 'ba=' should fail  """
-    u = self.ui
-    appendFile(join(self.clonedir, "testfile1.idl"), "uuid(something here)")
-    add(u, self.clonerepo, join(self.clonedir, "testfile1.idl"))
-    commit(u, self.clonerepo, message="checkin 1 bug 12345")
-    appendFile(join(self.clonedir, "testfile2.txt"), "checkin2")
-    add(u, self.clonerepo, join(self.clonedir, "testfile2.txt"))
-    commit(u, self.clonerepo, message="checkin 2 bug 12345")
-    self.assertRaises(util.Abort, push, u, self.clonerepo, dest=self.repodir)
-
-  def testUUIDMultiplePushShouldPass(self):
-    """ Test that changeset with 'uuid(' change in .idl should pass if 'ba=...' is in the push comment """
-    u = self.ui
-    appendFile(join(self.clonedir, "testfile3.idl"), "uuid(something here)")
-    add(u, self.clonerepo, join(self.clonedir, "testfile3.idl"))
-    commit(u, self.clonerepo, message="checkin 3 bug 12345")
-    appendFile(join(self.clonedir, "testfile2.txt"), "checkin2")
-    add(u, self.clonerepo, join(self.clonedir, "testfile2.txt"))
-    commit(u, self.clonerepo, message="checkin 2 bug 12345 ba=approver")
-    result = push(u, self.clonerepo, dest=self.repodir)
-    self.assertEqual(result, 0)
-
-  def testUUIDNonIDLShouldPass(self):
-    """ Test that changeset with 'uuid(' change in a file not ending in .idl should pass """
-    u = self.ui
-    appendFile(join(self.clonedir, "testfile1.txt"), "uuid(something here)")
-    add(u, self.clonerepo, join(self.clonedir, "testfile1.txt"))
-    commit(u, self.clonerepo, message="checkin 1 bug 12345")
-    result = push(u, self.clonerepo, dest=self.repodir)
-    self.assertEqual(result, 0)
-
-  def testUUIDRemoveUUIDNoApprovalShouldFail(self):
-    """ Test that changeset with 'uuid(' removed from file ending in .idl should fail """
-    u = self.ui
-    appendFile(join(self.clonedir, "original.idl"), "line of text")
-    removeFromFile(join(self.clonedir, "original.idl"), "uuid(abc123)")
-    commit(u, self.clonerepo, message="checkin removed uuid bug 12345")
-    self.assertRaises(util.Abort, push, u, self.clonerepo, dest=self.repodir)
-
-  def testUUIDRemoveUUIDWithApprovalShouldPass(self):
-    """ Test that changeset with 'uuid(' removed from file ending in .idl should pass with ba=... """
-    u = self.ui
-    appendFile(join(self.clonedir, "original.idl"), "line of text")
-    removeFromFile(join(self.clonedir, "original.idl"), "uuid(abc123)")
-    commit(u, self.clonerepo, message="checkin removed uuid bug 12345 ba=me")
-    result = push(u, self.clonerepo, dest=self.repodir)
-    self.assertEqual(result, 0)
-
-  def testUUIDDeletedIDLApproveShouldPass(self):
-    """ Test that changeset with .idl file removed should pass with ba= approval """
-    u = self.ui
-    remove(u, self.clonerepo, join(self.clonedir, "original.idl"))
-    commit(u, self.clonerepo, message="checkin 2 removed idl file ba=approver")
-    result = push(u, self.clonerepo, dest=self.repodir)
-    self.assertEqual(result, 0)
-
-  def testUUIDDeletedIDLNoApproveShouldFail(self):
-    """ Test that changeset with .idl file removed should fail without approval"""
-    u = self.ui
-    remove(u, self.clonerepo, join(self.clonedir, "original.idl"))
-    commit(u, self.clonerepo, message="checkin 2 removed idl file ")
-    self.assertRaises(util.Abort, push, u, self.clonerepo, dest=self.repodir)
-
 if __name__ == '__main__':
   unittest.main()
new file mode 100644
--- /dev/null
+++ b/hghooks/tests/test-prevent-uuid-changes.t
@@ -0,0 +1,204 @@
+  $ hg init server
+  $ cat >> server/.hg/hgrc << EOF
+  > [hooks]
+  > pretxnchangegroup.prevent_uuid_changes = python:mozhghooks.prevent_uuid_changes.hook
+  > EOF
+
+  $ hg init client
+  $ cd client
+  $ echo "uuid(abc123)" > original.idl
+  $ hg commit -A -m 'Add original.idl; ba=me'
+  adding original.idl
+  $ hg push ../server
+  pushing to ../server
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files
+  You've signaled approval for the binary change(s) in your push, thanks for the extra caution.
+
+Editing a UUID without ba= should fail
+
+  $ echo "uuid(def456)" > original.idl
+  $ hg commit -m 'Changing UUID'
+  $ hg push ../server
+  pushing to ../server
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files
+  
+  
+  ************************** ERROR ****************************
+  
+  *** IDL file original.idl altered in this changeset***
+  
+  Changes to IDL files in this repo require you to provide binary change approval in your top comment in the form of ba=... (or, more accurately, ba\S*=...)
+  This is to ensure that UUID changes (or method changes missing corresponding UUID change) are caught early, before release.
+  
+  *************************************************************
+  
+  
+  transaction abort!
+  rollback completed
+  abort: pretxnchangegroup.prevent_uuid_changes hook failed
+  [255]
+
+Editing a UUID with ba= should pass
+
+  $ hg commit --amend -m 'Changing UUID; ba=me'
+  saved backup bundle to $TESTTMP/client/.hg/strip-backup/5475ca91db3f-amend-backup.hg
+  $ hg push ../server
+  pushing to ../server
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files
+  You've signaled approval for the binary change(s) in your push, thanks for the extra caution.
+
+Editing .idl file with UUID with other files and no ba= should fail
+
+  $ echo "uuid(something here)" > testfile1.idl
+  $ hg commit -A -m 'adding testfile1'
+  adding testfile1.idl
+  $ echo "checkin2" > testfile2.txt
+  $ hg commit -A -m 'testfile2'
+  adding testfile2.txt
+  $ hg push ../server
+  pushing to ../server
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 2 changesets with 2 changes to 2 files
+  
+  
+  ************************** ERROR ****************************
+  
+  *** IDL file testfile1.idl altered in this changeset***
+  
+  Changes to IDL files in this repo require you to provide binary change approval in your top comment in the form of ba=... (or, more accurately, ba\S*=...)
+  This is to ensure that UUID changes (or method changes missing corresponding UUID change) are caught early, before release.
+  
+  *************************************************************
+  
+  
+  transaction abort!
+  rollback completed
+  abort: pretxnchangegroup.prevent_uuid_changes hook failed
+  [255]
+
+Adding ba= anywhere in the push will get through the hook
+
+  $ hg commit --amend -m 'Unrelated commit; ba=approver'
+  saved backup bundle to $TESTTMP/client/.hg/strip-backup/c2ca04c9aa66-amend-backup.hg
+  $ hg push ../server
+  pushing to ../server
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 2 changesets with 2 changes to 2 files
+  You've signaled approval for the binary change(s) in your push, thanks for the extra caution.
+
+uuid( in a non-idl file shouldn't be screened by the hook
+
+  $ echo "uuid(ignored)" > ignored.txt
+  $ hg commit -A -m 'adding ignored.txt'
+  adding ignored.txt
+  $ hg push ../server
+  pushing to ../server
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files
+
+Removing uuid() from an .idl file without ba= should fail
+
+  $ echo "not idl" > original.idl
+  $ hg commit -m 'removing uuid'
+  $ hg push ../server
+  pushing to ../server
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files
+  
+  
+  ************************** ERROR ****************************
+  
+  *** IDL file original.idl altered in this changeset***
+  
+  Changes to IDL files in this repo require you to provide binary change approval in your top comment in the form of ba=... (or, more accurately, ba\S*=...)
+  This is to ensure that UUID changes (or method changes missing corresponding UUID change) are caught early, before release.
+  
+  *************************************************************
+  
+  
+  transaction abort!
+  rollback completed
+  abort: pretxnchangegroup.prevent_uuid_changes hook failed
+  [255]
+
+Removing UUID with ba= approval should pass
+
+  $ hg commit --amend -m 'Removing UUID; ba=me'
+  saved backup bundle to $TESTTMP/client/.hg/strip-backup/72d6c9de6844-amend-backup.hg
+  $ hg push ../server
+  pushing to ../server
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files
+  You've signaled approval for the binary change(s) in your push, thanks for the extra caution.
+
+Removing an .idl with UUID without approval should fail
+
+  $ echo "uuid(123)" > existing.idl
+  $ hg commit -A -m 'adding existing.idl; ba=me'
+  adding existing.idl
+  $ hg push ../server >/dev/null
+  $ hg rm existing.idl
+  $ hg commit -m 'Removing existing'
+  $ hg push ../server
+  pushing to ../server
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 0 changes to 0 files
+  
+  
+  ************************** ERROR ****************************
+  
+  *** IDL file existing.idl altered in this changeset***
+  
+  Changes to IDL files in this repo require you to provide binary change approval in your top comment in the form of ba=... (or, more accurately, ba\S*=...)
+  This is to ensure that UUID changes (or method changes missing corresponding UUID change) are caught early, before release.
+  
+  *************************************************************
+  
+  
+  transaction abort!
+  rollback completed
+  abort: pretxnchangegroup.prevent_uuid_changes hook failed
+  [255]
+
+Removing an .idl with UUID with approval should pass
+
+  $ hg commit --amend -m 'Removing existing; ba=me'
+  saved backup bundle to $TESTTMP/client/.hg/strip-backup/d6eafdbb87e1-amend-backup.hg
+  $ hg push ../server
+  pushing to ../server
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 0 changes to 0 files
+  You've signaled approval for the binary change(s) in your push, thanks for the extra caution.