Skip to content

Commit

Permalink
Merge pull request #412 from Limmen/aggreagtedOSSEC
Browse files Browse the repository at this point in the history
unit test aggregated_ossec_ids_log_consumer_thread
  • Loading branch information
Limmen authored Aug 4, 2024
2 parents 369f646 + 083c9ac commit 8fcdd88
Showing 1 changed file with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from unittest.mock import MagicMock,patch
from csle_common.consumer_threads.aggregated_ossec_ids_log_consumer_thread import AggregatedOSSECIdsLogConsumerThread


class TestSuiteAggregatedOSSECIdsLogConsumerThread:
"""
Test suite for AggregatedOSSECIdsLogConsumerThread
"""

def test_initialization(self) -> None:
"""_summary_"""
kafka_server_ip = "127.0.0.1"
kafka_port = 9092
alert_counters = MagicMock()
auto_offset_reset = "earliest"

thread = AggregatedOSSECIdsLogConsumerThread(
kafka_server_ip=kafka_server_ip,
kafka_port=kafka_port,
ossec_ids_alert_counters=alert_counters,
auto_offset_reset=auto_offset_reset,
)
assert thread.running
assert thread.kafka_server_ip == kafka_server_ip
assert thread.kafka_port == kafka_port
assert thread.ossec_ids_alert_counters == alert_counters

def test_get_aggregated_ids_alert_counters(self) -> None:
"""
Test the method that returns the aggregated alert counters from the list
:return: None
"""
mock_alert_counters_1 = MagicMock()
mock_alert_counters_2 = MagicMock()
mock_alert_counters_1.copy.return_value = mock_alert_counters_1
mock_alert_counters_2.copy.return_value = mock_alert_counters_2
mock_alert_counters_1.add = MagicMock()
kafka_server_ip = "127.0.0.1"
kafka_port = 9092
alert_counters = MagicMock()
auto_offset_reset = "earliest"
thread = AggregatedOSSECIdsLogConsumerThread(
kafka_server_ip=kafka_server_ip,
kafka_port=kafka_port,
ossec_ids_alert_counters=alert_counters,
auto_offset_reset=auto_offset_reset,
)
thread.ossec_ids_alert_counters_list = []
thread.ossec_ids_alert_counters = mock_alert_counters_1

result = thread.get_aggregated_ids_alert_counters()
assert result == mock_alert_counters_1.copy.return_value

0 comments on commit 8fcdd88

Please sign in to comment.