Don Garrett | c4114cc | 2016-11-01 20:04:06 -0700 | [diff] [blame] | 1 | # Copyright 2016 The Chromium OS Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | """Unit tests for chromite.lib.git and helpers for testing that module.""" |
| 6 | |
| 7 | from __future__ import print_function |
| 8 | |
| 9 | from chromite.scripts import bootstrap |
| 10 | from chromite.lib import cros_build_lib_unittest |
| 11 | from chromite.lib import cros_test_lib |
| 12 | |
| 13 | |
| 14 | class BootstrapTest(cros_build_lib_unittest.RunCommandTestCase): |
| 15 | """Tests for bootstrap script.""" |
| 16 | |
| 17 | def testExtractBranchName(self): |
| 18 | """Test that we can correctly extract branch values from cbuildbot args.""" |
| 19 | cases = ( |
| 20 | ([], 'master'), |
| 21 | (['--arg1', 'value', '-a', '--arg2'], 'master'), |
| 22 | (['--branch', 'branch'], 'branch'), |
| 23 | (['-b', 'branch'], 'branch'), |
| 24 | (['--arg1', 'value', '-a', '--branch', 'branch', '--arg2'], 'branch'), |
| 25 | (['--arg1', '-a', '--branch', 'branch', 'config'], 'branch'), |
| 26 | ) |
| 27 | |
| 28 | for args, expected in cases: |
| 29 | result = bootstrap.ExtractBranchName(args) |
| 30 | self.assertEqual(result, expected) |
| 31 | |
| 32 | def testRunCbuildbot(self): |
| 33 | bootstrap.RunCbuildbot('/mock/chromite', ['foo', 'bar', 'arg']) |
| 34 | self.assertCommandContains( |
| 35 | ['/mock/chromite/bin/cbuildbot', 'foo', 'bar', 'arg']) |
| 36 | |
| 37 | def testMainMaster(self): |
| 38 | bootstrap.main(['foo']) |
| 39 | |
| 40 | # cbuildbot script is in tempdir, so can't be listed here. |
| 41 | self.assertCommandContains(['foo']) |
| 42 | |
| 43 | def testMainBranch(self): |
| 44 | bootstrap.main(['--branch', 'branch', 'foo']) |
| 45 | |
| 46 | # cbuildbot script is in tempdir, so can't be listed here. |
| 47 | self.assertCommandContains(['--branch', 'branch', 'foo']) |
| 48 | |
| 49 | |
| 50 | class LiveWorktreeTest(cros_test_lib.TempDirTestCase): |
| 51 | """Integration tests for git worktree usage.""" |
| 52 | |
| 53 | @cros_test_lib.NetworkTest() |
| 54 | def testCreateChromiteBranch(self): |
| 55 | """Test that we can a git worktree, from the current chromite, branched.""" |
| 56 | bootstrap.CloneChromiteOnBranch('release-R56-9000.B', self.tempdir) |