sapling/eden/fs/integration/repo_test.py
Adam Simpkins 90e1a87409 improvements to the repository command
Summary:
The "eden repository <name> <path>" command had a bug that it would duplicate
the existing edenrc contents when writing out a new config: it opened the file
in append mode rather than truncate mode when performing the write.

This addresses that issue, but also does a bigger overhaul of the config update
code.  We now acquire a lock for the duration of the modification, so that
another eden CLI process cannot modify the file between when we read it and
when we write out our modifications.  We also perform the write using an atomic
rename so the file contents are always valid at all points in time.

I also updated the CLI command to print the repositories in sorted order, and
to only catch expected exceptions, and show backtraces for unexpected errors.

Reviewed By: bolinfest

Differential Revision: D3554550

fbshipit-source-id: 5920ccb2447330673eac3f9956a8ae5d8a66a67e
2016-07-22 17:33:00 -07:00

69 lines
2.1 KiB
Python

# Copyright (c) 2016, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import os
from .lib import gitrepo
from .lib import hgrepo
from .lib import testcase
class RepoTest(testcase.EdenTestCase):
'''
Tests for the "eden repository" command.
Note that these tests do not use @testcase.eden_repo_test, since we don't
actually need to run separately with git and mercurial repositories. These
tests don't actually mount anything in eden at all.
'''
def test_list_repository(self):
self.assertEqual([], self._list_repos())
config = '''\
[repository fbsource]
path = /data/users/carenthomas/fbsource
type = git
[bindmounts fbsource]
fbcode-buck-out = fbcode/buck-out
fbandroid-buck-out = fbandroid/buck-out
fbobjc-buck-out = fbobjc/buck-out
buck-out = buck-out
[repository git]
path = /home/carenthomas/src/git
type = git
[repository hg-crew]
url = /data/users/carenthomas/facebook-hg-rpms/hg-crew
type = hg
'''
home_config_file = os.path.join(self.home_dir, '.edenrc')
with open(home_config_file, 'w') as f:
f.write(config)
expected = ['fbsource', 'git', 'hg-crew']
self.assertEqual(expected, self._list_repos())
def test_add_multiple(self):
hg_repo = self.create_repo('hg_repo', hgrepo.HgRepository)
git_repo = self.create_repo('git_repo', gitrepo.GitRepository)
self.eden.add_repository('hg1', hg_repo.path)
self.assertEqual(['hg1'], self._list_repos())
self.eden.add_repository('hg2', hg_repo.path)
self.assertEqual(['hg1', 'hg2'], self._list_repos())
self.eden.add_repository('git1', git_repo.path)
self.assertEqual(['git1', 'hg1', 'hg2'], self._list_repos())
def _list_repos(self):
return self.eden.repository_cmd().splitlines()