Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/azure-cli/azure/cli/command_modules/acr/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
IdentityProperties,
UserIdentityProperties
)
from knack.log import get_logger

logger = get_logger(__name__)


def acr_cache_show(cmd,
Expand Down Expand Up @@ -66,6 +69,7 @@ def acr_cache_create(cmd,
identity=None):

rg = get_resource_group_name_by_registry_name(cmd.cli_ctx, registry_name, resource_group_name)
logger.warning("If cache rule '%s' already exists, it will be overwritten.", name)

# Handle credential set
if cred_set:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
)
from azure.cli.command_modules.acr._docker_utils import ResourceNotFound
from azure.cli.command_modules.acr._constants import ACR_AUDIENCE_RESOURCE_NAME
from azure.cli.command_modules.acr.cache import acr_cache_create
from azure.cli.core.mock import DummyCli


Expand All @@ -64,6 +65,26 @@

class AcrMockCommandsTests(unittest.TestCase):

@mock.patch('azure.cli.command_modules.acr.cache.logger.warning')
@mock.patch('azure.cli.command_modules.acr.cache.get_resource_group_name_by_registry_name')
def test_cache_create_warns_that_existing_rule_is_overwritten(
self, mock_get_resource_group, mock_warning):
cmd = self._setup_cmd()
client = mock.MagicMock()
mock_get_resource_group.return_value = 'testresourcegroup'

acr_cache_create(
cmd=cmd,
client=client,
registry_name='testregistry',
name='testcache',
source_repo='mcr.microsoft.com/mcr/hello-world',
target_repo='hello-world')

mock_warning.assert_called_once_with(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we testing both outcomes, ie. if the rule already exists and if it doesn't exist? How does the test guarantee that the rule exists?

"If cache rule '%s' already exists, it will be overwritten.",
'testcache')

@mock.patch('azure.cli.command_modules.acr.repository.get_access_credentials', autospec=True)
@mock.patch('requests.request', autospec=True)
def test_repository_list(self, mock_requests_get, mock_get_access_credentials):
Expand Down
Loading