2018-07-11 08:50:42 -04:00
|
|
|
"""Unit tests: set_operating_system"""
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
2023-07-10 15:43:17 -04:00
|
|
|
"proc_value, expected_os",
|
|
|
|
[
|
|
|
|
("missing", "uname"),
|
|
|
|
("has microsoft inside", "WSL"), # case insensitive
|
|
|
|
("has Microsoft inside", "WSL"), # case insensitive
|
|
|
|
("another value", "uname"),
|
|
|
|
],
|
|
|
|
ids=[
|
|
|
|
"/proc/version missing",
|
|
|
|
"/proc/version includes ms",
|
|
|
|
"/proc/version excludes Ms",
|
|
|
|
"another value",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
def test_set_operating_system(runner, paths, tst_sys, proc_value, expected_os):
|
2018-07-11 08:50:42 -04:00
|
|
|
"""Run set_operating_system and test result"""
|
|
|
|
|
|
|
|
# Normally /proc/version (set in PROC_VERSION) is inspected to identify
|
|
|
|
# WSL. During testing, we will override that value.
|
2023-07-10 15:43:17 -04:00
|
|
|
proc_version = paths.root.join("proc_version")
|
|
|
|
if proc_value != "missing":
|
2018-07-11 08:50:42 -04:00
|
|
|
proc_version.write(proc_value)
|
|
|
|
script = f"""
|
|
|
|
YADM_TEST=1 source {paths.pgm}
|
|
|
|
PROC_VERSION={proc_version}
|
|
|
|
set_operating_system
|
|
|
|
echo $OPERATING_SYSTEM
|
|
|
|
"""
|
2023-07-10 15:43:17 -04:00
|
|
|
run = runner(command=["bash"], inp=script)
|
2018-07-11 08:50:42 -04:00
|
|
|
assert run.success
|
2023-07-10 15:43:17 -04:00
|
|
|
assert run.err == ""
|
|
|
|
if expected_os == "uname":
|
2018-07-11 08:50:42 -04:00
|
|
|
expected_os = tst_sys
|
|
|
|
assert run.out.rstrip() == expected_os
|