Switch to existing test fixtures

This commit is contained in:
Pedro Algarvio 2024-02-07 13:20:05 +00:00
parent f25bbaf744
commit 063adf0493

View file

@ -1,65 +1,31 @@
"""
tests.pytests.unit.test_config
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Unit tests for salt.fileclient
"""
import salt.config
from salt import fileclient
import salt.fileclient as fileclient
from tests.support.mock import MagicMock, patch
def _defaults(**kwargs):
"""
master/minion config defaults
"""
ret = {
"saltenv": kwargs.pop("saltenv", None),
"id": "test",
"cachedir": "/A",
"sock_dir": "/B",
"root_dir": "/C",
"fileserver_backend": "roots",
"open_mode": False,
"auto_accept": False,
"file_roots": {},
"pillar_roots": {},
"file_ignore_glob": [],
"file_ignore_regex": [],
"worker_threads": 5,
"hash_type": "sha256",
"log_file": "foo.log",
"ssl": True,
"file_client": "local",
}
ret.update(kwargs)
return ret
def test_master_no_fs_update():
def test_master_no_fs_update(master_opts):
"""
Test that an FSClient spawned from the master does not cause fileserver
backends to be refreshed on instantiation. The master already has the
maintenance thread for that.
"""
opts = salt.config.apply_master_config(defaults=_defaults())
master_opts["file_client"] = "local"
fileserver = MagicMock()
with patch("salt.fileserver.Fileserver", fileserver):
client = fileclient.FSClient(opts)
client = fileclient.FSClient(master_opts)
assert client.channel.fs.update.call_count == 0
def test_masterless_fs_update():
def test_masterless_fs_update(minion_opts):
"""
Test that an FSClient spawned from a masterless run refreshes the
fileserver backends. This is necessary to ensure that a masterless run
can access any configured gitfs remotes.
"""
opts = salt.config.apply_minion_config(defaults=_defaults())
minion_opts["file_client"] = "local"
fileserver = MagicMock()
with patch("salt.fileserver.Fileserver", fileserver):
client = fileclient.FSClient(opts)
client = fileclient.FSClient(minion_opts)
assert client.channel.fs.update.call_count == 1