Skip to content

Commit e471d95

Browse files
committed
Update tests for fail-fast DISTRO behavior and ubuntu codename mapping
1 parent 2dd62f1 commit e471d95

1 file changed

Lines changed: 23 additions & 4 deletions

File tree

test_module_metadata.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,35 @@ def test_uses_devcontainer_distro_before_host_distro(self):
1818
with mock.patch.object(module_metadata.distro, "version_parts", return_value=("8",)):
1919
self.assertEqual(module_metadata.get_curr_os(), "amzn2023")
2020

21-
def test_falls_back_to_distro_when_devcontainer_has_no_distro(self):
21+
def test_raises_when_devcontainer_has_no_distro(self):
2222
with tempfile.TemporaryDirectory() as temp_dir:
2323
devcontainer_path = os.path.join(temp_dir, "devcontainer")
2424
with open(devcontainer_path, "w") as f:
2525
f.write("OTHER=value\n")
2626

2727
with mock.patch.object(module_metadata, "DEVCONTAINER_PATH", devcontainer_path):
28-
with mock.patch.object(module_metadata.distro, "id", return_value="rocky"):
29-
with mock.patch.object(module_metadata.distro, "version_parts", return_value=("8",)):
30-
self.assertEqual(module_metadata.get_curr_os(), "rhel8")
28+
with self.assertRaises(KeyError):
29+
module_metadata.get_curr_os()
30+
31+
def test_maps_ubuntu_codenames_to_versions(self):
32+
with tempfile.TemporaryDirectory() as temp_dir:
33+
for distro_value, expected in (("focal", "ubuntu20"), ("jammy", "ubuntu22")):
34+
devcontainer_path = os.path.join(temp_dir, "devcontainer")
35+
with open(devcontainer_path, "w") as f:
36+
f.write("DISTRO=%s\n" % distro_value)
37+
38+
with mock.patch.object(module_metadata, "DEVCONTAINER_PATH", devcontainer_path):
39+
self.assertEqual(module_metadata.get_curr_os(), expected)
40+
41+
def test_amzn2023_unchanged_but_jammy_mapped_to_ubuntu22(self):
42+
with tempfile.TemporaryDirectory() as temp_dir:
43+
for distro_value, expected in (("amzn2023", "amzn2023"), ("jammy", "ubuntu22")):
44+
devcontainer_path = os.path.join(temp_dir, "devcontainer")
45+
with open(devcontainer_path, "w") as f:
46+
f.write("DISTRO=%s\n" % distro_value)
47+
48+
with mock.patch.object(module_metadata, "DEVCONTAINER_PATH", devcontainer_path):
49+
self.assertEqual(module_metadata.get_curr_os(), expected)
3150

3251
def test_preserves_distro_fallback_when_devcontainer_is_absent(self):
3352
devcontainer_path = os.path.join(tempfile.gettempdir(), "missing-devcontainer")

0 commit comments

Comments
 (0)