From: Stefan Eissing Date: Mon, 8 Nov 2021 12:33:46 +0000 (+0000) Subject: * test: just general cleanup and separation X-Git-Tag: 2.5.0-alpha2-ci-test-only~704 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0ecb9153ce1bb0159642efa70c9c3f80b5cd7d24;p=thirdparty%2Fapache%2Fhttpd.git * test: just general cleanup and separation - base modules loaded minimized - h2's htdocs/cgi setup now in test/modules/http2 - less args to constructors, more methods git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1894832 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/test/modules/core/conftest.py b/test/modules/core/conftest.py index bc2540f7173..439cd22e171 100644 --- a/test/modules/core/conftest.py +++ b/test/modules/core/conftest.py @@ -4,25 +4,26 @@ import os import pytest import sys -sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) +from pyhttpd.env import HttpdTestEnv -from .env import CoreTestEnv +sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) def pytest_report_header(config, startdir): - env = CoreTestEnv(setup_dirs=False) + env = HttpdTestEnv() return f"core [apache: {env.get_httpd_version()}, mpm: {env.mpm_module}, {env.prefix}]" @pytest.fixture(scope="package") -def env(pytestconfig) -> CoreTestEnv: +def env(pytestconfig) -> HttpdTestEnv: level = logging.INFO console = logging.StreamHandler() console.setLevel(level) console.setFormatter(logging.Formatter('%(levelname)s: %(message)s')) logging.getLogger('').addHandler(console) logging.getLogger('').setLevel(level=level) - env = CoreTestEnv(pytestconfig=pytestconfig) + env = HttpdTestEnv(pytestconfig=pytestconfig) + env.setup_httpd() env.apache_access_log_clear() env.httpd_error_log.clear_log() return env diff --git a/test/modules/core/env.py b/test/modules/core/env.py deleted file mode 100644 index 9b09e90c617..00000000000 --- a/test/modules/core/env.py +++ /dev/null @@ -1,18 +0,0 @@ -import inspect -import logging -import os - -from pyhttpd.env import HttpdTestEnv, HttpdTestSetup - -log = logging.getLogger(__name__) - - -class CoreTestEnv(HttpdTestEnv): - - def __init__(self, pytestconfig=None, setup_dirs=True): - super().__init__(pytestconfig=pytestconfig, - local_dir=os.path.dirname(inspect.getfile(CoreTestEnv))) - if setup_dirs: - self._setup = HttpdTestSetup(env=self) - self._setup.make() - self.issue_certs() diff --git a/test/modules/core/test_001_encoding.py b/test/modules/core/test_001_encoding.py index 5eac78e4b85..b7ffbaa8429 100644 --- a/test/modules/core/test_001_encoding.py +++ b/test/modules/core/test_001_encoding.py @@ -18,7 +18,7 @@ class TestEncoding: """, f"test2.{env.http_tld}": "AllowEncodedSlashes on", - f"cgi.{env.http_tld}": f"ScriptAlias /cgi-bin/ {env.gen_dir}", + f"test1.{env.http_tld}": f"ScriptAlias /cgi-bin/ {env.gen_dir}", }) conf.add_vhost_test1() conf.add_vhost_test2() @@ -73,7 +73,7 @@ class TestEncoding: ["/cgi-bin/%25%32%65%25%32%65/%25%32%65%25%32%65/h2_env.py", 404], ]) def test_core_001_04(self, env, path, status): - url = env.mkurl("https", "cgi", path) + url = env.mkurl("https", "test1", path) r = env.curl_get(url) assert r.response["status"] == status if status == 400: diff --git a/test/modules/http2/conftest.py b/test/modules/http2/conftest.py index 0cfa7cb4dc4..806777439ea 100644 --- a/test/modules/http2/conftest.py +++ b/test/modules/http2/conftest.py @@ -10,7 +10,7 @@ from .env import H2TestEnv def pytest_report_header(config, startdir): - env = H2TestEnv(setup_dirs=False) + env = H2TestEnv() return f"mod_h2 [apache: {env.get_httpd_version()}, mpm: {env.mpm_module}, {env.prefix}]" @@ -36,6 +36,7 @@ def env(pytestconfig) -> H2TestEnv: logging.getLogger('').addHandler(console) logging.getLogger('').setLevel(level=level) env = H2TestEnv(pytestconfig=pytestconfig) + env.setup_httpd() env.apache_access_log_clear() env.httpd_error_log.clear_log() return env diff --git a/test/modules/http2/env.py b/test/modules/http2/env.py index 7923d90f257..d6d96d50a3f 100644 --- a/test/modules/http2/env.py +++ b/test/modules/http2/env.py @@ -16,15 +16,19 @@ class H2TestSetup(HttpdTestSetup): def __init__(self, env: 'HttpdTestEnv'): super().__init__(env=env) + self.add_source_dir(os.path.dirname(inspect.getfile(H2TestSetup))) + self.add_modules(["http2", "proxy_http2", "cgid", "autoindex"]) def make(self): - super().make(add_modules=["http2", "proxy_http2"]) + super().make() self._add_h2test() + self._setup_data_1k_1m() def _add_h2test(self): + local_dir = os.path.dirname(inspect.getfile(H2TestSetup)) p = subprocess.run([self.env.apxs, '-c', 'mod_h2test.c'], capture_output=True, - cwd=os.path.join(self.env.local_dir, 'mod_h2test')) + cwd=os.path.join(local_dir, 'mod_h2test')) rv = p.returncode if rv != 0: log.error(f"compiling md_h2test failed: {p.stderr}") @@ -33,20 +37,34 @@ class H2TestSetup(HttpdTestSetup): modules_conf = os.path.join(self.env.server_dir, 'conf/modules.conf') with open(modules_conf, 'a') as fd: # load our test module which is not installed - fd.write(f"LoadModule h2test_module \"{self.env.local_dir}/mod_h2test/.libs/mod_h2test.so\"\n") + fd.write(f"LoadModule h2test_module \"{local_dir}/mod_h2test/.libs/mod_h2test.so\"\n") + + def _setup_data_1k_1m(self): + s90 = "01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678\n" + with open(os.path.join(self.env.gen_dir, "data-1k"), 'w') as f: + for i in range(10): + f.write(f"{i:09d}-{s90}") + with open(os.path.join(self.env.gen_dir, "data-10k"), 'w') as f: + for i in range(100): + f.write(f"{i:09d}-{s90}") + with open(os.path.join(self.env.gen_dir, "data-100k"), 'w') as f: + for i in range(1000): + f.write(f"{i:09d}-{s90}") + with open(os.path.join(self.env.gen_dir, "data-1m"), 'w') as f: + for i in range(10000): + f.write(f"{i:09d}-{s90}") class H2TestEnv(HttpdTestEnv): - def __init__(self, pytestconfig=None, setup_dirs=True): - super().__init__(pytestconfig=pytestconfig, - local_dir=os.path.dirname(inspect.getfile(H2TestEnv)), - add_base_conf=[ + def __init__(self, pytestconfig=None): + super().__init__(pytestconfig=pytestconfig) + self.add_httpd_conf([ "H2MinWorkers 1", "H2MaxWorkers 64", "Protocols h2 http/1.1 h2c", - ], - interesting_modules=["http2", "proxy_http2", "h2test"]) + ]) + self.add_httpd_log_modules(["http2", "proxy_http2", "h2test"]) self.add_cert_specs([ CertificateSpec(domains=[ f"push.{self._http_tld}", @@ -74,27 +92,8 @@ class H2TestEnv(HttpdTestEnv): re.compile(r'.*:tls_process_client_certificate:.*'), ]) - if setup_dirs: - self._setup = H2TestSetup(env=self) - self._setup.make() - self.issue_certs() - self.setup_data_1k_1m() - - - def setup_data_1k_1m(self): - s90 = "01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678\n" - with open(os.path.join(self.gen_dir, "data-1k"), 'w') as f: - for i in range(10): - f.write(f"{i:09d}-{s90}") - with open(os.path.join(self.gen_dir, "data-10k"), 'w') as f: - for i in range(100): - f.write(f"{i:09d}-{s90}") - with open(os.path.join(self.gen_dir, "data-100k"), 'w') as f: - for i in range(1000): - f.write(f"{i:09d}-{s90}") - with open(os.path.join(self.gen_dir, "data-1m"), 'w') as f: - for i in range(10000): - f.write(f"{i:09d}-{s90}") + def setup_httpd(self, setup: HttpdTestSetup = None): + super().setup_httpd(setup=H2TestSetup(env=self)) class H2Conf(HttpdConf): @@ -135,4 +134,3 @@ class H2Conf(HttpdConf): def add_vhost_test2(self): return super().add_vhost_test2() - diff --git a/test/pyhttpd/htdocs/cgi/echo.py b/test/modules/http2/htdocs/cgi/echo.py similarity index 100% rename from test/pyhttpd/htdocs/cgi/echo.py rename to test/modules/http2/htdocs/cgi/echo.py diff --git a/test/pyhttpd/htdocs/cgi/echohd.py b/test/modules/http2/htdocs/cgi/echohd.py similarity index 100% rename from test/pyhttpd/htdocs/cgi/echohd.py rename to test/modules/http2/htdocs/cgi/echohd.py diff --git a/test/pyhttpd/htdocs/cgi/env.py b/test/modules/http2/htdocs/cgi/env.py similarity index 100% rename from test/pyhttpd/htdocs/cgi/env.py rename to test/modules/http2/htdocs/cgi/env.py diff --git a/test/pyhttpd/htdocs/cgi/files/empty.txt b/test/modules/http2/htdocs/cgi/files/empty.txt similarity index 100% rename from test/pyhttpd/htdocs/cgi/files/empty.txt rename to test/modules/http2/htdocs/cgi/files/empty.txt diff --git a/test/pyhttpd/htdocs/cgi/hecho.py b/test/modules/http2/htdocs/cgi/hecho.py similarity index 100% rename from test/pyhttpd/htdocs/cgi/hecho.py rename to test/modules/http2/htdocs/cgi/hecho.py diff --git a/test/pyhttpd/htdocs/cgi/hello.py b/test/modules/http2/htdocs/cgi/hello.py similarity index 100% rename from test/pyhttpd/htdocs/cgi/hello.py rename to test/modules/http2/htdocs/cgi/hello.py diff --git a/test/pyhttpd/htdocs/cgi/mnot164.py b/test/modules/http2/htdocs/cgi/mnot164.py similarity index 100% rename from test/pyhttpd/htdocs/cgi/mnot164.py rename to test/modules/http2/htdocs/cgi/mnot164.py diff --git a/test/pyhttpd/htdocs/cgi/necho.py b/test/modules/http2/htdocs/cgi/necho.py similarity index 100% rename from test/pyhttpd/htdocs/cgi/necho.py rename to test/modules/http2/htdocs/cgi/necho.py diff --git a/test/pyhttpd/htdocs/cgi/upload.py b/test/modules/http2/htdocs/cgi/upload.py similarity index 100% rename from test/pyhttpd/htdocs/cgi/upload.py rename to test/modules/http2/htdocs/cgi/upload.py diff --git a/test/pyhttpd/htdocs/noh2/alive.json b/test/modules/http2/htdocs/noh2/alive.json similarity index 100% rename from test/pyhttpd/htdocs/noh2/alive.json rename to test/modules/http2/htdocs/noh2/alive.json diff --git a/test/pyhttpd/htdocs/noh2/index.html b/test/modules/http2/htdocs/noh2/index.html similarity index 100% rename from test/pyhttpd/htdocs/noh2/index.html rename to test/modules/http2/htdocs/noh2/index.html diff --git a/test/modules/http2/test_001_httpd_alive.py b/test/modules/http2/test_001_httpd_alive.py index d922b44001e..557d17a453f 100644 --- a/test/modules/http2/test_001_httpd_alive.py +++ b/test/modules/http2/test_001_httpd_alive.py @@ -3,7 +3,7 @@ import pytest from .env import H2Conf -class TestStore: +class TestBasicAlive: @pytest.fixture(autouse=True, scope='class') def _class_scope(self, env): diff --git a/test/modules/http2/test_002_curl_basics.py b/test/modules/http2/test_002_curl_basics.py index dfe39c53db4..bb03bd84f3d 100644 --- a/test/modules/http2/test_002_curl_basics.py +++ b/test/modules/http2/test_002_curl_basics.py @@ -3,7 +3,7 @@ import pytest from .env import H2Conf -class TestStore: +class TestCurlBasics: @pytest.fixture(autouse=True, scope='class') def _class_scope(self, env): diff --git a/test/modules/http2/test_003_get.py b/test/modules/http2/test_003_get.py index a62da2acb25..3fbaa081afd 100644 --- a/test/modules/http2/test_003_get.py +++ b/test/modules/http2/test_003_get.py @@ -4,7 +4,7 @@ import pytest from .env import H2Conf -class TestStore: +class TestGet: @pytest.fixture(autouse=True, scope='class') def _class_scope(self, env): @@ -92,7 +92,7 @@ class TestStore: Index of /006 -My Header Title +

Index of /006