Test static deploy action without pip
All checks were successful
Test / test (push) Successful in 12s
All checks were successful
Test / test (push) Successful in 12s
This commit is contained in:
parent
e6362c4862
commit
d40d2837f5
3 changed files with 60 additions and 49 deletions
|
|
@ -10,5 +10,4 @@ jobs:
|
||||||
runs-on: docker
|
runs-on: docker
|
||||||
steps:
|
steps:
|
||||||
- uses: https://data.forgejo.org/actions/checkout@v6
|
- uses: https://data.forgejo.org/actions/checkout@v6
|
||||||
- run: python3 -m pip install pytest
|
- run: python3 -m unittest discover -s tests
|
||||||
- run: python3 -m pytest -q
|
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ Set `BUNNY_STORAGE_ENDPOINT` when the Storage Zone is outside Frankfurt.
|
||||||
## Development
|
## Development
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
python3 -m pytest tests
|
python3 -m unittest discover -s tests
|
||||||
```
|
```
|
||||||
|
|
||||||
The canonical source lives in the private Gandalf infrastructure repository
|
The canonical source lives in the private Gandalf infrastructure repository
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
import importlib.util
|
import importlib.util
|
||||||
|
import json
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import sys
|
import sys
|
||||||
|
import tempfile
|
||||||
import pytest
|
import unittest
|
||||||
|
|
||||||
MODULE_PATH = Path(__file__).resolve().parents[1] / "static_site.py"
|
MODULE_PATH = Path(__file__).resolve().parents[1] / "static_site.py"
|
||||||
SPEC = importlib.util.spec_from_file_location("static_site_deploy", MODULE_PATH)
|
SPEC = importlib.util.spec_from_file_location("static_site_deploy", MODULE_PATH)
|
||||||
|
|
@ -24,47 +25,58 @@ def write_site(root: Path) -> None:
|
||||||
(root / "assets" / "app.js").write_text("console.log('hello')")
|
(root / "assets" / "app.js").write_text("console.log('hello')")
|
||||||
|
|
||||||
|
|
||||||
def test_collect_files_requires_index(tmp_path):
|
class StaticSiteTests(unittest.TestCase):
|
||||||
with pytest.raises(DeployError, match="index.html"):
|
def test_collect_files_requires_index(self) -> None:
|
||||||
collect_files(tmp_path)
|
with tempfile.TemporaryDirectory() as directory:
|
||||||
|
with self.assertRaisesRegex(DeployError, "index.html"):
|
||||||
|
collect_files(Path(directory))
|
||||||
|
|
||||||
|
def test_collect_files_rejects_symlinks(self) -> None:
|
||||||
|
with tempfile.TemporaryDirectory() as directory:
|
||||||
|
root = Path(directory)
|
||||||
|
write_site(root)
|
||||||
|
(root / "linked").symlink_to(root / "index.html")
|
||||||
|
with self.assertRaisesRegex(DeployError, "symbolic links"):
|
||||||
|
collect_files(root)
|
||||||
|
|
||||||
def test_collect_files_rejects_symlinks(tmp_path):
|
def test_manifest_round_trip(self) -> None:
|
||||||
write_site(tmp_path)
|
with tempfile.TemporaryDirectory() as directory:
|
||||||
(tmp_path / "linked").symlink_to(tmp_path / "index.html")
|
root = Path(directory)
|
||||||
with pytest.raises(DeployError, match="symbolic links"):
|
write_site(root)
|
||||||
collect_files(tmp_path)
|
files = collect_files(root)
|
||||||
|
|
||||||
|
|
||||||
def test_manifest_round_trip(tmp_path):
|
|
||||||
write_site(tmp_path)
|
|
||||||
files = collect_files(tmp_path)
|
|
||||||
manifest = manifest_for(files)
|
manifest = manifest_for(files)
|
||||||
parsed = parse_manifest(__import__("json").dumps(manifest).encode())
|
parsed = parse_manifest(json.dumps(manifest).encode())
|
||||||
assert parsed["index.html"]["sha256"] == files["index.html"].sha256
|
self.assertEqual(
|
||||||
|
parsed["index.html"]["sha256"], files["index.html"].sha256
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_manifest_rejects_unsafe_remote_path(self) -> None:
|
||||||
def test_manifest_rejects_unsafe_remote_path():
|
|
||||||
raw = b'{"version": 1, "files": {"../other-site/index.html": {}}}'
|
raw = b'{"version": 1, "files": {"../other-site/index.html": {}}}'
|
||||||
with pytest.raises(DeployError, match="unsafe path"):
|
with self.assertRaisesRegex(DeployError, "unsafe path"):
|
||||||
parse_manifest(raw)
|
parse_manifest(raw)
|
||||||
|
|
||||||
|
def test_bunny_plan_uploads_assets_before_html_and_removes_stale(self) -> None:
|
||||||
def test_bunny_plan_uploads_assets_before_html_and_removes_stale(tmp_path):
|
with tempfile.TemporaryDirectory() as directory:
|
||||||
write_site(tmp_path)
|
root = Path(directory)
|
||||||
files = collect_files(tmp_path)
|
write_site(root)
|
||||||
|
files = collect_files(root)
|
||||||
remote = {
|
remote = {
|
||||||
"index.html": {"sha256": "old", "size": 1},
|
"index.html": {"sha256": "old", "size": 1},
|
||||||
"assets/app.js": {"sha256": "old", "size": 1},
|
"assets/app.js": {"sha256": "old", "size": 1},
|
||||||
"old.css": {"sha256": "old", "size": 1},
|
"old.css": {"sha256": "old", "size": 1},
|
||||||
}
|
}
|
||||||
upload, delete = bunny_plan(files, remote)
|
upload, delete = bunny_plan(files, remote)
|
||||||
assert upload == ["assets/app.js", "index.html"]
|
self.assertEqual(upload, ["assets/app.js", "index.html"])
|
||||||
assert delete == ["old.css"]
|
self.assertEqual(delete, ["old.css"])
|
||||||
|
|
||||||
|
def test_bunny_plan_skips_unchanged_files(self) -> None:
|
||||||
def test_bunny_plan_skips_unchanged_files(tmp_path):
|
with tempfile.TemporaryDirectory() as directory:
|
||||||
write_site(tmp_path)
|
root = Path(directory)
|
||||||
files = collect_files(tmp_path)
|
write_site(root)
|
||||||
|
files = collect_files(root)
|
||||||
remote = manifest_for(files)["files"]
|
remote = manifest_for(files)["files"]
|
||||||
assert bunny_plan(files, remote) == ([], [])
|
self.assertEqual(bunny_plan(files, remote), ([], []))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue