Skip to content

Commit

Permalink
tests: add another test, mock platform
Browse files Browse the repository at this point in the history
Signed-off-by: Callahan Kovacs <callahan.kovacs@canonical.com>
  • Loading branch information
mr-cal committed Aug 15, 2023
1 parent 9add9ad commit d53501a
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/legacy/unit/pluginhandler/test_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,23 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import sys

import pytest

from snapcraft_legacy.internal.pluginhandler._part_environment import (
get_snapcraft_global_environment,
)
from snapcraft_legacy.project import Project
from tests.legacy.fixture_setup import SnapcraftYaml


@pytest.fixture(autouse=True)
def mock_platform(mocker):
mocker.patch.object(sys, "platform", "linux")
mocker.patch("platform.machine", return_value="aarch64")


def test_no_build_for_arch(tmp_path):
"""build-for envvars should exist when the build-for arch can be determined."""
snapcraft_yaml = SnapcraftYaml(
Expand All @@ -45,6 +55,30 @@ def test_no_build_for_arch(tmp_path):
)


def test_implicit_build_for_arch(tmp_path):
"""build-for envvars should exist for when the build-for arch is implicit."""
snapcraft_yaml = SnapcraftYaml(
tmp_path,
base="core20",
parts={"test-part": {"plugin": "nil"}},
architectures=[{"build-on": "arm64"}],
)
snapcraft_yaml.write_snapcraft_yaml()
project = Project(snapcraft_yaml_file_path=snapcraft_yaml.snapcraft_yaml_file_path)

environment = get_snapcraft_global_environment(project)

assert environment["SNAPCRAFT_ARCH_BUILD_ON"] == project.arch_build_on
assert (
environment["SNAPCRAFT_ARCH_TRIPLET_BUILD_ON"] == project.arch_triplet_build_on
)
assert environment["SNAPCRAFT_ARCH_BUILD_FOR"] == project.arch_build_for
assert (
environment["SNAPCRAFT_ARCH_TRIPLET_BUILD_FOR"]
== project.arch_triplet_build_for
)


def test_no_build_for_unknown_arch(tmp_path):
"""build-for envvars should not be defined for unknown build-for architectures."""
snapcraft_yaml = SnapcraftYaml(
Expand Down

0 comments on commit d53501a

Please sign in to comment.