Commit 468f3883 authored by Ayush Tiwari's avatar Ayush Tiwari

Update tests to use buildout

parent 2843fc08
...@@ -9,6 +9,8 @@ import stat ...@@ -9,6 +9,8 @@ import stat
import tempfile import tempfile
import unittest import unittest
import zc.buildout.testing import zc.buildout.testing
from zc.buildout.testing import buildoutTearDown
from functools import wraps
from subprocess import check_call, check_output, CalledProcessError from subprocess import check_call, check_output, CalledProcessError
from slapos.recipe.gitclone import GIT_CLONE_ERROR_MESSAGE, \ from slapos.recipe.gitclone import GIT_CLONE_ERROR_MESSAGE, \
GIT_CLONE_CACHE_ERROR_MESSAGE GIT_CLONE_CACHE_ERROR_MESSAGE
...@@ -28,6 +30,16 @@ def setUp(test): ...@@ -28,6 +30,16 @@ def setUp(test):
zc.buildout.testing.buildoutSetUp(test) zc.buildout.testing.buildoutSetUp(test)
zc.buildout.testing.install_develop('slapos.recipe.build', test) zc.buildout.testing.install_develop('slapos.recipe.build', test)
def with_buildout(wrapped):
def wrapper(self):
self.globs = {}
setUp(self)
try:
wrapped(self, **self.globs)
finally:
buildoutTearDown(self)
return wraps(wrapped)(wrapper)
class GitCloneNonInformativeTests(unittest.TestCase): class GitCloneNonInformativeTests(unittest.TestCase):
def setUp(self): def setUp(self):
...@@ -164,7 +176,8 @@ class GitCloneNonInformativeTests(unittest.TestCase): ...@@ -164,7 +176,8 @@ class GitCloneNonInformativeTests(unittest.TestCase):
self.assertTrue(os.path.exists(git_repository_path)) self.assertTrue(os.path.exists(git_repository_path))
self.assertFalse(os.path.exists(bad_file_path), "pyc file not removed") self.assertFalse(os.path.exists(bad_file_path), "pyc file not removed")
def test_clone_and_udpate_submodule(self): @with_buildout
def test_clone_and_udpate_submodule(self, buildout, write, sample_buildout, **kw):
""" """
STEP I: STEP I:
Repositories status: Main repo(M1) and Submodule repo (S1) Repositories status: Main repo(M1) and Submodule repo (S1)
...@@ -182,14 +195,20 @@ class GitCloneNonInformativeTests(unittest.TestCase): ...@@ -182,14 +195,20 @@ class GitCloneNonInformativeTests(unittest.TestCase):
Install should be M3+S2 Install should be M3+S2
""" """
self.setUpSubmoduleRepository() self.setUpSubmoduleRepository()
# STEP I: Clone repositories in status M1 and S1 (M1---->S1) # STEP I: Clone repositories in status M1 and S1 (M1---->S1)
recipe = self.makeGitCloneRecipe( write(sample_buildout, 'buildout.cfg',
{ """
'repository': self.project_dir, [buildout]
} parts = git-clone
)
recipe.install() [git-clone]
main_repo_path = os.path.join(self.parts_directory_path, "test") recipe = slapos.recipe.build:gitclone
repository = %s
""" % 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)) self.assertTrue(os.path.exists(main_repo_path))
submodule_repo_path = os.path.join(main_repo_path, 'dir1', submodule_repo_path = os.path.join(main_repo_path, 'dir1',
'submodule_repo') 'submodule_repo')
...@@ -211,13 +230,18 @@ class GitCloneNonInformativeTests(unittest.TestCase): ...@@ -211,13 +230,18 @@ class GitCloneNonInformativeTests(unittest.TestCase):
# STEP II: Clone repositories in status M2 and S2 (M2---->S1) # STEP II: Clone repositories in status M2 and S2 (M2---->S1)
# Update the recipe with new revision which still point to the submodule # Update the recipe with new revision which still point to the submodule
# old revision # old revision
recipe = self.makeGitCloneRecipe( write(sample_buildout, 'buildout.cfg',
{ """
'repository': self.project_dir, [buildout]
'revision': str(self.getRepositoryHeadCommit(self.project_dir)) parts = git-clone
}
) [git-clone]
recipe.update() recipe = slapos.recipe.build:gitclone
repository = %s
revision = %s
""" % (self.project_dir, str(self.getRepositoryHeadCommit(self.project_dir))))
check_call([buildout])
self.assertTrue(os.path.exists(main_repo_path)) self.assertTrue(os.path.exists(main_repo_path))
# Check if the submodule is not empty # Check if the submodule is not empty
self.assertTrue(os.listdir(submodule_repo_path)) self.assertTrue(os.listdir(submodule_repo_path))
...@@ -236,13 +260,18 @@ class GitCloneNonInformativeTests(unittest.TestCase): ...@@ -236,13 +260,18 @@ class GitCloneNonInformativeTests(unittest.TestCase):
# STEP III: Clone repositories in status M3 and S2 (M3---->S2) # STEP III: Clone repositories in status M3 and S2 (M3---->S2)
# Update the recipe with new revision which points to submodule new revision # Update the recipe with new revision which points to submodule new revision
recipe = self.makeGitCloneRecipe( write(sample_buildout, 'buildout.cfg',
{ """
'repository': self.project_dir, [buildout]
'revision': str(self.getRepositoryHeadCommit(self.project_dir)) parts = git-clone
}
) [git-clone]
recipe.update() recipe = slapos.recipe.build:gitclone
repository = %s
revision = %s
""" % (self.project_dir, str(self.getRepositoryHeadCommit(self.project_dir))))
check_call([buildout])
self.assertTrue(os.path.exists(main_repo_path)) self.assertTrue(os.path.exists(main_repo_path))
# Check if the submodule is not empty # Check if the submodule is not empty
self.assertTrue(os.listdir(submodule_repo_path)) self.assertTrue(os.listdir(submodule_repo_path))
......
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