parent
18d5f66542
commit
6c1970fb41
3 changed files with 15 additions and 10 deletions
|
@ -3,14 +3,16 @@
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("condition", ["os-release", "os-release-quotes", "missing"])
|
@pytest.mark.parametrize("condition", ["os-release", "os-release-quotes", "missing", "fallback"])
|
||||||
def test_query_distro_family(runner, yadm, tmp_path, condition):
|
def test_query_distro_family(runner, yadm, tmp_path, condition):
|
||||||
"""Match ID_LIKE when present"""
|
"""Match ID_LIKE when present"""
|
||||||
test_family = "testfamily"
|
test_family = "testfamily"
|
||||||
os_release = tmp_path.joinpath("os-release")
|
os_release = tmp_path.joinpath("os-release")
|
||||||
if "os-release" in condition:
|
if "os-release" in condition:
|
||||||
quotes = '"' if "quotes" in condition else ""
|
quotes = '"' if "quotes" in condition else ""
|
||||||
os_release.write_text(f"testing\nID_LIKE={quotes}{test_family}{quotes}\nfamily")
|
os_release.write_text(f"testing\nID=test\nID_LIKE={quotes}{test_family}{quotes}\nfamily")
|
||||||
|
elif condition == "fallback":
|
||||||
|
os_release.write_text(f'testing\nID="{test_family}"\nfamily')
|
||||||
script = f"""
|
script = f"""
|
||||||
YADM_TEST=1 source {yadm}
|
YADM_TEST=1 source {yadm}
|
||||||
OS_RELEASE="{os_release}"
|
OS_RELEASE="{os_release}"
|
||||||
|
@ -19,7 +21,7 @@ def test_query_distro_family(runner, yadm, tmp_path, condition):
|
||||||
run = runner(command=["bash"], inp=script)
|
run = runner(command=["bash"], inp=script)
|
||||||
assert run.success
|
assert run.success
|
||||||
assert run.err == ""
|
assert run.err == ""
|
||||||
if "os-release" in condition:
|
if condition == "missing":
|
||||||
assert run.out.rstrip() == test_family
|
|
||||||
else:
|
|
||||||
assert run.out.rstrip() == ""
|
assert run.out.rstrip() == ""
|
||||||
|
else:
|
||||||
|
assert run.out.rstrip() == test_family
|
||||||
|
|
10
yadm
10
yadm
|
@ -1499,7 +1499,7 @@ function exclude_encrypted() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function query_distro() {
|
function query_distro() {
|
||||||
distro=""
|
local distro=""
|
||||||
if command -v "$LSB_RELEASE_PROGRAM" &> /dev/null; then
|
if command -v "$LSB_RELEASE_PROGRAM" &> /dev/null; then
|
||||||
distro=$($LSB_RELEASE_PROGRAM -si 2>/dev/null)
|
distro=$($LSB_RELEASE_PROGRAM -si 2>/dev/null)
|
||||||
elif [ -f "$OS_RELEASE" ]; then
|
elif [ -f "$OS_RELEASE" ]; then
|
||||||
|
@ -1515,17 +1515,19 @@ function query_distro() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function query_distro_family() {
|
function query_distro_family() {
|
||||||
family=""
|
local family=""
|
||||||
if [ -f "$OS_RELEASE" ]; then
|
if [ -f "$OS_RELEASE" ]; then
|
||||||
while IFS='' read -r line || [ -n "$line" ]; do
|
while IFS='' read -r line || [ -n "$line" ]; do
|
||||||
if [[ "$line" = ID_LIKE=* ]]; then
|
if [[ "$line" = ID_LIKE=* ]]; then
|
||||||
family="${line#ID_LIKE=}"
|
family="${line#ID_LIKE=}"
|
||||||
family="${family//\"}"
|
|
||||||
break
|
break
|
||||||
|
elif [[ "$line" = ID=* ]]; then
|
||||||
|
family="${line#ID=}"
|
||||||
|
# No break, only used as fallback in case ID_LIKE isn't found
|
||||||
fi
|
fi
|
||||||
done < "$OS_RELEASE"
|
done < "$OS_RELEASE"
|
||||||
fi
|
fi
|
||||||
echo "$family"
|
echo "${family//\"}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function process_global_args() {
|
function process_global_args() {
|
||||||
|
|
3
yadm.1
3
yadm.1
|
@ -511,7 +511,8 @@ or by inspecting the ID from
|
||||||
.BR distro_family , " f
|
.BR distro_family , " f
|
||||||
Valid if the value matches the distro family (ignoring case).
|
Valid if the value matches the distro family (ignoring case).
|
||||||
Distro family is calculated by inspecting the ID_LIKE line from
|
Distro family is calculated by inspecting the ID_LIKE line from
|
||||||
.BR "/etc/os-release" .
|
.B "/etc/os-release"
|
||||||
|
(or ID if no ID_LIKE line is found).
|
||||||
.TP
|
.TP
|
||||||
.BR os , " o
|
.BR os , " o
|
||||||
Valid if the value matches the OS.
|
Valid if the value matches the OS.
|
||||||
|
|
Loading…
Reference in a new issue