S19: establish engineering repository
This commit is contained in:
59
tests/test_generator.py
Normal file
59
tests/test_generator.py
Normal file
@@ -0,0 +1,59 @@
|
||||
"""Check component selection and real Maven bootstrapping with generated/ absent."""
|
||||
import importlib.util
|
||||
import json
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
HOME = Path(__file__).resolve().parents[1]
|
||||
spec = importlib.util.spec_from_file_location('generator', HOME / 'create-project.py')
|
||||
generator = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(generator)
|
||||
|
||||
|
||||
class GeneratorTests(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.temporary = tempfile.TemporaryDirectory()
|
||||
cls.addClassCleanup(cls.temporary.cleanup)
|
||||
cls.root = Path(cls.temporary.name)
|
||||
cls.source = cls.root / 'engineering'
|
||||
shutil.copytree(HOME, cls.source, ignore=shutil.ignore_patterns('.git','target','__pycache__'))
|
||||
for args in (['init', '-q'], ['config','user.name','Recipe test'],
|
||||
['config','user.email','test@example.invalid'], ['add','.'],
|
||||
['commit','-qm','Test release'], ['tag','v1.0.0']):
|
||||
subprocess.run(['git','-C',str(cls.source),*args], check=True, stdout=subprocess.DEVNULL)
|
||||
generator.HOME = cls.source
|
||||
|
||||
def test_component_choices_and_bootstrap_without_generated_files(self):
|
||||
for components in (['backend'], ['frontend'], ['backend','frontend']):
|
||||
with self.subTest(components=components):
|
||||
project = self.root / ('consumer-' + '-'.join(components))
|
||||
generator.create(project, 'sample', components, str(self.source), 'v1.0.0', 'test-runner', 'https://landscape.invalid')
|
||||
self.assertEqual('backend' in components, (project / 'backend/pom.xml').exists())
|
||||
self.assertEqual('frontend' in components, (project / 'frontend/package.json').exists())
|
||||
self.assertIn('test-runner', (project / '.gitea/workflows/build.yaml').read_text())
|
||||
shutil.rmtree(project / 'generated')
|
||||
result = subprocess.run(['mvn','-N','-B','-ntp','-Pregenerate-engineering','validate'], cwd=project,
|
||||
text=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, timeout=180)
|
||||
self.assertEqual(0, result.returncode, result.stdout)
|
||||
self.assertTrue((project / 'generated/ci/Ci.java').exists())
|
||||
subprocess.run(['python3','scripts/engineering.py','--check'], cwd=project, check=True, stdout=subprocess.DEVNULL)
|
||||
if components == ['frontend']:
|
||||
for args in (['npm','ci'], ['npm','run','lint'], ['npm','test'], ['npm','run','build']):
|
||||
subprocess.run(args, cwd=project / 'frontend', check=True, stdout=subprocess.DEVNULL)
|
||||
self.assertTrue((project / 'frontend/dist/index.html').exists())
|
||||
|
||||
def test_generator_preserves_existing_destination(self):
|
||||
project = self.root / 'already-exists'
|
||||
project.mkdir()
|
||||
(project / 'important').write_text('preserve')
|
||||
with self.assertRaisesRegex(ValueError, 'must not exist'):
|
||||
generator.create(project, 'sample', ['backend'], str(self.source), 'v1.0.0', 'runner', 'landscape')
|
||||
self.assertEqual('preserve', (project / 'important').read_text())
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user