28 lines
945 B
Python
28 lines
945 B
Python
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
from enodia_sentinel import assurance
|
|
from enodia_sentinel.config import Config
|
|
|
|
|
|
class TestHashChain(unittest.TestCase):
|
|
def test_artifact_records_chain_to_previous_hash(self):
|
|
with tempfile.TemporaryDirectory() as d:
|
|
cfg = Config()
|
|
cfg.log_dir = Path(d)
|
|
one = cfg.log_dir / "one.txt"
|
|
two = cfg.log_dir / "two.txt"
|
|
one.write_text("one")
|
|
two.write_text("two")
|
|
r1 = assurance.append_artifact(cfg, "test", one)
|
|
r2 = assurance.append_artifact(cfg, "test", two)
|
|
self.assertEqual(r2["prev_hash"], r1["chain_hash"])
|
|
summary = assurance.summary(cfg)
|
|
self.assertEqual(summary["count"], 2)
|
|
self.assertEqual(summary["last_hash"], r2["chain_hash"])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|