ensure we unset ONEDIR env for unit/functional tests

This commit is contained in:
Megan Wilhite 2023-06-14 11:38:52 -06:00 committed by Pedro Algarvio
parent e01ceb5284
commit dc07caab95
6 changed files with 64 additions and 5 deletions

View file

@ -1,4 +1,5 @@
import logging
import os
import shutil
import pytest
@ -7,6 +8,21 @@ from saltfactories.utils.functional import Loaders
log = logging.getLogger(__name__)
@pytest.fixture(scope="package", autouse=True)
def onedir_env():
"""
Functional tests cannot currently test the
onedir artifact. This will need to be removed
when we do add onedir support for functional tests.
"""
if os.environ.get("ONEDIR_TESTRUN", "0") == "1":
try:
os.environ["ONEDIR_TESTRUN"] = "0"
yield
finally:
os.environ["ONEDIR_TESTRUN"] = "1"
@pytest.fixture(scope="package")
def minion_id():
return "func-tests-minion-opts"
@ -127,7 +143,7 @@ def master_opts(
@pytest.fixture(scope="module")
def loaders(minion_opts):
return Loaders(minion_opts, loaded_base_name="{}.loaded".format(__name__))
return Loaders(minion_opts, loaded_base_name=f"{__name__}.loaded")
@pytest.fixture(autouse=True)

View file

@ -0,0 +1,24 @@
"""
Grains include tests
"""
import os
def test_grains_package(salt_call_cli):
"""
An integration test for the package grain
is a bit overkill, but it is necessary currently
because the onedir package is only tested with
integration tests, so I want to ensure its working
correctly. Once the onedir package is tested with unit
and functional tests this test can be removed since
there is plenty of test coverage in both unit and functional
for this new grain.
"""
ret = salt_call_cli.run("grains.get", "package")
assert ret.returncode == 0
assert ret.data
if os.environ.get("ONEDIR_TESTRUN", "0") == "0":
assert ret.data == "pip"
else:
assert ret.data == "onedir"

View file

@ -1,8 +1,25 @@
import os
import pytest
import salt.config
@pytest.fixture(scope="package", autouse=True)
def onedir_env():
"""
Unit tests cannot currently test the
onedir artifact. This will need to be removed
when we do add onedir support for functional tests.
"""
if os.environ.get("ONEDIR_TESTRUN", "0") == "1":
try:
os.environ["ONEDIR_TESTRUN"] = "0"
yield
finally:
os.environ["ONEDIR_TESTRUN"] = "1"
@pytest.fixture
def minion_opts(tmp_path):
"""

View file

@ -3,7 +3,7 @@ import os
import salt.grains.package
def test_grain_package_type(tmp_path):
def test_grain_package_type():
"""
Test grains.package_type for both package types
"""

View file

@ -158,7 +158,9 @@ def test_version_report_lines():
line_lengths = {
len(line.split(":")[0])
for line in versions_report_ret[start_looking_index:]
if line != " " and line not in ("System Versions:", "Salt Extensions:")
if line != " "
and line
not in ("System Versions:", "Salt Extensions:", "Salt Package Information:")
}
# Check that they are all the same size (only one element in the set)
assert len(line_lengths) == 1

View file

@ -6,6 +6,6 @@ import salt.utils.package
def test_pkg_type():
ret = salt.utils.package.pkg_type()
if os.environ.get("ONEDIR_TESTRUN", "0") == "0":
assert ret == "onedir"
assert ret == "pip"
else:
assert ret == "system"
assert ret == "onedir"