cloudflare/cloudflared
Publicmirrored from https://github.com/cloudflare/cloudflaredAvailable
component-tests/conftest.py
35lines · modecode
| 1 | import os |
| 2 | import pytest |
| 3 | import yaml |
| 4 | |
| 5 | from time import sleep |
| 6 | |
| 7 | from config import NamedTunnelConfig, ClassicTunnelConfig |
| 8 | from constants import BACKOFF_SECS |
| 9 | from util import LOGGER |
| 10 | |
| 11 | |
| 12 | @pytest.fixture(scope="session") |
| 13 | def component_tests_config(): |
| 14 | config_file = os.getenv("COMPONENT_TESTS_CONFIG") |
| 15 | if config_file is None: |
| 16 | raise Exception( |
| 17 | "Need to provide path to config file in COMPONENT_TESTS_CONFIG") |
| 18 | with open(config_file, 'r') as stream: |
| 19 | config = yaml.safe_load(stream) |
| 20 | LOGGER.info(f"component tests base config {config}") |
| 21 | |
| 22 | def _component_tests_config(additional_config={}, named_tunnel=True): |
| 23 | if named_tunnel: |
| 24 | return NamedTunnelConfig(additional_config=additional_config, |
| 25 | cloudflared_binary=config['cloudflared_binary'], tunnel=config['tunnel'], credentials_file=config['credentials_file'], ingress=config['ingress']) |
| 26 | return ClassicTunnelConfig( |
| 27 | additional_config=additional_config, cloudflared_binary=config['cloudflared_binary'], hostname=config['classic_hostname'], origincert=config['origincert']) |
| 28 | |
| 29 | return _component_tests_config |
| 30 | |
| 31 | |
| 32 | # This fixture is automatically called before each tests to make sure the previous cloudflared has been shutdown |
| 33 | @pytest.fixture(autouse=True) |
| 34 | def wait_previous_cloudflared(): |
| 35 | sleep(BACKOFF_SECS) |
| 36 | |