From efe4f897c23d4fc19625a9479961b97637828ffc Mon Sep 17 00:00:00 2001 From: Edward Lemur Date: Thu, 7 Jun 2018 20:31:12 +0000 Subject: [PATCH] gclient: Add a test to make sure we're syncing CIPD dependencies. Bug: 849374 Change-Id: I5654ed65843c6dae6b7dbee10a40aa35e16803dc Reviewed-on: https://chromium-review.googlesource.com/1087390 Commit-Queue: Edward Lesmes Reviewed-by: Aaron Gable --- testing_support/cipd | 8 +++++++ testing_support/cipd.bat | 8 +++++++ testing_support/fake_cipd.py | 30 ++++++++++++++++++++++++++ testing_support/fake_repos.py | 13 ++++++++++++ tests/gclient_smoketest.py | 40 +++++++++++++++++++++++++++++++++++ 5 files changed, 99 insertions(+) create mode 100755 testing_support/cipd create mode 100755 testing_support/cipd.bat create mode 100644 testing_support/fake_cipd.py diff --git a/testing_support/cipd b/testing_support/cipd new file mode 100755 index 000000000..21519a129 --- /dev/null +++ b/testing_support/cipd @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +# Copyright (c) 2018 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +base_dir=$(dirname "$0") + +exec python "$base_dir/fake_cipd.py" "$@" diff --git a/testing_support/cipd.bat b/testing_support/cipd.bat new file mode 100755 index 000000000..a1a941061 --- /dev/null +++ b/testing_support/cipd.bat @@ -0,0 +1,8 @@ +echo off +:: Copyright (c) 2018 The Chromium Authors. All rights reserved. +:: Use of this source code is governed by a BSD-style license that can be +:: found in the LICENSE file. +setlocal + +:: Defer control. +python "%~dp0fake_cipd.py" %* diff --git a/testing_support/fake_cipd.py b/testing_support/fake_cipd.py new file mode 100644 index 000000000..782289383 --- /dev/null +++ b/testing_support/fake_cipd.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python +# Copyright (c) 2018 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import argparse +import os +import shutil +import sys + + +def main(): + assert sys.argv[1] == 'ensure' + parser = argparse.ArgumentParser() + parser.add_argument('-ensure-file') + parser.add_argument('-root') + args, _ = parser.parse_known_args() + + cipd_root = os.path.join(args.root, '.cipd') + if not os.path.isdir(cipd_root): + os.makedirs(cipd_root) + + if args.ensure_file: + shutil.copy(args.ensure_file, os.path.join(cipd_root, 'ensure')) + + return 0 + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/testing_support/fake_repos.py b/testing_support/fake_repos.py index 44d471824..63ea9912f 100755 --- a/testing_support/fake_repos.py +++ b/testing_support/fake_repos.py @@ -736,6 +736,19 @@ deps = { ], 'dep_type': 'cipd', }, + 'src/another_cipd_dep': { + 'packages': [ + { + 'package': 'package1', + 'version': '1.1-cr0', + }, + { + 'package': 'package2', + 'version': '1.13', + }, + ], + 'dep_type': 'cipd', + }, }"""), 'origin': 'git/repo_14@2\n' }) diff --git a/tests/gclient_smoketest.py b/tests/gclient_smoketest.py index 16a511f36..610da2a00 100755 --- a/tests/gclient_smoketest.py +++ b/tests/gclient_smoketest.py @@ -1349,6 +1349,21 @@ class GClientSmokeGIT(GClientSmokeBase): ' "url": "' + self.git_base + 'repo_14",', ' },', '', + ' # src -> src/another_cipd_dep:package1', + ' "src/another_cipd_dep": {', + ' "packages": [', + ' {', + ' "package": "package1",', + ' "version": "1.1-cr0",', + ' },', + ' {', + ' "package": "package2",', + ' "version": "1.13",', + ' },', + ' ],', + ' "dep_type": "cipd",', + ' },', + '', ' # src -> src/cipd_dep:package0', ' "src/cipd_dep": {', ' "packages": [', @@ -1711,6 +1726,31 @@ class BlinkDEPSTransitionSmokeTest(GClientSmokeBase): ['git', 'show-ref', '-q', '--verify', 'refs/heads/foo'], cwd=self.blink) +class GClientSmokeCipd(GClientSmokeBase): + def setUp(self): + super(GClientSmokeCipd, self).setUp() + self.enabled = self.FAKE_REPOS.set_up_git() + self.env['PATH'] = (os.path.join(ROOT_DIR, 'testing_support') + + os.pathsep + self.env['PATH']) + + def testSyncCipd(self): + self.gclient(['config', self.git_base + 'repo_14', '--name', 'src']) + self.gclient(['sync']) + + with open(os.path.join(self.root_dir, '.cipd', 'ensure')) as f: + contents = f.read() + + self.assertEqual([ + '@Subdir src/another_cipd_dep', + 'package1 1.1-cr0', + 'package2 1.13', + '', + '@Subdir src/cipd_dep', + 'package0 0.1', + '', + ], contents.splitlines()) + + if __name__ == '__main__': if '-v' in sys.argv: logging.basicConfig(level=logging.DEBUG)