summaryrefslogtreecommitdiff
path: root/scripts/cros_mark_as_stable_unittest.py
diff options
context:
space:
mode:
authorMike Frysinger <vapier@chromium.org>2012-05-24 18:17:38 -0400
committerGerrit <chrome-bot@google.com>2012-05-31 09:49:15 -0700
commit6cb624a11596132868ee384ab1a2b0a1330bca5d (patch)
tree5f27c25f60ac7f5187d8f92d23cb744991934292 /scripts/cros_mark_as_stable_unittest.py
parente522add7f9cf7d6d573a66e36a9c7e47fca0e1d6 (diff)
downloadchromite-6cb624a11596132868ee384ab1a2b0a1330bca5d.tar.gz
cros_mark_{chrome_,}as_stable: relocate to scripts/
We don't import these as modules, just execute them directly, so move them to the scripts/ subdir. BUG=None TEST=`./buildbot/run_tests` passes TEST=`cbuildbot arm-tegra2-paladin` with manual uprev works TEST=`cbuildbot x86-generic-tot-chrome-pfq-informational` passes Change-Id: I33b064aafa06b506022ba930c953f625bbb13795 Reviewed-on: https://gerrit.chromium.org/gerrit/23569 Commit-Ready: Mike Frysinger <vapier@chromium.org> Reviewed-by: Mike Frysinger <vapier@chromium.org> Tested-by: Mike Frysinger <vapier@chromium.org>
Diffstat (limited to 'scripts/cros_mark_as_stable_unittest.py')
-rwxr-xr-xscripts/cros_mark_as_stable_unittest.py112
1 files changed, 112 insertions, 0 deletions
diff --git a/scripts/cros_mark_as_stable_unittest.py b/scripts/cros_mark_as_stable_unittest.py
new file mode 100755
index 000000000..635de287c
--- /dev/null
+++ b/scripts/cros_mark_as_stable_unittest.py
@@ -0,0 +1,112 @@
+#!/usr/bin/python
+
+# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Unit tests for cros_mark_as_stable.py."""
+
+import mox
+import os
+import sys
+import unittest
+
+sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(__file__)),
+ '..', '..'))
+from chromite.buildbot import constants
+from chromite.buildbot import constants
+from chromite.lib import cros_build_lib
+from chromite.scripts import cros_mark_as_stable
+
+
+# pylint: disable=W0212,R0904
+class NonClassTests(mox.MoxTestBase):
+ def setUp(self):
+ mox.MoxTestBase.setUp(self)
+ self.mox.StubOutWithMock(cros_build_lib, 'RunCommand')
+ self.mox.StubOutWithMock(cros_build_lib, 'RunCommandCaptureOutput')
+ self._branch = 'test_branch'
+ self._target_manifest_branch = 'cros/master'
+
+ def testPushChange(self):
+ git_log = 'Marking test_one as stable\nMarking test_two as stable\n'
+ fake_description = 'Marking set of ebuilds as stable\n\n%s' % git_log
+ self.mox.StubOutWithMock(cros_mark_as_stable, '_DoWeHaveLocalCommits')
+ self.mox.StubOutWithMock(cros_mark_as_stable.GitBranch, 'CreateBranch')
+ self.mox.StubOutWithMock(cros_mark_as_stable.GitBranch, 'Exists')
+ self.mox.StubOutWithMock(cros_build_lib, 'GitPushWithRetry')
+ self.mox.StubOutWithMock(cros_build_lib, 'GetTrackingBranch')
+ self.mox.StubOutWithMock(cros_build_lib, 'SyncPushBranch')
+ self.mox.StubOutWithMock(cros_build_lib, 'CreatePushBranch')
+ self.mox.StubOutWithMock(cros_build_lib, 'RunGitCommand')
+
+ cros_mark_as_stable._DoWeHaveLocalCommits(
+ self._branch, self._target_manifest_branch, '.').AndReturn(True)
+ cros_build_lib.GetTrackingBranch('.', for_push=True).AndReturn(
+ ['gerrit', 'refs/remotes/gerrit/master'])
+ cros_build_lib.SyncPushBranch('.', 'gerrit', 'refs/remotes/gerrit/master')
+ cros_mark_as_stable._DoWeHaveLocalCommits(
+ self._branch, 'refs/remotes/gerrit/master', '.').AndReturn(True)
+ result = cros_build_lib.CommandResult(output=git_log)
+ cros_build_lib.RunCommandCaptureOutput(
+ ['git', 'log', '--format=format:%s%n%n%b',
+ 'refs/remotes/gerrit/master..%s' % self._branch],
+ cwd='.').AndReturn(result)
+ cros_build_lib.CreatePushBranch('merge_branch', '.')
+ cros_build_lib.RunGitCommand('.', ['merge', '--squash', self._branch])
+ cros_build_lib.RunGitCommand('.', ['commit', '-m', fake_description])
+ cros_build_lib.RunGitCommand('.', ['config', 'push.default', 'tracking'])
+ cros_build_lib.GitPushWithRetry('merge_branch', '.', dryrun=False)
+ self.mox.ReplayAll()
+ cros_mark_as_stable.PushChange(self._branch, self._target_manifest_branch,
+ False, '.')
+ self.mox.VerifyAll()
+
+
+class GitBranchTest(mox.MoxTestBase):
+
+ def setUp(self):
+ mox.MoxTestBase.setUp(self)
+ # Always stub RunCommmand out as we use it in every method.
+ self.mox.StubOutWithMock(cros_build_lib, 'RunCommand')
+ self.mox.StubOutWithMock(cros_build_lib, 'RunCommandCaptureOutput')
+ self._branch = self.mox.CreateMock(cros_mark_as_stable.GitBranch)
+ self._branch_name = 'test_branch'
+ self._branch.branch_name = self._branch_name
+ self._target_manifest_branch = 'cros/test'
+ self._branch.tracking_branch = self._target_manifest_branch
+ self._branch.cwd = '.'
+
+ def testCheckoutCreate(self):
+ # Test init with no previous branch existing.
+ self._branch.Exists(self._branch_name).AndReturn(False)
+ cros_build_lib.RunCommandCaptureOutput(['repo', 'start', self._branch_name,
+ '.'], print_cmd=False, cwd='.')
+ self.mox.ReplayAll()
+ cros_mark_as_stable.GitBranch.Checkout(self._branch)
+ self.mox.VerifyAll()
+
+ def testCheckoutNoCreate(self):
+ # Test init with previous branch existing.
+ self._branch.Exists(self._branch_name).AndReturn(True)
+ cros_build_lib.RunCommandCaptureOutput(['git', 'checkout', '-f',
+ self._branch_name], print_cmd=False,
+ cwd='.')
+ self.mox.ReplayAll()
+ cros_mark_as_stable.GitBranch.Checkout(self._branch)
+ self.mox.VerifyAll()
+
+ def testExists(self):
+ branch = cros_mark_as_stable.GitBranch(self._branch_name,
+ self._target_manifest_branch, '.')
+ # Test if branch exists that is created
+ result = cros_build_lib.CommandResult(output=self._branch_name + '\n')
+ cros_build_lib.RunCommandCaptureOutput(['git', 'branch'], print_cmd=False,
+ cwd='.').AndReturn(result)
+ self.mox.ReplayAll()
+ self.assertTrue(branch.Exists())
+ self.mox.VerifyAll()
+
+
+if __name__ == '__main__':
+ unittest.main()