forked from p15670423/monkey
UT: Add proper test for ControlChannel.should_agent_stop()
This commit is contained in:
parent
a5f1117ce3
commit
f7198ea98a
|
@ -1,8 +1,10 @@
|
|||
from typing import Optional
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
from infection_monkey.i_control_channel import IslandCommunicationError
|
||||
from common import AgentSignals
|
||||
from infection_monkey.i_control_channel import IControlChannel, IslandCommunicationError
|
||||
from infection_monkey.island_api_client import (
|
||||
IIslandAPIClient,
|
||||
IslandAPIConnectionError,
|
||||
|
@ -33,9 +35,17 @@ def control_channel(island_api_client) -> ControlChannel:
|
|||
return ControlChannel(SERVER, AGENT_ID, island_api_client)
|
||||
|
||||
|
||||
def test_control_channel__should_agent_stop(control_channel, island_api_client):
|
||||
control_channel.should_agent_stop()
|
||||
assert island_api_client.get_agent_signals.called_once()
|
||||
@pytest.mark.parametrize("signal_time,expected_should_stop", [(1663950115, True), (None, False)])
|
||||
def test_control_channel__should_agent_stop(
|
||||
control_channel: IControlChannel,
|
||||
island_api_client: IIslandAPIClient,
|
||||
signal_time: Optional[int],
|
||||
expected_should_stop: bool,
|
||||
):
|
||||
island_api_client.get_agent_signals = MagicMock(
|
||||
return_value=AgentSignals(terminate=signal_time)
|
||||
)
|
||||
assert control_channel.should_agent_stop() is expected_should_stop
|
||||
|
||||
|
||||
@pytest.mark.parametrize("api_error", CONTROL_CHANNEL_API_ERRORS)
|
||||
|
|
Loading…
Reference in New Issue