diff --git a/CHANGELOG.md b/CHANGELOG.md index c76da83..951d980 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1 +1,7 @@ -No changes since release yet. +## HEAD + +* Add support for dashes in `Worker` names to match the Procfile process naming format. `Worker` is implicitly used when configuring HireFire using the `Configuration#dyno` method. + +## v1.0.0 + +* Initial release. diff --git a/hirefire_resource/worker.py b/hirefire_resource/worker.py index eddcaad..50f2ed0 100644 --- a/hirefire_resource/worker.py +++ b/hirefire_resource/worker.py @@ -10,7 +10,7 @@ class MissingDynoProcError(Exception): class Worker: - PROCESS_NAME_PATTERN = r"^[a-zA-Z][a-zA-Z0-9_]{0,29}$" + PROCESS_NAME_PATTERN = r"^[a-zA-Z][a-zA-Z0-9_-]{0,29}$" def __init__(self, name, proc=None): self._validate(name, proc) diff --git a/tests/hirefire_resource/test_worker.py b/tests/hirefire_resource/test_worker.py index 0ba284a..22a92ec 100644 --- a/tests/hirefire_resource/test_worker.py +++ b/tests/hirefire_resource/test_worker.py @@ -3,15 +3,39 @@ from hirefire_resource.worker import InvalidDynoNameError, MissingDynoProcError, Worker -def test_worker_initialization_and_methods(): - worker = Worker("worker", lambda: 1.23) - assert worker.name == "worker" - assert worker.value() == 1.23 +def test_worker_valid_initialization(): + valid_names = [ + "worker", + "worker1", + "my-worker", + "my_worker", + "Worker_123", + "worker-123", + "w", + "a" * 30, + ] + for name in valid_names: + worker = Worker(name, lambda: 1.23) + assert worker.name == name + assert worker.value() == 1.23 -def test_invalid_dyno_name_error(): - with pytest.raises(InvalidDynoNameError): - Worker("invalid name", lambda: 1.23) + +def test_worker_invalid_name_raises_error(): + invalid_names = [ + "", # Empty string + "1worker", # Starts with a digit + "-worker", # Starts with a dash + "_worker", # Starts with an underscore + "worker!", # Contains an invalid character + " worker", # Starts with a space + "worker ", # Ends with a space + "a" * 31, # Exceeds maximum length + ] + + for name in invalid_names: + with pytest.raises(InvalidDynoNameError): + Worker(name, lambda: 1.23) def test_missing_dyno_proc_error():