Add initial tests

This commit is contained in:
Orsiris de Jong 2024-01-01 22:10:38 +01:00
parent 29581e6944
commit 6a8076fe6c
3 changed files with 88 additions and 0 deletions

35
.github/workflows/linux.yaml vendored Normal file
View file

@ -0,0 +1,35 @@
name: linux-tests
on: [push, pull_request]
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
# Python 3.3 and 3.4 have been removed since github won't provide these anymore
# As of 2023/01/09, we have removed python 3.5 and 3.6 as they don't work anymore with linux on github
# As of 2023/08/30, we have removed python 2.7 since github actions won't provide it anymore
python-version: [3.7, 3.8, 3.9, "3.10", "3.11", "3.12", 'pypy-3.6', 'pypy-3.7', 'pypy-3.8', 'pypy-3.10']
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade setuptools
if [ -f npbackup/requirements.txt ]; then pip install -r npbackup/requirements.txt; fi
- name: Generate Report
env:
RUNNING_ON_GITHUB_ACTIONS: true
run: |
pip install pytest coverage
python -m coverage run -m pytest -vvs tests
- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v3

38
.github/workflows/windows.yaml vendored Normal file
View file

@ -0,0 +1,38 @@
name: windows-tests
# The default shell here is Powershell
# Don't run with python 3.3 as using python -m to run flake8 or pytest will fail.
# Hence, without python -m, pytest will not have it's PYTHONPATH set to current dir and imports will fail
# Don't run with python 3.4 as github cannot install it (pip install --upgrade pip fails)
on: [push, pull_request]
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest]
# As of 2023/08/30, we have removed python 2.7 since github actions won't provide it anymore
python-version: [3.5, 3.6, 3.7, 3.8, 3.9, "3.10", "3.11", "3.12", 'pypy-3.6', 'pypy-3.7', 'pypy-3.8', 'pypy-3.10']
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade setuptools
if (Test-Path "npbackup/requirements.txt") { pip install -r npbackup/requirements.txt }
- name: Generate Report
env:
RUNNING_ON_GITHUB_ACTIONS: true
run: |
pip install pytest coverage
python -m coverage run -m pytest -vvs tests
- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v3

View file

@ -93,6 +93,16 @@ expected_results_V2 = [
r'restic_total_duration_seconds{instance="test",backup_job="some_nas",action="backup"} (\d+)',
]
def running_on_github_actions():
"""
This is set in github actions workflow with
env:
RUNNING_ON_GITHUB_ACTIONS: true
"""
return os.environ.get("RUNNING_ON_GITHUB_ACTIONS").lower() == "true"
def test_restic_str_output_2_metrics():
instance = "test"
backup_job = "some_nas"
@ -159,6 +169,11 @@ def test_restic_json_output():
def test_real_restic_output():
# Don't do the real tests on github actions, since we don't have
# the binaries there.
# TODO: Add download/unzip restic binaries so we can run these tests
if running_on_github_actions():
return
labels = {
"instance": "test",
"backup_job": "some_nas"