44 lines
2.1 KiB
Python
44 lines
2.1 KiB
Python
import importlib.util
|
|
from pathlib import Path
|
|
import subprocess
|
|
import tempfile
|
|
import unittest
|
|
from unittest.mock import patch
|
|
|
|
spec = importlib.util.spec_from_file_location('source_audit', Path(__file__).resolve().parents[2] / 'scripts/release_source_audit.py')
|
|
m = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(m)
|
|
|
|
|
|
class SourceAudit(unittest.TestCase):
|
|
def test_missing_or_diverged_source_cannot_be_reported_as_covered(self):
|
|
with tempfile.TemporaryDirectory() as tmp, patch.object(m, 'ROOT', Path(tmp)):
|
|
def git(*args):
|
|
return subprocess.check_output(['git', *args], cwd=tmp, text=True, stderr=subprocess.DEVNULL).strip()
|
|
git('init', '-q')
|
|
git('config', 'user.name', 'Local test')
|
|
git('config', 'user.email', 'test@example.invalid')
|
|
path = Path(tmp) / 'src'
|
|
path.mkdir()
|
|
(path / 'a').write_text('baseline')
|
|
git('add', '.')
|
|
git('commit', '-qm', 'baseline')
|
|
initial = git('rev-parse', 'HEAD')
|
|
(path / 'a').write_text('live fix')
|
|
git('commit', '-qam', 'live fix')
|
|
live = git('rev-parse', 'HEAD')
|
|
snapshot = {'items': [{'metadata': {'name': n}, 'spec': {'template': {'spec': {'containers': [
|
|
{'image': 'registry/api@sha256:test', 'env': [{'name': 'DROBOTICFLOW_BUILD_COMMIT', 'value': live}]}]}}}}
|
|
for n in ('droboticflow-api', 'droboticflow-annotation-processor', 'droboticflow-worker')]}
|
|
self.assertTrue(m.audit(snapshot, 'HEAD')['lineageComplete'])
|
|
git('checkout', '-qb', 'partial-pr', initial)
|
|
(path / 'other').write_text('other feature')
|
|
git('add', '.')
|
|
git('commit', '-qm', 'partial')
|
|
result = m.audit(snapshot, 'HEAD')
|
|
self.assertFalse(result['lineageComplete'])
|
|
self.assertIn('src/a', result['components'][0]['differentPaths'])
|
|
self.assertFalse(m.audit({'items': snapshot['items'][:1]}, live)['lineageComplete'])
|
|
with self.assertRaises(ValueError):
|
|
m.audit(snapshot, 'missing-ref')
|