mirror of
https://github.com/saltstack/salt.git
synced 2025-04-16 17:50:20 +00:00
add tests and add support for an iter
This commit is contained in:
parent
f122899f2b
commit
370d6e4f0f
2 changed files with 41 additions and 20 deletions
|
@ -334,6 +334,15 @@ __func_alias__ = {
|
|||
}
|
||||
|
||||
|
||||
def _http_ftp_check(source):
|
||||
"""
|
||||
Check if source or sources
|
||||
"""
|
||||
if isinstance(source, str):
|
||||
return source.lower().startswith(("http:", "ftp:"))
|
||||
return all([s.lower().startswith(("http:", "ftp:")) for s in source])
|
||||
|
||||
|
||||
def _get_accumulator_filepath():
|
||||
"""
|
||||
Return accumulator data path.
|
||||
|
@ -2948,11 +2957,7 @@ def managed(
|
|||
"'contents_grains' is permitted",
|
||||
)
|
||||
|
||||
if (
|
||||
source is not None
|
||||
and not source.lower().startswith(("http:", "ftp:"))
|
||||
and source_hash
|
||||
):
|
||||
if source is not None and not _http_ftp_check(source) and source_hash:
|
||||
log.warning("source_hash is only used with 'http' or 'ftp'")
|
||||
|
||||
# If no source is specified, set replace to False, as there is nothing
|
||||
|
@ -6007,11 +6012,7 @@ def blockreplace(
|
|||
if not name:
|
||||
return _error(ret, "Must provide name to file.blockreplace")
|
||||
|
||||
if (
|
||||
source is not None
|
||||
and not source.lower().startswith(("http:", "ftp:"))
|
||||
and source_hash
|
||||
):
|
||||
if source is not None and not _http_ftp_check(source) and source_hash:
|
||||
log.warning("source_hash is only used with 'http' or 'ftp'")
|
||||
|
||||
if sources is None:
|
||||
|
@ -6450,11 +6451,7 @@ def append(
|
|||
if not name:
|
||||
return _error(ret, "Must provide name to file.append")
|
||||
|
||||
if (
|
||||
source is not None
|
||||
and not source.lower().startswith(("http:", "ftp:"))
|
||||
and source_hash
|
||||
):
|
||||
if source is not None and not _http_ftp_check(source) and source_hash:
|
||||
log.warning("source_hash is only used with 'http' or 'ftp'")
|
||||
|
||||
name = os.path.expanduser(name)
|
||||
|
@ -6741,11 +6738,7 @@ def prepend(
|
|||
if not name:
|
||||
return _error(ret, "Must provide name to file.prepend")
|
||||
|
||||
if (
|
||||
source is not None
|
||||
and not source.lower().startswith(("http:", "ftp:"))
|
||||
and source_hash
|
||||
):
|
||||
if source is not None and not _http_ftp_check(source) and source_hash:
|
||||
log.warning("source_hash is only used with 'http' or 'ftp'")
|
||||
|
||||
if sources is None:
|
||||
|
|
|
@ -405,3 +405,31 @@ def test_managed_test_mode_user_group_not_present():
|
|||
)
|
||||
assert ret["result"] is not False
|
||||
assert "is not available" not in ret["comment"]
|
||||
|
||||
|
||||
def test_http_ftp_check_pass():
|
||||
assert filestate._http_ftp_check("http://@$@dead_link@$@/src.tar.gz") is True
|
||||
assert filestate._http_ftp_check("ftp://@$@dead_link@$@/src.tar.gz") is True
|
||||
|
||||
|
||||
def test_http_ftp_check_fail():
|
||||
assert filestate._http_ftp_check("salt://@$@dead_link@$@/src.tar.gz") is False
|
||||
assert filestate._http_ftp_check("https://@$@dead_link@$@/src.tar.gz") is False
|
||||
|
||||
|
||||
def test_http_ftp_check_list_pass():
|
||||
assert (
|
||||
filestate._http_ftp_check(
|
||||
["http://@$@dead_link@$@/src.tar.gz", "ftp://@$@dead_link@$@/src.tar.gz"]
|
||||
)
|
||||
is True
|
||||
)
|
||||
|
||||
|
||||
def test_http_ftp_check_list_fail():
|
||||
assert (
|
||||
filestate._http_ftp_check(
|
||||
["salt://@$@dead_link@$@/src.tar.gz", "https://@$@dead_link@$@/src.tar.gz"]
|
||||
)
|
||||
is False
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue