1#*************************************************************************** 2# _ _ ____ _ 3# Project ___| | | | _ \| | 4# / __| | | | |_) | | 5# | (__| |_| | _ <| |___ 6# \___|\___/|_| \_\_____| 7# 8# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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# 25import logging 26import os 27import sys 28from typing import Optional 29 30import pytest 31 32sys.path.append(os.path.join(os.path.dirname(__file__), '.')) 33 34from testenv import Env, Nghttpx, Httpd, NghttpxQuic, NghttpxFwd 35 36@pytest.fixture(scope="package") 37def env(pytestconfig) -> Env: 38 env = Env(pytestconfig=pytestconfig) 39 level = logging.DEBUG if env.verbose > 0 else logging.INFO 40 logging.getLogger('').setLevel(level=level) 41 if not env.curl_has_protocol('http'): 42 pytest.skip("curl built without HTTP support") 43 if not env.curl_has_protocol('https'): 44 pytest.skip("curl built without HTTPS support") 45 if env.setup_incomplete(): 46 pytest.skip(env.incomplete_reason()) 47 48 env.setup() 49 if not env.make_clients(): 50 pytest.exit(1) 51 return env 52 53@pytest.fixture(scope="package", autouse=True) 54def log_global_env_facts(record_testsuite_property, env): 55 record_testsuite_property("http-port", env.http_port) 56 57 58@pytest.fixture(scope='package') 59def httpd(env) -> Httpd: 60 httpd = Httpd(env=env) 61 if not httpd.exists(): 62 pytest.skip(f'httpd not found: {env.httpd}') 63 httpd.clear_logs() 64 if not httpd.start(): 65 pytest.fail(f'failed to start httpd: {env.httpd}') 66 yield httpd 67 httpd.stop() 68 69 70@pytest.fixture(scope='package') 71def nghttpx(env, httpd) -> Optional[Nghttpx]: 72 nghttpx = NghttpxQuic(env=env) 73 if env.have_h3(): 74 nghttpx.clear_logs() 75 assert nghttpx.start() 76 yield nghttpx 77 nghttpx.stop() 78 79@pytest.fixture(scope='package') 80def nghttpx_fwd(env, httpd) -> Optional[Nghttpx]: 81 nghttpx = NghttpxFwd(env=env) 82 if env.have_h3(): 83 nghttpx.clear_logs() 84 assert nghttpx.start() 85 yield nghttpx 86 nghttpx.stop() 87