Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
30 changes: 30 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# documentation: https://help.github.com/en/articles/workflow-syntax-for-github-actions
name: Unit tests
on: [push, pull_request, workflow_dispatch]
permissions:
contents: read # to fetch code (actions/checkout)
jobs:
ubuntu-minimal:
runs-on: ubuntu-22.04
strategy:
matrix:
python: ['3.9', '3.10', '3.11', '3.12', '3.13', '3.14']
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
- name: set up Python
uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0
with:
python-version: ${{matrix.python}}

- name: Install eessi command line tool
id: install
run: |
pip install .

- name: Install pytest
run: |
pip install pytest

- name: Run tests
run: |
pytest
17 changes: 11 additions & 6 deletions src/eessi/cli/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,19 @@ def get_repo_attribute(repo: str, key: str):
Get repository attribute
"""
repo_path = os.path.join(CVMFS_ROOT, repo)

value = UNKNOWN

(stdout, stderr, exit_code) = run_cmd(f"attr -g {key} {repo_path}")
if exit_code == 0:
# expected output is something like:
# Attribute "revision" had a 5 byte value for /cvmfs/software.eessi.io:
# 13972
value = stdout.splitlines()[-1]
else:
value = UNKNOWN
# Expected output is something like:
# Attribute "revision" had a 5 byte value for /cvmfs/software.eessi.io:
# 13972
#
# If there's no value found ('0 byte value'), then last line is *empty*
regex = re.compile("had a [1-9][0-9]* byte value", re.M)
if regex.search(stdout):
value = stdout.splitlines()[-1].strip()

return value

Expand Down
25 changes: 25 additions & 0 deletions tests/test_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import eessi.cli.check
from eessi.cli.check import UNKNOWN, get_repo_attribute


def test_get_repo_attribute(monkeypatch):
"""
Tests for get_repo_attribute
"""

out = '\n'.join([
'Attribute "revision" had a 5 byte value for /cvmfs/software.eessi.io:',
'13972',
])
monkeypatch.setattr(eessi.cli.check, 'run_cmd', lambda x: (out, '', 0))
res = get_repo_attribute('software.eessi.io', 'revision')
assert res == '13972'

# check that UNKNOWN is returned when attr returns '0 byte value' with empty last line
out = '\n'.join([
'Attribute "ncleanup24" had a 0 byte value for /cvmfs/software.eessi.io:',
'',
])
monkeypatch.setattr(eessi.cli.check, 'run_cmd', lambda x: (out, '', 0))
res = get_repo_attribute('software.eessi.io', 'ncleanup24')
assert res == UNKNOWN