Usa API Win32 per verificare share
This commit is contained in:
@@ -1,32 +1,30 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import subprocess
|
||||
|
||||
from bakrest.server_check import share_is_reachable
|
||||
from bakrest.server_check import FILE_ATTRIBUTE_DIRECTORY, INVALID_FILE_ATTRIBUTES, share_is_reachable
|
||||
|
||||
|
||||
def test_share_is_reachable_returns_true_on_zero_exit(monkeypatch) -> None:
|
||||
def fake_run(*args, **kwargs):
|
||||
return subprocess.CompletedProcess(args[0], 0)
|
||||
|
||||
monkeypatch.setattr("bakrest.server_check.subprocess.run", fake_run)
|
||||
def test_share_is_reachable_returns_true_for_directory_attributes(monkeypatch) -> None:
|
||||
monkeypatch.setattr(
|
||||
"bakrest.server_check.ctypes.windll.kernel32.GetFileAttributesW",
|
||||
lambda path: FILE_ATTRIBUTE_DIRECTORY,
|
||||
)
|
||||
|
||||
assert share_is_reachable("\\\\server\\share", 3)
|
||||
|
||||
|
||||
def test_share_is_reachable_returns_false_on_nonzero_exit(monkeypatch) -> None:
|
||||
def fake_run(*args, **kwargs):
|
||||
return subprocess.CompletedProcess(args[0], 1)
|
||||
|
||||
monkeypatch.setattr("bakrest.server_check.subprocess.run", fake_run)
|
||||
def test_share_is_reachable_returns_false_for_invalid_attributes(monkeypatch) -> None:
|
||||
monkeypatch.setattr(
|
||||
"bakrest.server_check.ctypes.windll.kernel32.GetFileAttributesW",
|
||||
lambda path: INVALID_FILE_ATTRIBUTES,
|
||||
)
|
||||
|
||||
assert not share_is_reachable("\\\\server\\share", 3)
|
||||
|
||||
|
||||
def test_share_is_reachable_returns_false_on_timeout(monkeypatch) -> None:
|
||||
def fake_run(*args, **kwargs):
|
||||
raise subprocess.TimeoutExpired(args[0], 3)
|
||||
|
||||
monkeypatch.setattr("bakrest.server_check.subprocess.run", fake_run)
|
||||
def test_share_is_reachable_returns_false_for_non_directory(monkeypatch) -> None:
|
||||
monkeypatch.setattr(
|
||||
"bakrest.server_check.ctypes.windll.kernel32.GetFileAttributesW",
|
||||
lambda path: 0,
|
||||
)
|
||||
|
||||
assert not share_is_reachable("\\\\server\\share", 3)
|
||||
|
||||
Reference in New Issue
Block a user