#!/usr/bin/env python3 """Run real provider hooks only against disposable nginx/index fixtures.""" from pathlib import Path import re import subprocess import tempfile import yaml root = Path(__file__).resolve().parents[2] hooks = yaml.safe_load((root / 'apps/indeedhub/manifest.yml').read_text())['app']['hooks']['post_install'] for mode in ('fresh', 'literal', 'legacy-filter'): with tempfile.TemporaryDirectory(prefix='indeehub-provider-hook-') as directory: fixture = Path(directory) nginx, index = fixture / 'default.conf', fixture / 'index.html' old_script = '' index.write_text('
' + (old_script if mode == 'literal' else '') + '') nginx.write_text('server {\n location = /sw.js {\n }\n' + ( " sub_filter '' '" + old_script + "';\n" if mode == 'legacy-filter' else '') + '}\n') first = None for repeat in range(2): for hook in hooks: command = hook.get('exec') if not command or command[0] == 'nginx': continue command = [argument.replace('/etc/nginx/conf.d/default.conf', str(nginx)).replace('/usr/share/nginx/html/index.html', str(index)) for argument in command] subprocess.run(command, check=True, capture_output=True, text=True) rendered = index.read_text() + nginx.read_text() assert len(re.findall(r'