From e76e0e92d6155e88a58344ffc83f448fd0e9a939 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 21 Dec 2023 16:39:35 +0100 Subject: [PATCH] osbuild: take `partition` into account in `calc_id` and add test --- osbuild/mounts.py | 2 ++ test/mod/test_mounts.py | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 test/mod/test_mounts.py diff --git a/osbuild/mounts.py b/osbuild/mounts.py index 2cd33095..86576ad0 100644 --- a/osbuild/mounts.py +++ b/osbuild/mounts.py @@ -37,6 +37,8 @@ class Mount: m.update(json.dumps(self.info.name, sort_keys=True).encode()) if self.device: m.update(json.dumps(self.device.id, sort_keys=True).encode()) + if self.partition: + m.update(json.dumps(self.partition, sort_keys=True).encode()) if self.target: m.update(json.dumps(self.target, sort_keys=True).encode()) m.update(json.dumps(self.options, sort_keys=True).encode()) diff --git a/test/mod/test_mounts.py b/test/mod/test_mounts.py new file mode 100644 index 00000000..416706a4 --- /dev/null +++ b/test/mod/test_mounts.py @@ -0,0 +1,22 @@ +from unittest.mock import Mock + +import pytest + +from osbuild.mounts import Mount +from osbuild.meta import ModuleInfo + + +def test_mount_calc_id_is_stable(): + info = Mock(spec=ModuleInfo) + info.name = "some-name" + device = Mock(spec=ModuleInfo) + device.id = "some-id" + partition = 1 + target = "/" + opts = {"opt1": 1} + # make sure to update Mount.calc_id and this test when adding + # parameters here + mount1 = Mount("name", info, device, partition, target, opts) + assert mount1.id == "15066da9ff760a60f1d1a360de2ad584cc0c97d6f6034e3258b3275ba3da6bb2" + mount2 = Mount("name", info, device, partition, target, opts) + assert mount1.id == mount2.id