1#!/usr/bin/env python3
2from pathlib import Path
3import tempfile
4import unittest
5from unittest.mock import patch
6
7import snowglobe
8
9
10class BuildBoundary(unittest.TestCase):
11 def test_shared_context_stays_inside_the_service_tree(self):
12 with tempfile.TemporaryDirectory() as temporary:
13 root = Path(temporary).resolve()
14 consumer = root / "service/consumer"
15 shared = root / "service/shared"
16 consumer.mkdir(parents=True)
17 (consumer / "service.pkl").touch()
18 shared.mkdir()
19 (shared / "Dockerfile").touch()
20 (root / "Dockerfile").touch()
21 (consumer / "escape").symlink_to(root, target_is_directory=True)
22 with patch.object(snowglobe, "REPO", root), patch.object(snowglobe, "SERVICES", root / "service"):
23 self.assertEqual(snowglobe.build_context("consumer", "../shared"), shared)
24 for relative in ("../..", "escape", "."):
25 with self.subTest(relative=relative), self.assertRaises(ValueError):
26 snowglobe.build_context("consumer", relative)
27 with self.assertRaises(ValueError):
28 snowglobe.config_path("consumer", "../shared/Dockerfile")
29
30
31if __name__ == "__main__":
32 unittest.main()