Skip to content

Commit

Permalink
Add some basic unittests (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
cooperlees authored May 23, 2024
1 parent 6257a82 commit 14aee38
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ jobs:
- name: Check files are formatted with black
run: |
black --check --diff .
- name: Run unittests
run: |
python godaddyip/tests.py -v
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# From https://raw.githubusercontent.com/github/gitignore/master/Python.gitignore

.coverage

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# Distribution / packaging
*.egg-info/
dist/
dist/
build/
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,10 @@ WantedBy=default.target
I advice running the daemon with a non-root user. A system user can be
created with `useradd --system godaddyip`.
# Unit tests
To run unit tests locally do the following:
- `python3 -m venv --upgrade-deps /tmp/tg`
- `/tmp/tg/bin/python godaddyip/tests.py -v`
28 changes: 28 additions & 0 deletions godaddyip/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env python3

from pathlib import Path
from tempfile import TemporaryDirectory
import unittest

from godaddyip.__main__ import Config, previous_value, store_value


class TestGodaddyIp(unittest.TestCase):
def test_config_load(self) -> None:
tests_src_path = Path(__file__).parent
unittest_config_path = tests_src_path / "unittest.yml"
config = Config(unittest_config_path)
self.assertEqual("unittest", config["arecord"])

def test_store_previous_value(self) -> None:
with TemporaryDirectory() as td:
td_path = Path(td)
store_value(td_path, "unittest", "unittest")
self.assertEqual(
"unittest",
previous_value(td_path, "unittest"),
)


if __name__ == "__main__": # pragma: no cover
unittest.main()
7 changes: 7 additions & 0 deletions godaddyip/unittest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
arecord: unittest
aaaarecord: unittest
key: ABC6969
secret: zYU0069
domain: unittest.com
cnames:
- testing

0 comments on commit 14aee38

Please sign in to comment.