def testCommitStagedCIPD(self, update_mock): with tempfile_ext.NamedTemporaryDirectory() as workDir,\ tempfile_ext.NamedTemporaryDirectory() as repoRoot,\ cts_utils.chdir(workDir): cts_utils_test.setup_fake_repo(repoRoot) cts_updater = update_cts.UpdateCTS('.', repoRoot) with self.assertRaises(update_cts.MissingDirError): cts_updater.commit_staged_cipd() cts_utils_test.writefile(CIPD_DATA['yaml'], os.path.join('staged', 'cipd.yaml')) with cts_utils.chdir('staged'): generate_zip_file(CONFIG_DATA['file11'], CONFIG_DATA['apk1']) generate_zip_file(CONFIG_DATA['file12'], CONFIG_DATA['apk1']) generate_zip_file(CONFIG_DATA['file21'], CONFIG_DATA['apk2a'], CONFIG_DATA['apk2b']) with self.assertRaises(update_cts.MissingFileError): cts_updater.commit_staged_cipd() generate_zip_file(CONFIG_DATA['file22'], CONFIG_DATA['apk2a'], CONFIG_DATA['apk2b']) update_mock.return_value = 'newcipdversion' cts_updater.commit_staged_cipd() update_mock.assert_called_with( os.path.join(workDir, 'staged', 'cipd.yaml')) self.assertEqual('newcipdversion', cts_utils_test.readfile('cipd_version.txt'))
def testUpdateRepository_buildbotUpdateError(self, cmd_mock, run_mock): with tempfile_ext.NamedTemporaryDirectory() as workDir,\ tempfile_ext.NamedTemporaryDirectory() as repoRoot,\ cts_utils.chdir(workDir): cts_utils_test.setup_fake_repo(repoRoot) cts_updater = update_cts.UpdateCTS('.', repoRoot) cts_utils_test.writefile('newversion', 'cipd_version.txt') cts_utils_test.writefile(CIPD_DATA['yaml'], os.path.join('staged', 'cipd.yaml')) cmd_mock.return_value = '' run_mock.return_value = 1 with self.assertRaises(IOError): cts_updater.update_repository()
def testUpdateRepository(self, cmd_mock, run_mock): with tempfile_ext.NamedTemporaryDirectory() as workDir,\ tempfile_ext.NamedTemporaryDirectory() as repoRoot,\ cts_utils.chdir(workDir): cts_utils_test.setup_fake_repo(repoRoot) cts_updater = update_cts.UpdateCTS('.', repoRoot) cts_utils_test.writefile('newversion', 'cipd_version.txt') cts_utils_test.writefile(CIPD_DATA['yaml'], os.path.join('staged', 'cipd.yaml')) cts_utils_test.writefile( CIPD_DATA['yaml'], os.path.join(os.path.join('staged', 'cipd.yaml'))) cmd_mock.return_value = '' run_mock.return_value = 0 cts_updater.update_repository() self._assertCIPDVersionUpdated(repoRoot, 'newversion') repo_cipd_yaml = os.path.join(repoRoot, cts_utils.TOOLS_DIR, cts_utils.CIPD_FILE) run_mock.assert_any_call([ 'cp', os.path.join(workDir, 'staged', 'cipd.yaml'), repo_cipd_yaml ]) run_mock.assert_any_call([ 'cipd', 'ensure', '-root', os.path.dirname(repo_cipd_yaml), '-ensure-file', mock.ANY ]) run_mock.assert_any_call(['python', GENERATE_BUILDBOT_JSON])
def testStageCIPDUpdate(self): with tempfile_ext.NamedTemporaryDirectory() as workDir,\ tempfile_ext.NamedTemporaryDirectory() as repoRoot,\ cts_utils.chdir(workDir): cts_utils_test.setup_fake_repo(repoRoot) cts_utils_test.writefile( 'n1', os.path.join('filtered', CONFIG_DATA['base11'])) cts_utils_test.writefile( 'n3', os.path.join('filtered', CONFIG_DATA['base12'])) for i in [str(i) for i in range(1, 5)]: cts_utils_test.writefile( 'o' + i, os.path.join('cipd', CIPD_DATA['file' + i])) cts_updater = update_cts.UpdateCTS('.', repoRoot) cts_updater.stage_cipd_update() self.assertTrue(os.path.isdir('staged')) with cts_utils.chdir('staged'): self.assertEqual( 'n1', cts_utils_test.readfile(CONFIG_DATA['file11'])) self.assertEqual( 'n3', cts_utils_test.readfile(CONFIG_DATA['file12'])) self.assertEqual( 'o2', cts_utils_test.readfile(CONFIG_DATA['file21'])) self.assertEqual( 'o4', cts_utils_test.readfile(CONFIG_DATA['file22'])) self.assertEqual(CIPD_DATA['yaml'], cts_utils_test.readfile('cipd.yaml'))
def testUpdateRepository_inconsistentFiles(self, cmd_mock, run_mock): with tempfile_ext.NamedTemporaryDirectory() as workDir,\ tempfile_ext.NamedTemporaryDirectory() as repoRoot,\ cts_utils.chdir(workDir): cts_utils_test.setup_fake_repo(repoRoot) cts_updater = update_cts.UpdateCTS('.', repoRoot) cts_utils_test.writefile('newversion', 'cipd_version.txt') cts_utils_test.writefile(CIPD_DATA['yaml'], os.path.join('staged', 'cipd.yaml')) cmd_mock.return_value = '' run_mock.return_value = 0 cts_utils_test.writefile( CIPD_DATA['template'] % ('wrong/package/name', CIPD_DATA['file1'], CIPD_DATA['file2'], CIPD_DATA['file3'], CIPD_DATA['file4']), os.path.join(os.path.join('staged', 'cipd.yaml'))) with self.assertRaises(update_cts.InconsistentFilesException): cts_updater.update_repository()