Lann Martin | 10f3ee9 | 2018-08-22 15:48:10 -0600 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
| 2 | # Copyright 2018 The Chromium OS Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | """Tests for scripts/repo_sync_manifest.""" |
| 7 | |
| 8 | from __future__ import print_function |
| 9 | |
| 10 | import os |
| 11 | |
| 12 | from chromite.lib import cros_test_lib |
| 13 | from chromite.lib import osutils |
| 14 | from chromite.lib import repo_util |
| 15 | from chromite.lib import repo_util_unittest |
| 16 | from chromite.scripts import repo_sync_manifest |
| 17 | |
| 18 | |
| 19 | class RepoSyncManifestTest(cros_test_lib.MockTempDirTestCase): |
| 20 | """Unit tests for repo_sync_manifest.""" |
| 21 | |
| 22 | def setUp(self): |
| 23 | self.manifest = os.path.join(self.tempdir, 'manifest.xml') |
| 24 | osutils.Touch(self.manifest) |
| 25 | |
| 26 | self.repo_root = os.path.join(self.tempdir, 'root') |
| 27 | os.makedirs(os.path.join(self.repo_root, '.repo')) |
| 28 | |
| 29 | self.empty_root = os.path.join(self.tempdir, 'empty') |
| 30 | os.makedirs(os.path.join(self.empty_root)) |
| 31 | |
| 32 | self.mock_copy = self.PatchObject( |
| 33 | repo_util.Repository, 'Copy', |
| 34 | side_effect=repo_util_unittest.CopySideEffects) |
| 35 | self.mock_sync = self.PatchObject(repo_util.Repository, 'Sync') |
| 36 | |
| 37 | def testRepoRoot(self): |
| 38 | repo_sync_manifest.main([self.manifest, '--repo-root', self.repo_root]) |
| 39 | self.mock_sync.assert_called_with(manifest_path=self.manifest) |
| 40 | |
| 41 | def testCopyRepo(self): |
| 42 | repo_sync_manifest.main([self.manifest, '--repo-root', self.empty_root, |
| 43 | '--copy-repo', self.repo_root]) |
| 44 | self.mock_copy.assert_called_with(self.empty_root) |
| 45 | self.mock_sync.assert_called_with(manifest_path=self.manifest) |