Skip to content

Commit

Permalink
Added more tests (some failing)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-bdufour committed Jun 13, 2024
1 parent c591fd7 commit 166eae5
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 15 deletions.
2 changes: 1 addition & 1 deletion RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* Fixed `DeprerationWarning`/`SyntaxWarning` due to invalid escape sequences
* Improved error message in `snow spcs image-registry login` when docker is not installed.
* Improved detection of conflicts between artifact rules for native application projects
* Passing a directory to `snow app deploy` will now deploy any of its subfolders specified in the application's artifact rules
* Passing a directory to `snow app deploy` will now deploy any contained file or subfolder specified in the application's artifact rules


# v2.4.0
Expand Down
21 changes: 14 additions & 7 deletions src/snowflake/cli/plugins/nativeapp/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import logging
from pathlib import Path
from textwrap import dedent
from typing import List, Optional

import typer
Expand Down Expand Up @@ -269,18 +270,24 @@ def app_teardown(
def app_deploy(
prune: Optional[bool] = typer.Option(
default=None,
help=f"""Whether to delete specified files from the stage if they don't exist locally. If set, the command deletes files that exist in the stage, but not in the local filesystem. This option cannot be used when files are specified.""",
help=f"""Whether to delete specified files from the stage if they don't exist locally. If set, the command deletes files that exist in the stage, but not in the local filesystem. This option cannot be used when paths are specified.""",
),
recursive: Optional[bool] = typer.Option(
None,
"--recursive/--no-recursive",
"-r",
help=f"""Whether to traverse and deploy files from subdirectories. If set, the command deploys all files and subdirectories; otherwise, only files in the current directory are deployed.""",
),
files: Optional[List[Path]] = typer.Argument(
paths: Optional[List[Path]] = typer.Argument(
default=None,
show_default=False,
help=f"""Paths, relative to the the project root, of files you want to upload to a stage. The paths must match one of the artifacts src pattern entries in snowflake.yml. If unspecified, the command syncs all local changes to the stage.""",
help=dedent(
f"""
Paths, relative to the the project root, of files or directories you want to upload to a stage. If a file is
specified, it must match one of the artifacts src pattern entries in snowflake.yml. If a directory is
specified, it will be searched for subfolders or files to deploy based on artifacts src pattern entries. If
unspecified, the command syncs all local changes to the stage."""
).strip(),
),
validate: bool = ValidateOption,
**options,
Expand All @@ -289,8 +296,8 @@ def app_deploy(
Creates an application package in your Snowflake account and syncs the local changes to the stage without creating or updating the application.
Running this command with no arguments at all, as in `snow app deploy`, is a shorthand for `snow app deploy --prune --recursive`.
"""
has_files = files is not None and len(files) > 0
if prune is None and recursive is None and not has_files:
has_paths = paths is not None and len(paths) > 0
if prune is None and recursive is None and not has_paths:
prune = True
recursive = True
else:
Expand All @@ -299,7 +306,7 @@ def app_deploy(
if recursive is None:
recursive = False

if has_files and prune:
if has_paths and prune:
raise ClickException("--prune cannot be used when paths are also specified")

manager = NativeAppManager(
Expand All @@ -312,7 +319,7 @@ def app_deploy(
bundle_map=bundle_map,
prune=prune,
recursive=recursive,
local_paths_to_sync=files,
local_paths_to_sync=paths,
validate=validate,
)

Expand Down
17 changes: 10 additions & 7 deletions tests/__snapshots__/test_help_messages.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,22 @@
# name: test_help_messages[app.deploy]
'''

Usage: default app deploy [OPTIONS] [FILES]...
Usage: default app deploy [OPTIONS] [PATHS]...

Creates an application package in your Snowflake account and syncs the local
changes to the stage without creating or updating the application. Running
this command with no arguments at all, as in `snow app deploy`, is a shorthand
for `snow app deploy --prune --recursive`.

╭─ Arguments ──────────────────────────────────────────────────────────────────╮
│ files [FILES]... Paths, relative to the the project root, of files │
│ you want to upload to a stage. The paths must match │
│ one of the artifacts src pattern entries in │
│ snowflake.yml. If unspecified, the command syncs │
│ all local changes to the stage. │
│ paths [PATHS]... Paths, relative to the the project root, of files │
│ or directories you want to upload to a stage. If a │
│ file is specified, it must match one of the │
│ artifacts src pattern entries in snowflake.yml. If │
│ a directory is specified, it will be searched for │
│ subfolders or files to deploy based on artifacts │
│ src pattern entries. If unspecified, the command │
│ syncs all local changes to the stage. │
╰──────────────────────────────────────────────────────────────────────────────╯
╭─ Options ────────────────────────────────────────────────────────────────────╮
│ --prune --no-prune Whether to delete specified files │
Expand All @@ -88,7 +91,7 @@
│ deletes files that exist in the │
│ stage, but not in the local │
│ filesystem. This option cannot be │
│ used when files are specified. │
│ used when paths are specified. │
│ [default: no-prune] │
│ --recursive -r --no-recursive Whether to traverse and deploy │
│ files from subdirectories. If set, │
Expand Down
52 changes: 52 additions & 0 deletions tests_integration/nativeapp/test_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,10 +499,17 @@ def test_nativeapp_deploy_looks_for_prefix_matches(
snowflake_yml.read_text(), yaml.BaseLoader
)
project_definition_file["native_app"]["artifacts"].append("src")
project_definition_file["native_app"]["artifacts"].append(
"lib/parent/child"
)
snowflake_yml.write_text(yaml.dump(project_definition_file))

touch(str(project_dir / "src/main.py"))

touch(str(project_dir / "lib/parent/child/a.py"))
touch(str(project_dir / "lib/parent/child/b.py"))
touch(str(project_dir / "lib/parent/child/c/c.py"))

result = runner.invoke_with_connection_json(
["app", "deploy", "-r", "app"],
env=TEST_ENV,
Expand All @@ -522,6 +529,51 @@ def test_nativeapp_deploy_looks_for_prefix_matches(
assert contains_row_with(stage_files.json, {"name": "stage/README.md"})
assert not_contains_row_with(stage_files.json, {"name": "src/main.py"})

result = runner.invoke_with_connection_json(
["app", "deploy", "-r", "lib/parent/child/c"],
env=TEST_ENV,
)
assert result.exit_code == 0
assert contains_row_with(
stage_files.json, {"name": "lib/parent/child/c/c.py"}
)
assert not_contains_row_with(
stage_files.json, {"name": "lib/parent/child/a.py"}
)
assert not_contains_row_with(
stage_files.json, {"name": "lib/parent/child/b.py"}
)

result = runner.invoke_with_connection_json(
["app", "deploy", "lib/parent/child/a.py"],
env=TEST_ENV,
)
assert result.exit_code == 0
assert contains_row_with(
stage_files.json, {"name": "lib/parent/child/c/c.py"}
)
assert contains_row_with(
stage_files.json, {"name": "lib/parent/child/a.py"}
)
assert not_contains_row_with(
stage_files.json, {"name": "lib/parent/child/b.py"}
)

result = runner.invoke_with_connection_json(
["app", "deploy", "lib", "-r"],
env=TEST_ENV,
)
assert result.exit_code == 0
assert contains_row_with(
stage_files.json, {"name": "lib/parent/child/c/c.py"}
)
assert contains_row_with(
stage_files.json, {"name": "lib/parent/child/a.py"}
)
assert contains_row_with(
stage_files.json, {"name": "lib/parent/child/b.py"}
)

finally:
result = runner.invoke_with_connection_json(
["app", "teardown", "--force"],
Expand Down

0 comments on commit 166eae5

Please sign in to comment.