From 6aae63f9fc3ccab7655f938aef018d5e2db75798 Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Wed, 28 Sep 2022 16:10:55 +0530 Subject: [PATCH] UT: Add tests for FileAgentLogRepository --- .../test_file_agent_log_repository.py | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 monkey/tests/unit_tests/monkey_island/cc/repository/test_file_agent_log_repository.py diff --git a/monkey/tests/unit_tests/monkey_island/cc/repository/test_file_agent_log_repository.py b/monkey/tests/unit_tests/monkey_island/cc/repository/test_file_agent_log_repository.py new file mode 100644 index 000000000..035903e18 --- /dev/null +++ b/monkey/tests/unit_tests/monkey_island/cc/repository/test_file_agent_log_repository.py @@ -0,0 +1,39 @@ +from uuid import UUID + +import pytest +from tests.monkey_island import OpenErrorFileRepository, SingleFileRepository + +from monkey_island.cc.repository import FileAgentLogRepository, RetrievalError, UnknownRecordError + +LOG_CONTENTS = "lots of useful information" +AGENT_ID = UUID("6bfd8b64-43d8-4449-8c70-d898aca74ad8") + + +@pytest.fixture +def repository(): + return FileAgentLogRepository(SingleFileRepository()) + + +def test_store_agent_log(repository): + repository.upsert_agent_log(AGENT_ID, LOG_CONTENTS) + retrieved_log_contents = repository.get_agent_log(AGENT_ID) + + assert retrieved_log_contents == LOG_CONTENTS + + +def test_get_agent_log__unknown_record_error(repository): + with pytest.raises(UnknownRecordError): + repository.get_agent_log(AGENT_ID) + + +def test_get_agent_log__retrieval_error(): + repository = FileAgentLogRepository(OpenErrorFileRepository()) + with pytest.raises(RetrievalError): + repository.get_agent_log(AGENT_ID) + + +def test_reset_agent_logs(repository): + repository.upsert_agent_log(AGENT_ID, LOG_CONTENTS) + repository.reset() + with pytest.raises(UnknownRecordError): + repository.get_agent_log(AGENT_ID)