File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import argparse
2+ import tempfile
13import unittest
4+ from pathlib import Path
25from typing import Any
36from unittest .mock import MagicMock
47
8+ import yaml
9+
510from composekit .generate import (
611 Config ,
712 capitalize_name ,
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 ---\n image: 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}"
You can’t perform that action at this time.
0 commit comments