Commit 35849c3a authored by Ayush Tiwari's avatar Ayush Tiwari

Add test for develop mode

parent 5b69b5c6
......@@ -137,6 +137,14 @@ class GitCloneNonInformativeTests(unittest.TestCase):
myFile.write(line)
myFile.close()
def checkLocalChanges(self, parent_local_change_path,
submodule_local_change_path):
# Check if the file are created at the expected position and check contents
self.assertTrue(os.path.exists(parent_local_change_path))
self.assertTrue(os.path.exists(submodule_local_change_path))
self.assertEqual(check_output(['cat', parent_local_change_path]), 'foo')
self.assertEqual(check_output(['cat', submodule_local_change_path]), 'bar')
def makeGitCloneRecipe(self, options):
from slapos.recipe.gitclone import Recipe
bo = {
......@@ -181,6 +189,71 @@ class GitCloneNonInformativeTests(unittest.TestCase):
self.assertTrue(os.path.exists(git_repository_path))
self.assertFalse(os.path.exists(bad_file_path), "pyc file not removed")
@with_buildout
def test_clone_and_update_submodule_develop_mode(self, buildout, write,
sample_buildout, **kw):
"""
Cloning in develop mode should be keeping the local change untouched, same
for update it should do nothing.
"""
self.setUpSubmoduleRepository()
# STEP I: Clone repositories in status M1 and S1 (M1---->S1)
write(sample_buildout, 'buildout.cfg',
"""
[buildout]
parts = git-clone
[git-clone]
recipe = slapos.recipe.build:gitclone
repository = %s
develop = true
""" % self.project_dir)
check_call([buildout])
main_repo_path = os.path.join(sample_buildout, 'parts', 'git-clone')
self.assertTrue(os.path.exists(main_repo_path))
submodule_repo_path = os.path.join(main_repo_path, 'dir1',
'submodule_repo')
# Check if the submodule is not empty
self.assertTrue(os.listdir(submodule_repo_path))
# Get the head commit of the submodule repo
head_commit_submodule_after_clone = self.getRepositoryHeadCommit(
submodule_repo_path)
# Add a marker file in parent as well as submodule repo
parent_local_change_path = os.path.join(main_repo_path,
'local_change_main')
submodule_local_change_path = os.path.join(submodule_repo_path,
'local_change_submodule')
self.echo(parent_local_change_path, 'foo')
self.echo(submodule_local_change_path, 'bar')
self.checkLocalChanges(parent_local_change_path, submodule_local_change_path)
# Update buildout and check local changes which still should be there
# unchanged
check_call([buildout])
self.checkLocalChanges(parent_local_change_path, submodule_local_change_path)
# Update the builout revision to trigger uninstall and install again. In
# this case, as there have been local changes, buildot will try to keep
# the repository directory
write(sample_buildout, 'buildout.cfg',
"""
[buildout]
parts = git-clone
[git-clone]
recipe = slapos.recipe.build:gitclone
repository = %s
revision = %s
develop = true
""" % (self.project_dir, str(self.getRepositoryHeadCommit(self.project_dir))))
check_call([buildout])
# The local changes should be still there
self.checkLocalChanges(parent_local_change_path, submodule_local_change_path)
@with_buildout
def test_clone_and_update_submodule(self, buildout, write, sample_buildout,
**kw):
......@@ -232,21 +305,13 @@ repository = %s
'local_change_submodule')
self.echo(parent_local_change_path, 'foo')
self.echo(submodule_local_change_path, 'bar')
# Check if the file are created at the expected position and check contents
self.assertTrue(os.path.exists(parent_local_change_path))
self.assertTrue(os.path.exists(submodule_local_change_path))
self.assertEqual(check_output(['cat', parent_local_change_path]), 'foo')
self.assertEqual(check_output(['cat', submodule_local_change_path]), 'bar')
self.checkLocalChanges(parent_local_change_path, submodule_local_change_path)
# Update buildout
check_call([buildout])
# The local changes should be still there
self.assertTrue(os.path.exists(parent_local_change_path))
self.assertTrue(os.path.exists(submodule_local_change_path))
self.assertEqual(check_output(['cat', parent_local_change_path]), 'foo')
self.assertEqual(check_output(['cat', submodule_local_change_path]), 'bar')
self.checkLocalChanges(parent_local_change_path, submodule_local_change_path)
# Update submodule repository and main repo separately
self.touch(self.project_dir, 'file2.py')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment