Skip to content

Commit

Permalink
Add integration test to check for backslashes on Windows (#1595)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-melnacouzi committed Sep 18, 2024
1 parent 55ffab6 commit 3614294
Showing 1 changed file with 116 additions and 34 deletions.
150 changes: 116 additions & 34 deletions tests_integration/nativeapp/test_post_deploy.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Tests that application post-deploy scripts are executed by creating a post_deploy_log table and having each post-deploy script add a record to it

from pathlib import Path
import pytest
import yaml

from tests_common import IS_WINDOWS
from tests_integration.test_utils import (
row_from_snowflake_session,
)
Expand Down Expand Up @@ -108,16 +111,14 @@ def test_nativeapp_post_deploy(
create_version(runner, version, project_args)
run(runner, base_command, project_args + version_run_args)

# TODO Remove condition once ApplicationEntity deploy is implemented
if base_command == "app":
verify_app_post_deploy_log(
snowflake_session,
app_name,
[
{"TEXT": "app-post-deploy-part-1"},
{"TEXT": "app-post-deploy-part-2"},
],
)
verify_app_post_deploy_log(
snowflake_session,
app_name,
[
{"TEXT": "app-post-deploy-part-1"},
{"TEXT": "app-post-deploy-part-2"},
],
)

verify_pkg_post_deploy_log(
snowflake_session,
Expand All @@ -133,18 +134,16 @@ def test_nativeapp_post_deploy(
create_version(runner, version, project_args)
run(runner, base_command, project_args + version_run_args)

# TODO Remove condition once ApplicationEntity deploy is implemented
if base_command == "app":
verify_app_post_deploy_log(
snowflake_session,
app_name,
[
{"TEXT": "app-post-deploy-part-1"},
{"TEXT": "app-post-deploy-part-2"},
{"TEXT": "app-post-deploy-part-1"},
{"TEXT": "app-post-deploy-part-2"},
],
)
verify_app_post_deploy_log(
snowflake_session,
app_name,
[
{"TEXT": "app-post-deploy-part-1"},
{"TEXT": "app-post-deploy-part-2"},
{"TEXT": "app-post-deploy-part-1"},
{"TEXT": "app-post-deploy-part-2"},
],
)
verify_pkg_post_deploy_log(
snowflake_session,
pkg_name,
Expand All @@ -158,18 +157,16 @@ def test_nativeapp_post_deploy(

deploy(runner, base_command, project_args)

# TODO Remove condition once ApplicationEntity deploy is implemented
if base_command == "app":
verify_app_post_deploy_log(
snowflake_session,
app_name,
[
{"TEXT": "app-post-deploy-part-1"},
{"TEXT": "app-post-deploy-part-2"},
{"TEXT": "app-post-deploy-part-1"},
{"TEXT": "app-post-deploy-part-2"},
],
)
verify_app_post_deploy_log(
snowflake_session,
app_name,
[
{"TEXT": "app-post-deploy-part-1"},
{"TEXT": "app-post-deploy-part-2"},
{"TEXT": "app-post-deploy-part-1"},
{"TEXT": "app-post-deploy-part-2"},
],
)
verify_pkg_post_deploy_log(
snowflake_session,
pkg_name,
Expand All @@ -188,3 +185,88 @@ def test_nativeapp_post_deploy(
# need to drop the version before we can teardown
drop_version(runner, version, project_args)
teardown(runner, project_args)


@pytest.mark.integration
@pytest.mark.skipif(
not IS_WINDOWS, reason="Testing windows path should only be done on Windows"
)
@pytest.mark.parametrize(
"base_command,test_project",
[
["app", "napp_application_post_deploy_v1"],
["app", "napp_application_post_deploy_v2"],
["ws", "napp_application_post_deploy_v2"],
],
)
def test_nativeapp_post_deploy_with_windows_path(
runner,
snowflake_session,
default_username,
resource_suffix,
nativeapp_project_directory,
base_command,
test_project,
):
project_name = "myapp"
app_name = f"{project_name}_{default_username}{resource_suffix}"
pkg_name = f"{project_name}_pkg_{default_username}{resource_suffix}"

with nativeapp_project_directory(test_project) as tmp_dir:
try:
snowflake_yml_path = tmp_dir / "snowflake.yml"
with open(snowflake_yml_path, "r", encoding="utf-8") as file:
yml = yaml.safe_load(file)
if yml["definition_version"] >= 2:
artifact = yml["entities"]["pkg"]["artifacts"][0]
pkg_scripts = yml["entities"]["pkg"]["meta"]["post_deploy"]
app_scripts = yml["entities"]["app"]["meta"]["post_deploy"]
else:
artifact = yml["native_app"]["artifacts"][0]
pkg_scripts = yml["native_app"]["package"]["post_deploy"]
app_scripts = yml["native_app"]["application"]["post_deploy"]

# use backslashes in artifacts src
artifact["src"] = artifact["src"].replace("/", "\\")

# use backslashes in post_deploy paths, as well as full paths with backslashes
pkg_scripts[0]["sql_script"] = pkg_scripts[0]["sql_script"].replace(
"/", "\\"
)
pkg_scripts[1]["sql_script"] = str(
(tmp_dir / pkg_scripts[1]["sql_script"]).absolute()
)

# use backslashes in post_deploy paths, as well as full paths with backslashes
app_scripts[0]["sql_script"] = app_scripts[0]["sql_script"].replace(
"/", "\\"
)
app_scripts[1]["sql_script"] = str(
(tmp_dir / app_scripts[1]["sql_script"]).absolute()
)

with open(snowflake_yml_path, "w", encoding="utf-8") as file:
yaml.dump(yml, file)

run(runner, base_command, [])

verify_app_post_deploy_log(
snowflake_session,
app_name,
[
{"TEXT": "app-post-deploy-part-1"},
{"TEXT": "app-post-deploy-part-2"},
],
)

verify_pkg_post_deploy_log(
snowflake_session,
pkg_name,
[
{"TEXT": "package-post-deploy-part-1"},
{"TEXT": "package-post-deploy-part-2"},
],
)

finally:
teardown(runner, [])

0 comments on commit 3614294

Please sign in to comment.