generated from canonical/template-operator
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e529ef3
commit e03fc8c
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright 2024 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
|
||
from unittest.mock import patch | ||
|
||
from architecture import is_wrong_architecture | ||
|
||
TEST_MANIFEST = """ | ||
bases: | ||
- architectures: | ||
- {arch} | ||
channel: '22.04' | ||
name: ubuntu | ||
""" | ||
|
||
|
||
def test_wrong_architecture_file_not_found(): | ||
"""Tests if the function returns False when the charm file doesn't exist.""" | ||
with ( | ||
patch("os.environ", return_value={"CHARM_DIR": "/tmp"}), | ||
patch("pathlib.Path.exists", return_value=False), | ||
): | ||
assert not is_wrong_architecture() | ||
|
||
|
||
def test_wrong_architecture_amd64(): | ||
"""Tests if the function correctly identifies arch when charm is AMD.""" | ||
with ( | ||
patch("os.environ", return_value={"CHARM_DIR": "/tmp"}), | ||
patch("pathlib.Path.exists", return_value=True), | ||
patch("pathlib.Path.read_text", return_value=TEST_MANIFEST.format(arch="amd64")), | ||
patch("platform.machine") as machine, | ||
): | ||
machine.return_value = "x86_64" | ||
assert not is_wrong_architecture() | ||
machine.return_value = "aarch64" | ||
assert is_wrong_architecture() | ||
|
||
|
||
def test_wrong_architecture_arm64(): | ||
"""Tests if the function correctly identifies arch when charm is ARM.""" | ||
with ( | ||
patch("os.environ", return_value={"CHARM_DIR": "/tmp"}), | ||
patch("pathlib.Path.exists", return_value=True), | ||
patch("pathlib.Path.read_text", return_value=TEST_MANIFEST.format(arch="arm64")), | ||
patch("platform.machine") as machine, | ||
): | ||
machine.return_value = "x86_64" | ||
assert is_wrong_architecture() | ||
machine.return_value = "aarch64" | ||
assert not is_wrong_architecture() |