cloudflare/cloudflared

Public

mirrored from https://github.com/cloudflare/cloudflaredAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
2026.3.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

component-tests/conftest.py

55lines · modeblame

a7344435cthuang5 years ago1import os
1e8dea91Nuno Diegues4 years ago2from enum import Enum, auto
3from time import sleep
4
a7344435cthuang5 years ago5import pytest
6import yaml
7
9388e7f4João "Pisco" Fernandes5 months ago8from config import NamedTunnelConfig, QuickTunnelConfig
9from constants import BACKOFF_SECS
a7344435cthuang5 years ago10from util import LOGGER
11
f23e33c0cthuang5 years ago12
1e8dea91Nuno Diegues4 years ago13class CfdModes(Enum):
14NAMED = auto()
93f8f6b5Devin Carr3 years ago15QUICK = auto()
1e8dea91Nuno Diegues4 years ago16
17
a7344435cthuang5 years ago18@pytest.fixture(scope="session")
19def component_tests_config():
20config_file = os.getenv("COMPONENT_TESTS_CONFIG")
21if config_file is None:
f23e33c0cthuang5 years ago22raise Exception(
23"Need to provide path to config file in COMPONENT_TESTS_CONFIG")
a7344435cthuang5 years ago24with open(config_file, 'r') as stream:
25config = yaml.safe_load(stream)
26LOGGER.info(f"component tests base config {config}")
27
9388e7f4João "Pisco" Fernandes5 months ago28def _component_tests_config(additional_config={}, cfd_mode=CfdModes.NAMED, provide_ingress=True):
7b8b3f73Devin Carr3 years ago29# Allows the ingress rules to be omitted from the provided config
30ingress = []
31if provide_ingress:
32ingress = config['ingress']
33
34# Provide the hostname to allow routing to the tunnel even if the ingress rule isn't defined in the config
35hostname = config['ingress'][0]['hostname']
36
1e8dea91Nuno Diegues4 years ago37if cfd_mode is CfdModes.NAMED:
25cfbec0cthuang5 years ago38return NamedTunnelConfig(additional_config=additional_config,
b25d38ddNuno Diegues5 years ago39cloudflared_binary=config['cloudflared_binary'],
40tunnel=config['tunnel'],
41credentials_file=config['credentials_file'],
7b8b3f73Devin Carr3 years ago42ingress=ingress,
43hostname=hostname)
93f8f6b5Devin Carr3 years ago44elif cfd_mode is CfdModes.QUICK:
45return QuickTunnelConfig(additional_config=additional_config, cloudflared_binary=config['cloudflared_binary'])
1e8dea91Nuno Diegues4 years ago46else:
47raise Exception(f"Unknown cloudflared mode {cfd_mode}")
a7344435cthuang5 years ago48
f23e33c0cthuang5 years ago49return _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():
55sleep(BACKOFF_SECS)