Commit f33b1f3f authored by Ayush Tiwari's avatar Ayush Tiwari

Update tests with cleaner comments

parent 35849c3a
......@@ -189,93 +189,31 @@ 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):
"""
STEP I:
Repositories status: Main repo(M1) and Submodule repo (S1)
Main repo (M1) ---references---> Submodule(S1)
Install should be M1+S1
STEP II:
Repositories status: Main repo(M2) and Submodule repo (S2)
Main repo (M2) ---references---> Submodule(S1)
Install should be M2+S1
STEP III:
Repositories status: Main repo(M3) and Submodule repo (S2)
Main repo (M3) ---references---> Submodule(S2)
Install should be M3+S2
Remote:
Repositories status: Parent repo(M1) and Submodule repo (S1)
Parent repo (M1) ---references---> Submodule(S1)
Local:
Buildout should install(using branch) at M1+S1
Remote:
Repositories status: Parent repo(M2) and Submodule repo (S2)
Parent repo (M2) ---references---> Submodule(S1)
Local:
Buildout should uninstall/install(using revision M2) at M2+S1
Remote:
Repositories status: Parent repo(M3) and Submodule repo (S2)
Parent repo (M3) ---references---> Submodule(S2)
Local:
Buildout should uninstall/install(using revision M3) at M3+S2
"""
self.setUpSubmoduleRepository()
# STEP I: Clone repositories in status M1 and S1 (M1---->S1)
# Clone repositories in status M1 and S1 (M1---->S1)
write(sample_buildout, 'buildout.cfg',
"""
[buildout]
......@@ -298,7 +236,7 @@ repository = %s
head_commit_submodule_after_clone = self.getRepositoryHeadCommit(
submodule_repo_path)
# Add a marker file in parent as well as submodule repo
# Add a marker file in parent as well as submodule repo to test for update
parent_local_change_path = os.path.join(main_repo_path,
'local_change_main')
submodule_local_change_path = os.path.join(submodule_repo_path,
......@@ -307,13 +245,14 @@ repository = %s
self.echo(submodule_local_change_path, 'bar')
self.checkLocalChanges(parent_local_change_path, submodule_local_change_path)
# Update buildout
# Trigger `update` method call for gitclone recipe
check_call([buildout])
# The local changes should be still there
# The local changes should be still there after update
self.checkLocalChanges(parent_local_change_path, submodule_local_change_path)
# Update submodule repository and main repo separately
# On REMOTE, update submodule repository and parent repo with new commit,
# but do not update the pointer to submodule on parent repo
self.touch(self.project_dir, 'file2.py')
self.gitAdd(self.project_dir)
self.gitCommit(self.project_dir, msg='Add file2 in main repo')
......@@ -321,9 +260,9 @@ repository = %s
self.gitAdd(self.submodule_dir)
self.gitCommit(self.submodule_dir, msg='Add file2 in submodule repo')
# STEP II: Clone repositories in status M2 and S2 (M2---->S1)
# Update the recipe with new revision which still point to the submodule
# old revision
# Clone repositories in status M2 and S2 (M2---->S1)
# Update the recipe with new revision for parent and trigger uninstall/
# install
write(sample_buildout, 'buildout.cfg',
"""
[buildout]
......@@ -349,17 +288,8 @@ revision = %s
head_commit_submodule_after_first_revision = self.getRepositoryHeadCommit(
submodule_repo_path)
# Change the HEAD of the cloned repository and then run buildout
check_call(['git', 'reset', '--hard', 'HEAD'], cwd=main_repo_path)
# Update buildout. This should fetch and reset to the revision given in
# the buildout
check_call([buildout])
head_commit_parent_repo_after_update = self.getRepositoryHeadCommit(
main_repo_path)
self.assertEqual(head_commit_parent_repo_after_update,
self.getRepositoryHeadCommit(self.project_dir))
# Update main repo with changes of submodule
# On REMOTE, add new commit to submodule and then update the submodule
# pointer on parent repo and commit it
submodule_dir_main_repo = os.path.join(self.project_dir, 'dir1',
'submodule_repo')
check_call(['git', 'checkout', 'master'], cwd=submodule_dir_main_repo)
......@@ -367,8 +297,9 @@ revision = %s
self.gitAdd(self.project_dir)
self.gitCommit(self.project_dir, msg='Update submodule version')
# STEP III: Clone repositories in status M3 and S2 (M3---->S2)
# Clone repositories in status M3 and S2 (M3---->S2)
# Update the recipe with new revision which points to submodule new revision
# and run uninstall/install again
write(sample_buildout, 'buildout.cfg',
"""
[buildout]
......
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