cloudflare/cloudflared

Public

mirrored fromhttps://github.com/cloudflare/cloudflaredAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
4d95ab73f584a5a6439803648f013031ca1dd4ac

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

component-tests/conftest.py

55lines · modecode

1import os
2from enum import Enum, auto
3from time import sleep
4
5import pytest
6import yaml
7
8from config import NamedTunnelConfig, QuickTunnelConfig
9from constants import BACKOFF_SECS
10from util import LOGGER
11
12
13class CfdModes(Enum):
14 NAMED = auto()
15 QUICK = auto()
16
17
18@pytest.fixture(scope="session")
19def component_tests_config():
20 config_file = os.getenv("COMPONENT_TESTS_CONFIG")
21 if config_file is None:
22 raise Exception(
23 "Need to provide path to config file in COMPONENT_TESTS_CONFIG")
24 with open(config_file, 'r') as stream:
25 config = yaml.safe_load(stream)
26 LOGGER.info(f"component tests base config {config}")
27
28 def _component_tests_config(additional_config={}, cfd_mode=CfdModes.NAMED, provide_ingress=True):
29 # Allows the ingress rules to be omitted from the provided config
30 ingress = []
31 if provide_ingress:
32 ingress = config['ingress']
33
34 # Provide the hostname to allow routing to the tunnel even if the ingress rule isn't defined in the config
35 hostname = config['ingress'][0]['hostname']
36
37 if cfd_mode is CfdModes.NAMED:
38 return NamedTunnelConfig(additional_config=additional_config,
39 cloudflared_binary=config['cloudflared_binary'],
40 tunnel=config['tunnel'],
41 credentials_file=config['credentials_file'],
42 ingress=ingress,
43 hostname=hostname)
44 elif cfd_mode is CfdModes.QUICK:
45 return QuickTunnelConfig(additional_config=additional_config, cloudflared_binary=config['cloudflared_binary'])
46 else:
47 raise Exception(f"Unknown cloudflared mode {cfd_mode}")
48
49 return _component_tests_config
50
51
52# This fixture is automatically called before each tests to make sure the previous cloudflared has been shutdown
53@pytest.fixture(autouse=True)
54def wait_previous_cloudflared():
55 sleep(BACKOFF_SECS)
56