import pytest
from hypothesis import given, assume
from hypothesis.strategies import text

from flag_slurper.autolib import exploit


@pytest.mark.parametrize('err', exploit.FILTERED_ERRORS)
def test_log_error_filtered(mock, err):
    logger = mock.MagicMock()
    mock.patch('flag_slurper.autolib.exploit.logger.error', logger)
    exploit.log_error('There was an error', 'test', err)
    assert not logger.called


@given(err=text())
def test_log_error(mock, err):
    assume(err not in exploit.FILTERED_ERRORS)
    logger = mock.MagicMock()
    mock.patch('flag_slurper.autolib.exploit.logger.error', logger)
    exploit.log_error('There was an error', 'test', err)
    assert logger.called
