Changeset View
Changeset View
Standalone View
Standalone View
swh/icinga_plugins/tests/test_vault.py
Show First 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | def test_vault_immediate_success(requests_mock, mocker): | ||||
result = invoke([ | result = invoke([ | ||||
'--swh-web-url', 'mock://swh-web.example.org', | '--swh-web-url', 'mock://swh-web.example.org', | ||||
'--swh-storage-url', 'foo://example.org', | '--swh-storage-url', 'foo://example.org', | ||||
'check-vault', 'directory', | 'check-vault', 'directory', | ||||
]) | ]) | ||||
assert re.match( | assert re.match( | ||||
rf'VAULT OK - cooking directory {dir_id} took ' | rf'^VAULT OK - cooking directory {dir_id} took ' | ||||
r'[0-9]\.[0-9]{2}s and succeeded.\n' | r'[0-9]\.[0-9]{2}s and succeeded.\n' | ||||
r"| 'total time' = [0-9]\.[0-9]{2}s", | r"\| 'total time' = [0-9]\.[0-9]{2}s$", | ||||
result.output) | result.output) | ||||
assert result.exit_code == 0, result.output | assert result.exit_code == 0, result.output | ||||
sleep_mock.assert_called_once_with(10) | sleep_mock.assert_called_once_with(10) | ||||
def test_vault_delayed_success(requests_mock, mocker): | def test_vault_delayed_success(requests_mock, mocker): | ||||
scenario = WebScenario() | scenario = WebScenario() | ||||
Show All 14 Lines | def test_vault_delayed_success(requests_mock, mocker): | ||||
result = invoke([ | result = invoke([ | ||||
'--swh-web-url', 'mock://swh-web.example.org', | '--swh-web-url', 'mock://swh-web.example.org', | ||||
'--swh-storage-url', 'foo://example.org', | '--swh-storage-url', 'foo://example.org', | ||||
'check-vault', 'directory', | 'check-vault', 'directory', | ||||
]) | ]) | ||||
assert re.match( | assert re.match( | ||||
rf'VAULT OK - cooking directory {dir_id} took ' | rf'^VAULT OK - cooking directory {dir_id} took ' | ||||
r'[0-9]\.[0-9]{2}s and succeeded.\n' | r'[0-9]\.[0-9]{2}s and succeeded.\n' | ||||
r"| 'total time' = [0-9]\.[0-9]{2}s", | r"\| 'total time' = [0-9]\.[0-9]{2}s$", | ||||
result.output) | result.output) | ||||
assert result.exit_code == 0, result.output | assert result.exit_code == 0, result.output | ||||
assert sleep_mock.call_count == 2 | assert sleep_mock.call_count == 2 | ||||
def test_vault_failure(requests_mock, mocker): | def test_vault_failure(requests_mock, mocker): | ||||
scenario = WebScenario() | scenario = WebScenario() | ||||
Show All 13 Lines | def test_vault_failure(requests_mock, mocker): | ||||
result = invoke([ | result = invoke([ | ||||
'--swh-web-url', 'mock://swh-web.example.org', | '--swh-web-url', 'mock://swh-web.example.org', | ||||
'--swh-storage-url', 'foo://example.org', | '--swh-storage-url', 'foo://example.org', | ||||
'check-vault', 'directory', | 'check-vault', 'directory', | ||||
], catch_exceptions=True) | ], catch_exceptions=True) | ||||
assert re.match( | assert re.match( | ||||
rf'VAULT CRITICAL - cooking directory {dir_id} took ' | rf'^VAULT CRITICAL - cooking directory {dir_id} took ' | ||||
r'[0-9]\.[0-9]{2}s and failed with: foobar\n' | r'[0-9]\.[0-9]{2}s and failed with: foobar\n' | ||||
r"| 'total time' = [0-9]\.[0-9]{2}s", | r"\| 'total time' = [0-9]\.[0-9]{2}s\n$", | ||||
result.output) | result.output) | ||||
assert result.exit_code == 2, result.output | assert result.exit_code == 2, result.output | ||||
sleep_mock.assert_called_once_with(10) | sleep_mock.assert_called_once_with(10) | ||||
def test_vault_timeout(requests_mock, mocker): | def test_vault_timeout(requests_mock, mocker): | ||||
time_offset = 0 | time_offset = 0 | ||||
Show All 25 Lines | def test_vault_timeout(requests_mock, mocker): | ||||
result = invoke([ | result = invoke([ | ||||
'--swh-web-url', 'mock://swh-web.example.org', | '--swh-web-url', 'mock://swh-web.example.org', | ||||
'--swh-storage-url', 'foo://example.org', | '--swh-storage-url', 'foo://example.org', | ||||
'check-vault', 'directory', | 'check-vault', 'directory', | ||||
], catch_exceptions=True) | ], catch_exceptions=True) | ||||
assert re.match( | assert re.match( | ||||
rf'VAULT CRITICAL - cooking directory {dir_id} took more than ' | rf'^VAULT CRITICAL - cooking directory {dir_id} took more than ' | ||||
r'[0-9]+\.[0-9]{2}s and has status: foo\n' | r'[0-9]+\.[0-9]{2}s and has status: foo\n' | ||||
r"| 'total time' = [0-9]\.[0-9]{2}s", | r"\| 'total time' = [0-9]{4}\.[0-9]{2}s\n$", | ||||
result.output) | result.output) | ||||
assert result.exit_code == 2, result.output | assert result.exit_code == 2, result.output | ||||
assert sleep_mock.call_count == 2 | assert sleep_mock.call_count == 2 |