Skip to content

Commit

Permalink
Added better error when docker is not installed (#1191)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-astus committed Jun 12, 2024
1 parent 5e98392 commit ed61857
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
* Deploying function/procedure with `--replace` flag now copies all grants
* Fixed MFA caching
* Fixed `DeprerationWarning`/`SyntaxWarning` due to invalid escape sequences
* Improved error message in `snow spcs image-registry login` when docker is not installed.

# v2.4.0
## Backward incompatibility
Expand Down
2 changes: 2 additions & 0 deletions src/snowflake/cli/plugins/spcs/image_registry/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,5 @@ def docker_registry_login(self) -> str:
)
except subprocess.CalledProcessError as e:
raise ClickException(f"Login Failed: {e.stderr}".strip())
except FileNotFoundError:
raise ClickException("Docker is not installed.")
22 changes: 22 additions & 0 deletions tests/spcs/test_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,25 @@ def test_docker_registry_login_subprocess_error(
RegistryManager().docker_registry_login()

assert e.value.message == snapshot


@mock.patch(
"snowflake.cli.plugins.spcs.image_registry.manager.RegistryManager.get_token"
)
@mock.patch(
"snowflake.cli.plugins.spcs.image_registry.manager.RegistryManager.get_registry_url"
)
@mock.patch("snowflake.cli.plugins.spcs.image_registry.manager.subprocess.check_output")
def test_docker_registry_login_docker_not_installed_error(
mock_check_output, mock_get_url, mock_get_token
):
mock_get_token.return_value = {
"token": "ver:1-hint:abc",
"expires_in": 3600,
}

mock_check_output.side_effect = FileNotFoundError()
with pytest.raises(ClickException) as e:
RegistryManager().docker_registry_login()

assert e.value.message == "Docker is not installed."

0 comments on commit ed61857

Please sign in to comment.