Skip to content

Commit

Permalink
Correctly handle read-only files when cleaning up in `snow app list-t…
Browse files Browse the repository at this point in the history
…emplates` (#1138)
  • Loading branch information
sfc-gh-bdufour authored May 29, 2024
1 parent 47f733a commit 7a9d15f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 31 deletions.
6 changes: 6 additions & 0 deletions src/snowflake/cli/plugins/nativeapp/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ def app_list_templates(**options) -> CommandResult:
Prints information regarding the official templates that can be used with snow app init.
"""
with SecurePath.temporary_directory() as temp_path:
from git import rmtree as git_rmtree

repo = shallow_git_clone(OFFICIAL_TEMPLATES_GITHUB_URL, temp_path.path)

# Mark a directory as a template if a project definition jinja template is inside
Expand All @@ -113,6 +115,10 @@ def app_list_templates(**options) -> CommandResult:
)
)

# proactively clean up here to avoid permission issues on Windows
repo.close()
git_rmtree(temp_path.path)

return CollectionResult(result)


Expand Down
26 changes: 0 additions & 26 deletions tests_integration/nativeapp/__snapshots__/test_templates.ambr

This file was deleted.

16 changes: 11 additions & 5 deletions tests_integration/nativeapp/test_templates.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import pytest
from snowflake.connector.compat import IS_WINDOWS


@pytest.mark.integration
@pytest.mark.skipif(IS_WINDOWS, reason="Permissions issue on Windows")
def test_list_templates_no_options_success(runner, snapshot):
def test_list_templates_no_options_success(runner):
args = ["app", "list-templates"]
result = runner.invoke(args)
result = runner.invoke_json(args)

assert result.exit_code == 0
assert result.output == snapshot
templates = result.json
assert len(templates) > 0

# Check that the basic templates are present, but explicitly avoid checking for an
# exact list so that adding new templates won't break the tests.
all_template_names = [t["template"] for t in templates]
assert "basic" in all_template_names
assert "streamlit-java" in all_template_names
assert "streamlit-python" in all_template_names

0 comments on commit 7a9d15f

Please sign in to comment.