mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-03 23:14:02 -07:00
initial nfs_exports_info module
This commit is contained in:
parent
86507e8aca
commit
309fe6d4d0
3 changed files with 181 additions and 0 deletions
56
tests/unit/plugins/modules/test_nfs_exports_info.py
Normal file
56
tests/unit/plugins/modules/test_nfs_exports_info.py
Normal file
|
@ -0,0 +1,56 @@
|
|||
import pytest
|
||||
from unittest.mock import mock_open, patch, MagicMock
|
||||
from nfs_exports_info import get_exports
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def fake_exports_content():
|
||||
return """
|
||||
# Sample exports
|
||||
/srv/nfs1 192.168.1.10(rw,sync) 192.168.1.20(ro,sync)
|
||||
/srv/nfs2 192.168.1.30(rw,no_root_squash)
|
||||
"""
|
||||
|
||||
|
||||
def test_get_exports_ips_per_share(fake_exports_content):
|
||||
mock_module = MagicMock()
|
||||
mock_module.digest_from_file.return_value = "fake_sha1_digest"
|
||||
|
||||
with patch("builtins.open", mock_open(read_data=fake_exports_content)):
|
||||
result = get_exports(mock_module, "ips_per_share")
|
||||
|
||||
expected = {
|
||||
'/srv/nfs1': [
|
||||
{'ip': '192.168.1.10', 'options': ['rw', 'sync']},
|
||||
{'ip': '192.168.1.20', 'options': ['ro', 'sync']}
|
||||
],
|
||||
'/srv/nfs2': [
|
||||
{'ip': '192.168.1.30', 'options': ['rw', 'no_root_squash']}
|
||||
]
|
||||
}
|
||||
|
||||
assert result['exports_info'] == expected
|
||||
assert result['file_digest'] == "fake_sha1_digest"
|
||||
|
||||
|
||||
def test_get_exports_shares_per_ip(fake_exports_content):
|
||||
mock_module = MagicMock()
|
||||
mock_module.digest_from_file.return_value = "fake_sha1_digest"
|
||||
|
||||
with patch("builtins.open", mock_open(read_data=fake_exports_content)):
|
||||
result = get_exports(mock_module, "shares_per_ip")
|
||||
|
||||
expected = {
|
||||
'192.168.1.10': [
|
||||
{'folder': '/srv/nfs1', 'options': ['rw', 'sync']}
|
||||
],
|
||||
'192.168.1.20': [
|
||||
{'folder': '/srv/nfs1', 'options': ['ro', 'sync']}
|
||||
],
|
||||
'192.168.1.30': [
|
||||
{'folder': '/srv/nfs2', 'options': ['rw', 'no_root_squash']}
|
||||
]
|
||||
}
|
||||
|
||||
assert result['exports_info'] == expected
|
||||
assert result['file_digest'] == "fake_sha1_digest"
|
Loading…
Add table
Add a link
Reference in a new issue