-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some basic tests with pytest. The functions that require Docker Hub access aren't currently tested. A GitHub workflow is included to run the tests on push.
- Loading branch information
Showing
6 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Validation | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
name: Python tests | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: ["3.6", "3.7", "3.8", "3.9", "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: pip install -r requirements-dev.txt -r requirements.txt | ||
|
||
- name: Run pytest | ||
run: pytest -v tests/test.py | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pytest>=7.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[ | ||
{ "tags": ["4", "4.*"], "date": "April 1, 2022" }, | ||
{ "tags": ["5", "5.*"], "date": "June 10, 2023" }, | ||
{ "tags": ["json-foobar"], "date": "October 31, 2023" } | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<!-- BEGIN deletion_table --> | ||
| Tag | Deletion Date | ||
| ---------- | ---------------------- | ||
| `1*` | October 5, 2022 | ||
| `2.*` | October 5, 2022 | ||
| `3.*` | October 5, 2040 | ||
| `foobar` | December 25, 2021 | ||
<!-- END deletion_table --> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
from datetime import datetime | ||
import os,sys,inspect | ||
|
||
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) | ||
parentdir = os.path.dirname(currentdir) | ||
sys.path.insert(0,parentdir) | ||
|
||
os.environ['MARKDOWN_FILE'] = "tests/test.md" | ||
os.environ['JSON_FILE'] = "tests/test.json" | ||
os.environ['DOCKERHUB_REPOSITORY'] = "foo/bar" | ||
|
||
target = __import__("hub-tag-delete") | ||
|
||
def test_line_is_ignored(): | ||
assert target.line_is_ignored('| Tag') is True | ||
assert target.line_is_ignored('| xTag') is False | ||
assert target.line_is_ignored('| 1.0') is False | ||
assert target.line_is_ignored('| `1.0`') is False | ||
|
||
def test_get_readme_table(): | ||
taglist = [ | ||
{'date': 'October 5, 2022', 'tags': ['1*']}, | ||
{'date': 'October 5, 2022', 'tags': ['2.*']}, | ||
{'date': 'October 5, 2040', 'tags': ['3.*']}, | ||
{'date': 'December 25, 2021', 'tags': ['foobar']} | ||
] | ||
assert target.get_readme_table() == taglist | ||
|
||
def test_parse_date(): | ||
date = "October 6, 2022" | ||
assert target.parse_date(date) == datetime(2022, 10, 6, 0, 0) | ||
|
||
def test_parse_md_line(): | ||
mdline = '| `1.*`, `2.0` | October 6, 2022' | ||
result = {'tags': ['1.*',' 2.0'], 'date': 'October 6, 2022'} | ||
assert target.parse_md_line(mdline) == result | ||
|
||
def test_json_tags(): | ||
result = [ | ||
{'date': 'April 1, 2022', 'tags': ['4', '4.*']}, | ||
{'date': 'June 10, 2023', 'tags': ['5', '5.*']}, | ||
{'date': 'October 31, 2023', 'tags': ['json-foobar']} | ||
] | ||
assert target.json_tags() == result | ||
|
||
def test_get_tag_list(): | ||
taglist = [ | ||
{'date': 'April 1, 2022', 'tags': ['4', '4.*']}, | ||
{'date': 'June 10, 2023', 'tags': ['5', '5.*']}, | ||
{'date': 'October 31, 2023', 'tags': ['json-foobar']}, | ||
{'date': 'October 5, 2022', 'tags': ['1*']}, | ||
{'date': 'October 5, 2022', 'tags': ['2.*']}, | ||
{'date': 'October 5, 2040', 'tags': ['3.*']}, | ||
{'date': 'December 25, 2021', 'tags': ['foobar']} | ||
] | ||
assert target.get_tag_list() == taglist | ||
|
||
# TODO: The tests that require Docker Hub connectivity are pending | ||
def test_tags_to_delete(): | ||
"""Docker Hub required""" | ||
pass | ||
|
||
def test_delete_expired_tags(): | ||
"""Docker Hub required""" | ||
pass | ||
|
||
def test_docker_hub_token(): | ||
"""Docker Hub required""" | ||
pass | ||
|
||
def test_tags_matching_pattern(): | ||
"""Docker Hub required""" | ||
pass | ||
|