devbox/scripts/test-install.py

44 lines
1.9 KiB
Python

#!/usr/bin/env python3
"""Installer smoke using explicit temporary binaries; never installs services."""
import os
from pathlib import Path
import subprocess
import tempfile
import unittest
INSTALLER = Path(__file__).resolve().parents[1] / 'install.sh'
class InstallTest(unittest.TestCase):
def test_optional_plugin(self):
for mode in ('default', 'flag', 'env'):
with self.subTest(mode=mode), tempfile.TemporaryDirectory() as tmp:
root = Path(tmp)
env = dict(os.environ)
env.pop('DEVBOX_INSTALL_HUB', None)
env.pop('DEVBOX_INSTALL_MCPD_PLUGIN', None)
for binary in ('devbox', 'devbox-hub', 'devbox-mcpd-plugin'):
source = root / binary
source.write_text(f'#!/bin/sh\necho {binary}-fixture\n')
source.chmod(0o755)
env[binary.upper().replace('-', '_') + '_BIN'] = str(source)
dest = root / 'installed'
args = ['sh', str(INSTALLER), '--no-service', '--bin-dir', str(dest)]
if mode == 'flag':
args += ['--mcpd-plugin', '--hub']
if mode == 'env':
env['DEVBOX_INSTALL_MCPD_PLUGIN'] = '1'
result = subprocess.run(args, env=env, capture_output=True, text=True, timeout=10)
self.assertEqual(result.returncode, 0, result.stderr)
expected = {'devbox'}
if mode != 'default':
expected.add('devbox-mcpd-plugin')
if mode == 'flag':
expected.add('devbox-hub')
self.assertEqual({p.name for p in dest.iterdir()}, expected)
for binary in expected:
self.assertEqual(subprocess.check_output([str(dest / binary)], text=True), f'{binary}-fixture\n')
if __name__ == '__main__':
unittest.main()