Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/pkg
Path: blob/main/external/curl/tests/http/conftest.py
2066 views
1
#***************************************************************************
2
# _ _ ____ _
3
# Project ___| | | | _ \| |
4
# / __| | | | |_) | |
5
# | (__| |_| | _ <| |___
6
# \___|\___/|_| \_\_____|
7
#
8
# Copyright (C) Daniel Stenberg, <[email protected]>, et al.
9
#
10
# This software is licensed as described in the file COPYING, which
11
# you should have received as part of this distribution. The terms
12
# are also available at https://curl.se/docs/copyright.html.
13
#
14
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
15
# copies of the Software, and permit persons to whom the Software is
16
# furnished to do so, under the terms of the COPYING file.
17
#
18
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
# KIND, either express or implied.
20
#
21
# SPDX-License-Identifier: curl
22
#
23
###########################################################################
24
#
25
import logging
26
import os
27
import sys
28
import platform
29
from typing import Generator, Union
30
31
import pytest
32
33
from testenv.env import EnvConfig
34
35
sys.path.append(os.path.join(os.path.dirname(__file__), '.'))
36
37
from testenv import Env, Nghttpx, Httpd, NghttpxQuic, NghttpxFwd
38
39
40
def pytest_report_header(config):
41
# Env inits its base properties only once, we can report them here
42
env = Env()
43
report = [
44
f'Testing curl {env.curl_version()}',
45
f' platform: {platform.platform()}',
46
f' curl: Version: {env.curl_version_string()}',
47
f' curl: Features: {env.curl_features_string()}',
48
f' curl: Protocols: {env.curl_protocols_string()}',
49
f' httpd: {env.httpd_version()}',
50
f' httpd-proxy: {env.httpd_version()}'
51
]
52
if env.have_h3():
53
report.extend([
54
f' nghttpx: {env.nghttpx_version()}'
55
])
56
if env.has_caddy():
57
report.extend([
58
f' Caddy: {env.caddy_version()}'
59
])
60
if env.has_vsftpd():
61
report.extend([
62
f' VsFTPD: {env.vsftpd_version()}'
63
])
64
buildinfo_fn = os.path.join(env.build_dir, 'buildinfo.txt')
65
if os.path.exists(buildinfo_fn):
66
with open(buildinfo_fn, 'r') as file_in:
67
for line in file_in:
68
line = line.strip()
69
if line and not line.startswith('#'):
70
report.extend([line])
71
return '\n'.join(report)
72
73
74
@pytest.fixture(scope='session')
75
def env_config(pytestconfig, testrun_uid, worker_id) -> EnvConfig:
76
env_config = EnvConfig(pytestconfig=pytestconfig,
77
testrun_uid=testrun_uid,
78
worker_id=worker_id)
79
return env_config
80
81
82
@pytest.fixture(scope='session', autouse=True)
83
def env(pytestconfig, env_config) -> Env:
84
env = Env(pytestconfig=pytestconfig, env_config=env_config)
85
level = logging.DEBUG if env.verbose > 0 else logging.INFO
86
logging.getLogger('').setLevel(level=level)
87
if not env.curl_has_protocol('http'):
88
pytest.skip("curl built without HTTP support")
89
if not env.curl_has_protocol('https'):
90
pytest.skip("curl built without HTTPS support")
91
if env.setup_incomplete():
92
pytest.skip(env.incomplete_reason())
93
94
env.setup()
95
return env
96
97
98
@pytest.fixture(scope='session')
99
def httpd(env) -> Generator[Httpd, None, None]:
100
httpd = Httpd(env=env)
101
if not httpd.exists():
102
pytest.skip(f'httpd not found: {env.httpd}')
103
httpd.clear_logs()
104
assert httpd.initial_start()
105
yield httpd
106
httpd.stop()
107
108
109
@pytest.fixture(scope='session')
110
def nghttpx(env, httpd) -> Generator[Union[Nghttpx,bool], None, None]:
111
nghttpx = NghttpxQuic(env=env)
112
if nghttpx.exists() and env.have_h3():
113
nghttpx.clear_logs()
114
assert nghttpx.initial_start()
115
yield nghttpx
116
nghttpx.stop()
117
else:
118
yield False
119
120
121
@pytest.fixture(scope='session')
122
def nghttpx_fwd(env, httpd) -> Generator[Union[Nghttpx,bool], None, None]:
123
nghttpx = NghttpxFwd(env=env)
124
if nghttpx.exists():
125
nghttpx.clear_logs()
126
assert nghttpx.initial_start()
127
yield nghttpx
128
nghttpx.stop()
129
else:
130
yield False
131
132
133
@pytest.fixture(scope='session')
134
def configures_httpd(env, httpd) -> Generator[bool, None, None]:
135
# include this fixture as test parameter if the test configures httpd itself
136
yield True
137
138
@pytest.fixture(scope='session')
139
def configures_nghttpx(env, httpd) -> Generator[bool, None, None]:
140
# include this fixture as test parameter if the test configures nghttpx itself
141
yield True
142
143
@pytest.fixture(autouse=True, scope='function')
144
def server_reset(request, env, httpd, nghttpx):
145
# make sure httpd is in default configuration when a test starts
146
if 'configures_httpd' not in request.node._fixtureinfo.argnames:
147
httpd.reset_config()
148
httpd.reload_if_config_changed()
149
if env.have_h3() and \
150
'nghttpx' in request.node._fixtureinfo.argnames and \
151
'configures_nghttpx' not in request.node._fixtureinfo.argnames:
152
nghttpx.reset_config()
153
nghttpx.reload_if_config_changed()
154
155