Explorar el Código

Refactor test: Extract helper function to reduce code duplication

- Created _generate_traefik_template() helper function
- Reduced code duplication between test functions
- Fixed whitespace linting issue
- All 52 tests passing

Co-authored-by: ChristianLempa <28359525+ChristianLempa@users.noreply.github.com>
copilot-swe-agent[bot] hace 1 mes
padre
commit
21d1b3b4fe
Se han modificado 1 ficheros con 28 adiciones y 40 borrados
  1. 28 40
      tests/test_traefik_template.py

+ 28 - 40
tests/test_traefik_template.py

@@ -5,31 +5,38 @@ import tempfile
 from pathlib import Path
 
 
+def _generate_traefik_template(output_dir: Path) -> None:
+    """Helper function to generate traefik template.
+
+    Args:
+        output_dir: Directory where template should be generated
+    """
+    subprocess.run(
+        [
+            "python3",
+            "-m",
+            "cli",
+            "compose",
+            "generate",
+            "traefik",
+            "--no-interactive",
+            "-o",
+            str(output_dir),
+            "--var",
+            "traefik_tls_acme_email=test@example.com",
+        ],
+        capture_output=True,
+        text=True,
+        check=True,
+    )
+
+
 def test_traefik_no_duplicate_ping_entrypoint():
     """Test that the traefik template does not generate duplicate --ping.entryPoint arguments."""
     # Generate the template
     with tempfile.TemporaryDirectory() as tmpdir:
         output_dir = Path(tmpdir)
-
-        # Run the CLI to generate the traefik template
-        subprocess.run(
-            [
-                "python3",
-                "-m",
-                "cli",
-                "compose",
-                "generate",
-                "traefik",
-                "--no-interactive",
-                "-o",
-                str(output_dir),
-                "--var",
-                "traefik_tls_acme_email=test@example.com",
-            ],
-            capture_output=True,
-            text=True,
-            check=True,
-        )
+        _generate_traefik_template(output_dir)
 
         # Read the generated compose.yaml
         compose_file = output_dir / "compose.yaml"
@@ -52,26 +59,7 @@ def test_traefik_template_renders_successfully():
     # Generate the template
     with tempfile.TemporaryDirectory() as tmpdir:
         output_dir = Path(tmpdir)
-
-        # Run the CLI to generate the traefik template
-        subprocess.run(
-            [
-                "python3",
-                "-m",
-                "cli",
-                "compose",
-                "generate",
-                "traefik",
-                "--no-interactive",
-                "-o",
-                str(output_dir),
-                "--var",
-                "traefik_tls_acme_email=test@example.com",
-            ],
-            capture_output=True,
-            text=True,
-            check=True,
-        )
+        _generate_traefik_template(output_dir)
 
         # Verify compose.yaml exists (main file)
         assert (output_dir / "compose.yaml").exists(), "compose.yaml not generated"