-
Notifications
You must be signed in to change notification settings - Fork 3.3k
{ARM} Fix race condition in bicep unit tests #26797
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |||||
| import os | ||||||
| import contextlib | ||||||
| import unittest | ||||||
| import semver | ||||||
| from unittest import mock | ||||||
|
|
||||||
| from knack.util import CLIError | ||||||
|
|
@@ -19,20 +20,21 @@ | |||||
| from azure.cli.core.azclierror import InvalidTemplateError | ||||||
| from azure.cli.core.mock import DummyCli | ||||||
|
|
||||||
| cli_ctx = DummyCli() | ||||||
|
|
||||||
|
|
||||||
| class TestBicep(unittest.TestCase): | ||||||
| def setUp(self): | ||||||
| self.cli_ctx = DummyCli(random_config_dir=True) | ||||||
|
Comment on lines
+25
to
+26
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This contradicts the convention used in #25689 that azure-cli/src/azure-cli/azure/cli/command_modules/config/tests/latest/test_config.py Lines 16 to 17 in b223dd9
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Its superclass is |
||||||
|
|
||||||
| @mock.patch("os.path.isfile") | ||||||
| def test_run_bicep_command_raise_error_if_not_installed_and_not_auto_install(self, isfile_stub): | ||||||
| isfile_stub.return_value = False | ||||||
|
|
||||||
| with contextlib.suppress(FileNotFoundError): | ||||||
| remove_bicep_installation(cli_ctx) | ||||||
| remove_bicep_installation(self.cli_ctx) | ||||||
|
|
||||||
| cli_ctx.config.set_value("bicep", "use_binary_from_path", "false") | ||||||
| self.cli_ctx.config.set_value("bicep", "use_binary_from_path", "false") | ||||||
| with self.assertRaisesRegex(CLIError, 'Bicep CLI not found. Install it now by running "az bicep install".'): | ||||||
| run_bicep_command(cli_ctx, ["--version"], auto_install=False) | ||||||
| run_bicep_command(self.cli_ctx, ["--version"], auto_install=False) | ||||||
|
|
||||||
| @mock.patch("os.chmod") | ||||||
| @mock.patch("os.stat") | ||||||
|
|
@@ -59,22 +61,22 @@ def test_use_bicep_cli_from_path_false_after_install(self, isfile_stub, dirname_ | |||||
| response.read.return_value = b"test" | ||||||
| urlopen_stub.return_value = response | ||||||
|
|
||||||
| ensure_bicep_installation(cli_ctx, release_tag="v0.14.85", stdout=False) | ||||||
| ensure_bicep_installation(self.cli_ctx, release_tag="v0.14.85", stdout=False) | ||||||
|
|
||||||
| self.assertTrue(cli_ctx.config.get("bicep", "use_binary_from_path") == "false") | ||||||
| self.assertTrue(self.cli_ctx.config.get("bicep", "use_binary_from_path") == "false") | ||||||
|
|
||||||
| @mock.patch("shutil.which") | ||||||
| def test_run_bicep_command_raise_error_if_bicep_cli_not_found_when_use_binary_from_path_is_true(self, which_stub): | ||||||
| which_stub.return_value = None | ||||||
| cli_ctx.config.set_value("bicep", "use_binary_from_path", "true") | ||||||
| self.cli_ctx.config.set_value("bicep", "use_binary_from_path", "true") | ||||||
|
|
||||||
| with self.assertRaisesRegex( | ||||||
| CLIError, | ||||||
| 'Could not find the "bicep" executable on PATH. To install Bicep via Azure CLI, set the "bicep.use_binary_from_path" configuration to False and run "az bicep install".', | ||||||
| ): | ||||||
| run_bicep_command(cli_ctx, ["--version"], auto_install=False) | ||||||
| run_bicep_command(self.cli_ctx, ["--version"], auto_install=False) | ||||||
|
|
||||||
| cli_ctx.config.set_value("bicep", "use_binary_from_path", "false") | ||||||
| self.cli_ctx.config.set_value("bicep", "use_binary_from_path", "false") | ||||||
|
|
||||||
| @mock.patch.dict(os.environ, {"GITHUB_ACTIONS": "true"}, clear=True) | ||||||
| @mock.patch("azure.cli.command_modules.resource._bicep._logger.debug") | ||||||
|
|
@@ -83,9 +85,9 @@ def test_run_bicep_command_raise_error_if_bicep_cli_not_found_when_use_binary_fr | |||||
| def test_run_bicep_command_use_bicep_cli_from_path_in_ci(self, which_stub, run_command_stub, debug_mock): | ||||||
| which_stub.return_value = True | ||||||
| run_command_stub.return_value = "Bicep CLI version 0.13.1 (e3ac80d678)" | ||||||
| cli_ctx.config.set_value("bicep", "use_binary_from_path", "if_found_in_ci") | ||||||
| self.cli_ctx.config.set_value("bicep", "use_binary_from_path", "if_found_in_ci") | ||||||
|
|
||||||
| run_bicep_command(cli_ctx, ["--version"], auto_install=False) | ||||||
| run_bicep_command(self.cli_ctx, ["--version"], auto_install=False) | ||||||
|
|
||||||
| debug_mock.assert_called_with( | ||||||
| "Using Bicep CLI from PATH. %s", | ||||||
|
|
@@ -108,12 +110,12 @@ def test_run_bicep_command_check_version( | |||||
| warning_mock, | ||||||
| ): | ||||||
| isfile_stub.return_value = True | ||||||
| _get_bicep_installed_version_stub.return_value = "1.0.0" | ||||||
| _get_bicep_installed_version_stub.return_value = semver.VersionInfo.parse("1.0.0") | ||||||
| get_bicep_latest_release_tag_stub.return_value = "v2.0.0" | ||||||
|
|
||||||
| cli_ctx.config.set_value("bicep", "check_version", "True") | ||||||
| cli_ctx.config.set_value("bicep", "use_binary_from_path", "false") | ||||||
| run_bicep_command(cli_ctx, ["--version"]) | ||||||
| self.cli_ctx.config.set_value("bicep", "check_version", "True") | ||||||
| self.cli_ctx.config.set_value("bicep", "use_binary_from_path", "false") | ||||||
| run_bicep_command(self.cli_ctx, ["--version"]) | ||||||
|
|
||||||
| warning_mock.assert_called_once_with( | ||||||
| 'A new Bicep release is available: %s. Upgrade now by running "az bicep upgrade".', | ||||||
|
|
@@ -139,10 +141,10 @@ def test_run_bicep_command_check_version_cache_read_write( | |||||
| self._remove_bicep_version_check_file() | ||||||
|
|
||||||
| isfile_stub.return_value = True | ||||||
| _get_bicep_installed_version_stub.return_value = "1.0.0" | ||||||
| _get_bicep_installed_version_stub.return_value = semver.VersionInfo.parse("1.0.0") | ||||||
| get_bicep_latest_release_tag_stub.return_value = "v2.0.0" | ||||||
|
|
||||||
| run_bicep_command(cli_ctx, ["--version"]) | ||||||
| run_bicep_command(self.cli_ctx, ["--version"]) | ||||||
|
|
||||||
| self.assertTrue(os.path.isfile(_bicep_version_check_file_path)) | ||||||
| finally: | ||||||
|
|
@@ -154,10 +156,10 @@ def test_run_bicep_command_check_version_cache_read_write( | |||||
| def test_ensure_bicep_installation_skip_download_if_installed_version_matches_release_tag( | ||||||
| self, dirname_mock, _get_bicep_installed_version_stub, isfile_stub | ||||||
| ): | ||||||
| _get_bicep_installed_version_stub.return_value = "0.1.0" | ||||||
| _get_bicep_installed_version_stub.return_value = semver.VersionInfo.parse("0.1.0") | ||||||
| isfile_stub.return_value = True | ||||||
|
|
||||||
| ensure_bicep_installation(cli_ctx, release_tag="v0.1.0") | ||||||
| ensure_bicep_installation(self.cli_ctx, release_tag="v0.1.0") | ||||||
|
|
||||||
| dirname_mock.assert_not_called() | ||||||
|
|
||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
semveris indeed required, we should consider reviving #26523.