-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
107 additions
and
18 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
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 @@ | ||
try: | ||
from .error import RenderError | ||
from .validations import must_be_valid_depend_condition | ||
except ImportError: | ||
from error import RenderError | ||
from validations import must_be_valid_depend_condition | ||
|
||
|
||
class Depends: | ||
def __init__(self, render_instance): | ||
self.render_instance = render_instance | ||
self.dependencies: dict[str, str] = {} | ||
|
||
def add_dependency(self, name: str, condition: str): | ||
if name in self.dependencies.keys(): | ||
raise RenderError(f"Dependency [{name}] already added") | ||
if name not in self.render_instance.containers.keys(): | ||
raise RenderError(f"Dependency [{name}] not found in defined containers") | ||
must_be_valid_depend_condition(condition) | ||
self.dependencies[name] = condition | ||
|
||
def has_dependencies(self): | ||
return len(self.dependencies) > 0 | ||
|
||
def render(self): | ||
return self.dependencies |
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
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,48 @@ | ||
import pytest | ||
|
||
|
||
from render import Render | ||
|
||
|
||
@pytest.fixture | ||
def mock_values(): | ||
return { | ||
"images": { | ||
"test_image": { | ||
"repository": "nginx", | ||
"tag": "latest", | ||
} | ||
}, | ||
} | ||
|
||
|
||
def test_add_dependency(mock_values): | ||
render = Render(mock_values) | ||
c1 = render.add_container("test_container", "test_image") | ||
render.add_container("test_container2", "test_image") | ||
c1.depends.add_dependency("test_container2", "service_started") | ||
output = render.render() | ||
assert output["services"]["test_container"]["depends_on"] == {"test_container2": "service_started"} | ||
|
||
|
||
def test_add_dependency_invalid_condition(mock_values): | ||
render = Render(mock_values) | ||
c1 = render.add_container("test_container", "test_image") | ||
with pytest.raises(Exception): | ||
c1.depends.add_dependency("test_container2", "invalid_condition") | ||
|
||
|
||
def test_add_dependency_missing_container(mock_values): | ||
render = Render(mock_values) | ||
c1 = render.add_container("test_container", "test_image") | ||
with pytest.raises(Exception): | ||
c1.depends.add_dependency("test_container2", "service_started") | ||
|
||
|
||
def test_add_dependency_duplicate(mock_values): | ||
render = Render(mock_values) | ||
c1 = render.add_container("test_container", "test_image") | ||
render.add_container("test_container2", "test_image") | ||
c1.depends.add_dependency("test_container2", "service_started") | ||
with pytest.raises(Exception): | ||
c1.depends.add_dependency("test_container2", "service_started") |
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