test SHA validation using a fake repository
Create a local repository instead of cloning one from the git server for the tests that verify the SHA values being tagged. Change-Id: I12b65577b93f07d383b9cfa131ef56d68bdd130a Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
parent
502fd6dfcd
commit
f942b9e076
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
import textwrap
|
import textwrap
|
||||||
|
|
||||||
@ -25,9 +26,48 @@ from openstack_releases.cmds import validate
|
|||||||
from openstack_releases import defaults
|
from openstack_releases import defaults
|
||||||
from openstack_releases import deliverable
|
from openstack_releases import deliverable
|
||||||
from openstack_releases import gitutils
|
from openstack_releases import gitutils
|
||||||
|
from openstack_releases import processutils
|
||||||
from openstack_releases import yamlutils
|
from openstack_releases import yamlutils
|
||||||
|
|
||||||
|
|
||||||
|
class GitRepoFixture(fixtures.Fixture):
|
||||||
|
|
||||||
|
logger = logging.getLogger('git')
|
||||||
|
|
||||||
|
def __init__(self, workdir, name):
|
||||||
|
self.workdir = workdir
|
||||||
|
self.name = name
|
||||||
|
self.path = os.path.join(self.workdir, self.name)
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super().setUp()
|
||||||
|
os.makedirs(self.path)
|
||||||
|
self.git('init', '.')
|
||||||
|
self.git('config', '--local', 'user.email', 'example@example.com')
|
||||||
|
self.git('config', '--local', 'user.name', 'super developer')
|
||||||
|
|
||||||
|
def git(self, *args):
|
||||||
|
self.logger.debug('$ git %s', ' '.join(args))
|
||||||
|
output = processutils.check_output(
|
||||||
|
['git'] + list(args),
|
||||||
|
cwd=self.path,
|
||||||
|
)
|
||||||
|
self.logger.debug(output)
|
||||||
|
return output
|
||||||
|
|
||||||
|
def commit(self, message='commit message'):
|
||||||
|
self.git('add', '.')
|
||||||
|
self.git('commit', '-m', message)
|
||||||
|
sha = self.git('show', '--pretty=format:%H')
|
||||||
|
return sha.decode('utf-8')
|
||||||
|
|
||||||
|
def add_file(self, name):
|
||||||
|
with open(os.path.join(self.path, name), 'w') as f:
|
||||||
|
f.write('adding %s\n' % name)
|
||||||
|
return self.commit('add %s' % name)
|
||||||
|
|
||||||
|
|
||||||
class TestDecorators(base.BaseTestCase):
|
class TestDecorators(base.BaseTestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@ -538,7 +578,13 @@ class TestValidateReleaseSHAExists(base.BaseTestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
self.ctx = validate.ValidationContext()
|
self.ctx = validate.ValidationContext()
|
||||||
gitutils.clone_repo(self.ctx.workdir, 'openstack/release-test')
|
self._make_repo()
|
||||||
|
|
||||||
|
def _make_repo(self):
|
||||||
|
self.repo = self.useFixture(
|
||||||
|
GitRepoFixture(self.ctx.workdir, 'openstack/release-test')
|
||||||
|
)
|
||||||
|
self.commit_1 = self.repo.add_file('testfile.txt')
|
||||||
|
|
||||||
def test_invalid_hash(self):
|
def test_invalid_hash(self):
|
||||||
deliv = deliverable.Deliverable(
|
deliv = deliverable.Deliverable(
|
||||||
@ -562,6 +608,28 @@ class TestValidateReleaseSHAExists(base.BaseTestCase):
|
|||||||
self.assertEqual(0, len(self.ctx.warnings))
|
self.assertEqual(0, len(self.ctx.warnings))
|
||||||
self.assertEqual(1, len(self.ctx.errors))
|
self.assertEqual(1, len(self.ctx.errors))
|
||||||
|
|
||||||
|
def test_valid_hash(self):
|
||||||
|
deliv = deliverable.Deliverable(
|
||||||
|
team='team',
|
||||||
|
series='ocata',
|
||||||
|
name='name',
|
||||||
|
data={
|
||||||
|
'artifact-link-mode': 'none',
|
||||||
|
'releases': [
|
||||||
|
{'version': '0.1',
|
||||||
|
'projects': [
|
||||||
|
{'repo': 'openstack/release-test',
|
||||||
|
'hash': self.commit_1,
|
||||||
|
'tarball-base': 'openstack-release-test'},
|
||||||
|
]}
|
||||||
|
],
|
||||||
|
},
|
||||||
|
)
|
||||||
|
validate.validate_release_sha_exists(deliv, self.ctx)
|
||||||
|
self.ctx.show_summary()
|
||||||
|
self.assertEqual(0, len(self.ctx.warnings))
|
||||||
|
self.assertEqual(1, len(self.ctx.errors))
|
||||||
|
|
||||||
def test_no_such_hash(self):
|
def test_no_such_hash(self):
|
||||||
deliv = deliverable.Deliverable(
|
deliv = deliverable.Deliverable(
|
||||||
team='team',
|
team='team',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user