mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
update some unit tests
This commit is contained in:
parent
27c0b43e25
commit
c521434bdd
4 changed files with 28 additions and 57 deletions
|
@ -465,10 +465,13 @@ class GitProvider:
|
|||
"/", "_"
|
||||
) # replace "/" with "_" to not cause trouble with file system
|
||||
self._cache_hash = salt.utils.path.join(cache_root, self._cache_basehash)
|
||||
try:
|
||||
self._cache_basename = self.get_checkout_target()
|
||||
except AttributeError:
|
||||
self._cache_basename = "_"
|
||||
self._cache_basename = "_"
|
||||
if self.id.startswith("__env__"):
|
||||
try:
|
||||
self._cache_basename = self.get_checkout_target()
|
||||
except AttributeError:
|
||||
log.critical(f"__env__ cant generate basename: {self.role} {self.id}")
|
||||
failhard(self.role)
|
||||
self._cache_full_basename = salt.utils.path.join(
|
||||
self._cache_basehash, self._cache_basename
|
||||
)
|
||||
|
@ -2566,8 +2569,8 @@ class GitBase:
|
|||
remote_set = {r.get_cache_basehash() for r in self.remotes}
|
||||
for item in self._iter_remote_hashs():
|
||||
if item not in remote_set:
|
||||
change = change or self._remove_cache_dir(
|
||||
salt.utils.path.join(self.cache_root, item)
|
||||
change = self._remove_cache_dir(
|
||||
salt.utils.path.join(self.cache_root, item) or change
|
||||
)
|
||||
if not change:
|
||||
self.write_remote_map()
|
||||
|
|
|
@ -21,35 +21,33 @@ from tests.support.mock import MagicMock, patch
|
|||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def test_minion_load_grains_false():
|
||||
def test_minion_load_grains_false(minion_opts):
|
||||
"""
|
||||
Minion does not generate grains when load_grains is False
|
||||
"""
|
||||
opts = {"random_startup_delay": 0, "grains": {"foo": "bar"}}
|
||||
minion_opts["grains"] = {"foo": "bar"}
|
||||
with patch("salt.loader.grains") as grainsfunc:
|
||||
minion = salt.minion.Minion(opts, load_grains=False)
|
||||
assert minion.opts["grains"] == opts["grains"]
|
||||
minion = salt.minion.Minion(minion_opts, load_grains=False)
|
||||
assert minion.opts["grains"] == minion_opts["grains"]
|
||||
grainsfunc.assert_not_called()
|
||||
|
||||
|
||||
def test_minion_load_grains_true():
|
||||
def test_minion_load_grains_true(minion_opts):
|
||||
"""
|
||||
Minion generates grains when load_grains is True
|
||||
"""
|
||||
opts = {"random_startup_delay": 0, "grains": {}}
|
||||
with patch("salt.loader.grains") as grainsfunc:
|
||||
minion = salt.minion.Minion(opts, load_grains=True)
|
||||
minion = salt.minion.Minion(minion_opts, load_grains=True)
|
||||
assert minion.opts["grains"] != {}
|
||||
grainsfunc.assert_called()
|
||||
|
||||
|
||||
def test_minion_load_grains_default():
|
||||
def test_minion_load_grains_default(minion_opts):
|
||||
"""
|
||||
Minion load_grains defaults to True
|
||||
"""
|
||||
opts = {"random_startup_delay": 0, "grains": {}}
|
||||
with patch("salt.loader.grains") as grainsfunc:
|
||||
minion = salt.minion.Minion(opts)
|
||||
minion = salt.minion.Minion(minion_opts)
|
||||
assert minion.opts["grains"] != {}
|
||||
grainsfunc.assert_called()
|
||||
|
||||
|
@ -141,22 +139,17 @@ async def test_send_req_async_regression_62453(minion_opts):
|
|||
assert rtn is False
|
||||
|
||||
|
||||
def test_mine_send_tries():
|
||||
def test_mine_send_tries(minion_opts):
|
||||
channel_enter = MagicMock()
|
||||
channel_enter.send.side_effect = lambda load, timeout, tries: tries
|
||||
channel = MagicMock()
|
||||
channel.__enter__.return_value = channel_enter
|
||||
|
||||
opts = {
|
||||
"random_startup_delay": 0,
|
||||
"grains": {},
|
||||
"return_retry_tries": 20,
|
||||
"minion_sign_messages": False,
|
||||
}
|
||||
minion_opts["return_retry_tries"] = 20
|
||||
with patch("salt.channel.client.ReqChannel.factory", return_value=channel), patch(
|
||||
"salt.loader.grains"
|
||||
):
|
||||
minion = salt.minion.Minion(opts)
|
||||
minion = salt.minion.Minion(minion_opts)
|
||||
minion.tok = "token"
|
||||
|
||||
data = {}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import os
|
||||
import string
|
||||
import time
|
||||
|
||||
import pytest
|
||||
|
@ -231,11 +230,11 @@ def test_checkout_pygit2(_prepare_provider):
|
|||
provider.init_remote()
|
||||
provider.fetch()
|
||||
provider.branch = "master"
|
||||
assert provider.cachedir in provider.checkout()
|
||||
assert provider.get_cachedir() in provider.checkout()
|
||||
provider.branch = "simple_tag"
|
||||
assert provider.cachedir in provider.checkout()
|
||||
assert provider.get_cachedir() in provider.checkout()
|
||||
provider.branch = "annotated_tag"
|
||||
assert provider.cachedir in provider.checkout()
|
||||
assert provider.get_cachedir() in provider.checkout()
|
||||
provider.branch = "does_not_exist"
|
||||
assert provider.checkout() is None
|
||||
|
||||
|
@ -244,20 +243,9 @@ def test_checkout_pygit2(_prepare_provider):
|
|||
@pytest.mark.skip_on_windows(
|
||||
reason="Skip Pygit2 on windows, due to pygit2 access error on windows"
|
||||
)
|
||||
def test_full_id_pygit2(_prepare_provider):
|
||||
assert _prepare_provider.full_id().startswith("-")
|
||||
assert _prepare_provider.full_id().endswith("/pygit2-repo---gitfs-master--")
|
||||
|
||||
|
||||
@pytest.mark.skipif(not HAS_PYGIT2, reason="This host lacks proper pygit2 support")
|
||||
@pytest.mark.skip_on_windows(
|
||||
reason="Skip Pygit2 on windows, due to pygit2 access error on windows"
|
||||
)
|
||||
def test_get_cachedir_basename_pygit2(_prepare_provider):
|
||||
basename = _prepare_provider.get_cachedir_basename()
|
||||
# Note: if you are changing the length of basename
|
||||
# keep in mind that pygit2 will error out on large file paths on Windows
|
||||
assert len(basename) == 45
|
||||
assert basename[0] == "-"
|
||||
# check that a valid base64 is given '/' -> '_'
|
||||
assert all(c in string.ascii_letters + string.digits + "+_=" for c in basename[1:])
|
||||
assert "_" == _prepare_provider.get_cache_basename()
|
||||
|
|
|
@ -114,27 +114,14 @@ class TestGitBase(TestCase, AdaptedConfigurationTestCaseMixin):
|
|||
self.assertTrue(self.main_class.remotes[0].fetched)
|
||||
self.assertFalse(self.main_class.remotes[1].fetched)
|
||||
|
||||
def test_full_id(self):
|
||||
self.assertEqual(
|
||||
self.main_class.remotes[0].full_id(), "-file://repo1.git---gitfs-master--"
|
||||
)
|
||||
|
||||
def test_full_id_with_name(self):
|
||||
self.assertEqual(
|
||||
self.main_class.remotes[1].full_id(),
|
||||
"repo2-file://repo2.git---gitfs-master--",
|
||||
)
|
||||
|
||||
def test_get_cachedir_basename(self):
|
||||
self.assertEqual(
|
||||
self.main_class.remotes[0].get_cachedir_basename(),
|
||||
"-jXhnbGDemchtZwTwaD2s6VOaVvs98a7w+AtiYlmOVb0=",
|
||||
self.main_class.remotes[0].get_cache_basename(),
|
||||
"_",
|
||||
)
|
||||
|
||||
def test_get_cachedir_base_with_name(self):
|
||||
self.assertEqual(
|
||||
self.main_class.remotes[1].get_cachedir_basename(),
|
||||
"repo2-nuezpiDtjQRFC0ZJDByvi+F6Vb8ZhfoH41n_KFxTGsU=",
|
||||
self.main_class.remotes[1].get_cache_basename(),
|
||||
"_",
|
||||
)
|
||||
|
||||
def test_git_provider_mp_lock(self):
|
||||
|
|
Loading…
Add table
Reference in a new issue