From 0889dbc2687fc01a87254676055cd1a2aa83b8ec Mon Sep 17 00:00:00 2001 From: egvimo Date: Tue, 24 Oct 2023 19:44:13 +0200 Subject: [PATCH] test: add test for app --- .github/workflows/build.yml | 25 +++++++++++++++++++++++++ test_app.py | 12 ++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 test_app.py diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f29fd5a..1ef5701 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -33,6 +33,31 @@ jobs: - name: Lint run: pylint app.py apt_info.py + test: + name: Test + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Python 3 + id: setup-python + uses: actions/setup-python@v4 + with: + python-version: "3.x" + + - name: Prepare + run: | + sudo apt install libapt-pkg-dev + pip install httpx + + - name: Install dependencies + run: pip install -r requirements.txt + + - name: Test + run: pytest test_app.py + build: name: Build runs-on: ubuntu-latest diff --git a/test_app.py b/test_app.py new file mode 100644 index 0000000..70bae96 --- /dev/null +++ b/test_app.py @@ -0,0 +1,12 @@ +from fastapi.testclient import TestClient +from app import app + +client = TestClient(app) + + +def test_read_main(): + response = client.get("/metrics") + assert response.status_code == 200 + assert "# HELP" in response.text + assert "# TYPE" in response.text + assert "apt_" in response.text