From 1a71973117bd6490d2d48e7c2fcd34cf9aa3f7fb Mon Sep 17 00:00:00 2001 From: Alexandre Rossi Date: Tue, 30 Apr 2024 11:23:42 +0200 Subject: [PATCH] add integration test for static-expires-uri --- .github/workflows/test.yml | 12 ++++++ Makefile | 3 ++ t/runner | 82 ++++++++++++++++++++++++++++++++++++++ t/static/config.ini | 4 ++ 4 files changed, 101 insertions(+) create mode 100755 t/runner create mode 100644 t/static/config.ini diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 19f06baa0a..88df146b6c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,6 +21,18 @@ jobs: - name: Run unit tests run: make unittests + test: + runs-on: ubuntu-20.04 + steps: + - name: Install dependencies + run: | + sudo apt update -qq + sudo apt install --no-install-recommends -qqyf \ + libpcre2-dev libjansson-dev libcap2-dev + - uses: actions/checkout@v4 + - name: Run integration tests + run: make all tests + python: runs-on: ubuntu-20.04 strategy: diff --git a/Makefile b/Makefile index 2a4f0d6782..fd2e3301c6 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,9 @@ unittests: $(PYTHON) uwsgiconfig.py --build unittest cd unittest && make test +tests: + $(PYTHON) t/runner + %: $(PYTHON) uwsgiconfig.py --build $@ diff --git a/t/runner b/t/runner new file mode 100755 index 0000000000..b9d9ce5294 --- /dev/null +++ b/t/runner @@ -0,0 +1,82 @@ +#!/usr/bin/python3 + + +import os +import requests +import signal +import socket +import subprocess +import time +import unittest + + +TESTS_DIR = os.path.dirname(__file__) +UWSGI_BINARY = os.getenv("UWSGI_BINARY", os.path.join(TESTS_DIR, "..", "uwsgi")) +UWSGI_ADDR = "127.0.0.1" +UWSGI_PORT = 8000 +UWSGI_HTTP = f"{UWSGI_ADDR}:{UWSGI_PORT}" + + +class BaseTest: + """ + Container class to avoid base test being run + """ + + class UwsgiServerTest(unittest.TestCase): + """ + Test case with a server instance available on a socket for requests + """ + + @classmethod + def uwsgi_ready(cls): + try: + s = socket.socket() + s.connect( + ( + UWSGI_ADDR, + UWSGI_PORT, + ) + ) + except socket.error: + return False + else: + return True + finally: + s.close() + + @classmethod + def setUpClass(cls): + # launch server + cls.testserver = subprocess.Popen( + [UWSGI_BINARY, "--http-socket", UWSGI_HTTP] + cls.ARGS + ) + + # ensure server is ready + retries = 10 + while not cls.uwsgi_ready() and retries > 0: + time.sleep(0.1) + retries = retries - 1 + if retries == 0: + raise RuntimeError("uwsgi test server is not available") + + @classmethod + def tearDownClass(cls): + cls.testserver.send_signal(signal.SIGTERM) + cls.testserver.wait() + + +class StaticTest(BaseTest.UwsgiServerTest): + + ARGS = [ + "--plugin", + "python3", # provide a request plugin if no embedded request plugin + os.path.join(TESTS_DIR, "static", "config.ini"), + ] + + def test_static_expires(self): + with requests.get(f"http://{UWSGI_HTTP}/foobar/config.ini") as r: + self.assertTrue("Expires" in r.headers) + + +if __name__ == "__main__": + unittest.main() diff --git a/t/static/config.ini b/t/static/config.ini new file mode 100644 index 0000000000..e0e23c55ed --- /dev/null +++ b/t/static/config.ini @@ -0,0 +1,4 @@ +[uwsgi] +need-app = False +static-map = /foobar=t/static +static-expires-uri = ^/foobar/ 315360000