Skip to content

Commit 902325f

Browse files
committed
test(generate): cover duplicate containers without folder
1 parent 2c1f355 commit 902325f

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

tests/test_generate.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
import argparse
2+
import tempfile
13
import unittest
4+
from pathlib import Path
25
from typing import Any
36
from unittest.mock import MagicMock
47

8+
import yaml
9+
510
from composekit.generate import (
611
Config,
712
capitalize_name,
@@ -10,6 +15,7 @@
1015
get_folder_name,
1116
handle_volumes,
1217
is_custom_bind,
18+
main,
1319
)
1420

1521

@@ -84,6 +90,32 @@ def test_generate_minimal(self) -> None:
8490
self.assertEqual(result["restart"], "unless-stopped")
8591
self.assertEqual(result["networks"], ["cloud"])
8692

93+
def test_main_handles_duplicate_containers_without_folder(self) -> None:
94+
with tempfile.TemporaryDirectory() as directory:
95+
root = Path(directory)
96+
containers = root / "containers"
97+
composes = root / "composes"
98+
output = root / "docker-compose.yaml"
99+
containers.mkdir()
100+
(containers / "container.yaml").write_text(
101+
"image: nginx\n---\nimage: redis\n"
102+
)
103+
104+
args = argparse.Namespace(
105+
config=None,
106+
containers=str(containers),
107+
composes=str(composes),
108+
output=str(output),
109+
commit=False,
110+
)
111+
112+
main(args)
113+
114+
compose = yaml.safe_load((composes / "container.yaml").read_text())
115+
self.assertEqual(
116+
list(compose["services"].keys()), ["container", "container_2"]
117+
)
118+
87119
def test_handle_volumes_with_full_capitalize(self) -> None:
88120
config = Config()
89121
config["bind_path"] = "${BIND_PATH}"

0 commit comments

Comments
 (0)