2014-06-26 19:37:07 +00:00
|
|
|
import logging
|
|
|
|
import os.path
|
|
|
|
from pytest import raises
|
|
|
|
import shutil
|
|
|
|
|
|
|
|
from .. import repo_utils
|
|
|
|
repo_utils.log.setLevel(logging.WARNING)
|
|
|
|
|
|
|
|
|
|
|
|
class TestRepoUtils(object):
|
|
|
|
empty_repo = 'https://github.com/ceph/empty'
|
|
|
|
local_dir = '/tmp/empty'
|
|
|
|
|
|
|
|
def setup(self):
|
|
|
|
assert not os.path.exists(self.local_dir)
|
|
|
|
|
|
|
|
def teardown(self):
|
|
|
|
shutil.rmtree(self.local_dir, ignore_errors=True)
|
|
|
|
|
|
|
|
def test_existing_branch(self):
|
2014-06-30 16:10:31 +00:00
|
|
|
repo_utils.enforce_repo_state(self.empty_repo, self.local_dir,
|
|
|
|
'master')
|
2014-06-26 19:37:07 +00:00
|
|
|
assert os.path.exists(self.local_dir)
|
|
|
|
|
|
|
|
def test_non_existing_branch(self):
|
|
|
|
with raises(repo_utils.BranchNotFoundError):
|
2014-06-30 16:10:31 +00:00
|
|
|
repo_utils.enforce_repo_state(self.empty_repo, self.local_dir,
|
|
|
|
'blah')
|
2014-06-26 19:37:07 +00:00
|
|
|
assert not os.path.exists(self.local_dir)
|
|
|
|
|
|
|
|
def test_multiple_calls_same_branch(self):
|
2014-06-30 16:10:31 +00:00
|
|
|
repo_utils.enforce_repo_state(self.empty_repo, self.local_dir,
|
|
|
|
'master')
|
2014-06-26 19:37:07 +00:00
|
|
|
assert os.path.exists(self.local_dir)
|
2014-06-30 16:10:31 +00:00
|
|
|
repo_utils.enforce_repo_state(self.empty_repo, self.local_dir,
|
|
|
|
'master')
|
2014-06-26 19:37:07 +00:00
|
|
|
assert os.path.exists(self.local_dir)
|
2014-06-30 16:10:31 +00:00
|
|
|
repo_utils.enforce_repo_state(self.empty_repo, self.local_dir,
|
|
|
|
'master')
|
2014-06-26 19:37:07 +00:00
|
|
|
assert os.path.exists(self.local_dir)
|
|
|
|
|
|
|
|
def test_multiple_calls_different_branches(self):
|
|
|
|
with raises(repo_utils.BranchNotFoundError):
|
2014-06-30 16:10:31 +00:00
|
|
|
repo_utils.enforce_repo_state(self.empty_repo, self.local_dir,
|
|
|
|
'blah1')
|
2014-06-26 19:37:07 +00:00
|
|
|
assert not os.path.exists(self.local_dir)
|
2014-06-30 16:10:31 +00:00
|
|
|
repo_utils.enforce_repo_state(self.empty_repo, self.local_dir,
|
|
|
|
'master')
|
2014-06-26 19:37:07 +00:00
|
|
|
assert os.path.exists(self.local_dir)
|
2014-06-30 16:10:31 +00:00
|
|
|
repo_utils.enforce_repo_state(self.empty_repo, self.local_dir,
|
|
|
|
'master')
|
2014-06-26 19:37:07 +00:00
|
|
|
assert os.path.exists(self.local_dir)
|
|
|
|
with raises(repo_utils.BranchNotFoundError):
|
2014-06-30 16:10:31 +00:00
|
|
|
repo_utils.enforce_repo_state(self.empty_repo, self.local_dir,
|
|
|
|
'blah2')
|
2014-06-26 19:37:07 +00:00
|
|
|
assert not os.path.exists(self.local_dir)
|
2014-06-30 16:10:31 +00:00
|
|
|
repo_utils.enforce_repo_state(self.empty_repo, self.local_dir,
|
|
|
|
'master')
|
2014-06-26 19:37:07 +00:00
|
|
|
assert os.path.exists(self.local_dir)
|