cloudflare/cloudflared
Publicmirrored from https://github.com/cloudflare/cloudflaredAvailable
component-tests/conftest.py
45lines · 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 | |
| 24 | # Regression test for TUN-4177, running with proxy-dns should not prevent tunnels from running |
| 25 | additional_config["proxy-dns"] = True |
| 26 | additional_config["proxy-dns-port"] = 9053 |
| 27 | |
| 28 | if named_tunnel: |
| 29 | return NamedTunnelConfig(additional_config=additional_config, |
| 30 | cloudflared_binary=config['cloudflared_binary'], |
| 31 | tunnel=config['tunnel'], |
| 32 | credentials_file=config['credentials_file'], |
| 33 | ingress=config['ingress']) |
| 34 | |
| 35 | return ClassicTunnelConfig( |
| 36 | additional_config=additional_config, cloudflared_binary=config['cloudflared_binary'], |
| 37 | hostname=config['classic_hostname'], origincert=config['origincert']) |
| 38 | |
| 39 | return _component_tests_config |
| 40 | |
| 41 | |
| 42 | # This fixture is automatically called before each tests to make sure the previous cloudflared has been shutdown |
| 43 | @pytest.fixture(autouse=True) |
| 44 | def wait_previous_cloudflared(): |
| 45 | sleep(BACKOFF_SECS) |