Skip to content

Commit

Permalink
add duplicate test for sync
Browse files Browse the repository at this point in the history
  • Loading branch information
jonife committed Dec 4, 2024
1 parent d9fdc5b commit 9c30c76
Showing 1 changed file with 181 additions and 0 deletions.
181 changes: 181 additions & 0 deletions tests/unit/commands/samconfig/test_samconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -1294,6 +1294,187 @@ def test_sync_with_no_use_container(
{"HelloWorld": ["file.txt", "other.txt"], "HelloMars": ["single.file"]},
)

@patch("samcli.commands._utils.experimental.is_experimental_enabled")
@patch("samcli.lib.cli_validation.image_repository_validation._is_all_image_funcs_provided")
@patch("samcli.lib.cli_validation.image_repository_validation.get_template_artifacts_format")
@patch("samcli.commands._utils.template.get_template_artifacts_format")
@patch("samcli.commands._utils.options.get_template_artifacts_format")
@patch("samcli.commands.sync.command.do_cli")
def test_sync_with_no_use_container_options(
self,
do_cli_mock,
template_artifacts_mock1,
template_artifacts_mock2,
template_artifacts_mock3,
is_all_image_funcs_provided_mock,
experimental_mock,
):
template_artifacts_mock1.return_value = [ZIP]
template_artifacts_mock2.return_value = [ZIP]
template_artifacts_mock3.return_value = [ZIP]
is_all_image_funcs_provided_mock.return_value = True
experimental_mock.return_value = True

config_values = {
"template_file": "mytemplate.yaml",
"stack_name": "mystack",
"image_repository": "123456789012.dkr.ecr.us-east-1.amazonaws.com/test1",
"base_dir": "path",
"s3_bucket": "mybucket",
"s3_prefix": "myprefix",
"kms_key_id": "mykms",
"parameter_overrides": 'Key1=Value1 Key2="Multiple spaces in the value"',
"capabilities": "cap1 cap2",
"no_execute_changeset": True,
"role_arn": "arn",
"notification_arns": "notify1 notify2",
"tags": 'a=tag1 b="tag with spaces"',
"metadata": '{"m1": "value1", "m2": "value2"}',
"container_env_var_file": "file",
"guided": True,
"confirm_changeset": True,
"region": "myregion",
"signing_profiles": "function=profile:owner",
"watch_exclude": {"HelloWorld": ["file.txt", "other.txt"], "HelloMars": ["single.file"]},
}

with samconfig_parameters(["sync"], self.scratch_dir, **config_values) as config_path:
from samcli.commands.sync.command import cli

LOG.debug(Path(config_path).read_text())
runner = CliRunner()
result = runner.invoke(cli, ["--no-use-container"])

LOG.info(result.output)
LOG.info(result.exception)
if result.exception:
LOG.exception("Command failed", exc_info=result.exc_info)
self.assertIsNone(result.exception)

do_cli_mock.assert_called_with(
str(Path(os.getcwd(), "mytemplate.yaml")),
False,
False,
(),
(),
True,
True,
"mystack",
"myregion",
None,
"path",
{"Key1": "Value1", "Key2": "Multiple spaces in the value"},
None,
"123456789012.dkr.ecr.us-east-1.amazonaws.com/test1",
None,
"mybucket",
"myprefix",
"mykms",
["cap1", "cap2"],
"arn",
["notify1", "notify2"],
{"a": "tag1", "b": "tag with spaces"},
{"m1": "value1", "m2": "value2"},
False,
"file",
(),
"samconfig.toml",
"default",
False,
{"HelloWorld": ["file.txt", "other.txt"], "HelloMars": ["single.file"]},
)

@patch("samcli.commands._utils.experimental.is_experimental_enabled")
@patch("samcli.lib.cli_validation.image_repository_validation._is_all_image_funcs_provided")
@patch("samcli.lib.cli_validation.image_repository_validation.get_template_artifacts_format")
@patch("samcli.commands._utils.template.get_template_artifacts_format")
@patch("samcli.commands._utils.options.get_template_artifacts_format")
@patch("samcli.commands.sync.command.do_cli")
def test_sync_with_no_use_container_override(
self,
do_cli_mock,
template_artifacts_mock1,
template_artifacts_mock2,
template_artifacts_mock3,
is_all_image_funcs_provided_mock,
experimental_mock,
):
template_artifacts_mock1.return_value = [ZIP]
template_artifacts_mock2.return_value = [ZIP]
template_artifacts_mock3.return_value = [ZIP]
is_all_image_funcs_provided_mock.return_value = True
experimental_mock.return_value = True

config_values = {
"template_file": "mytemplate.yaml",
"stack_name": "mystack",
"image_repository": "123456789012.dkr.ecr.us-east-1.amazonaws.com/test1",
"base_dir": "path",
"use_container": True,
"s3_bucket": "mybucket",
"s3_prefix": "myprefix",
"kms_key_id": "mykms",
"parameter_overrides": 'Key1=Value1 Key2="Multiple spaces in the value"',
"capabilities": "cap1 cap2",
"no_execute_changeset": True,
"role_arn": "arn",
"notification_arns": "notify1 notify2",
"tags": 'a=tag1 b="tag with spaces"',
"metadata": '{"m1": "value1", "m2": "value2"}',
"container_env_var_file": "file",
"guided": True,
"confirm_changeset": True,
"region": "myregion",
"signing_profiles": "function=profile:owner",
"watch_exclude": {"HelloWorld": ["file.txt", "other.txt"], "HelloMars": ["single.file"]},
}

with samconfig_parameters(["sync"], self.scratch_dir, **config_values) as config_path:
from samcli.commands.sync.command import cli

LOG.debug(Path(config_path).read_text())
runner = CliRunner()
result = runner.invoke(cli, ["--no-use-container"])

LOG.info(result.output)
LOG.info(result.exception)
if result.exception:
LOG.exception("Command failed", exc_info=result.exc_info)
self.assertIsNone(result.exception)

do_cli_mock.assert_called_with(
str(Path(os.getcwd(), "mytemplate.yaml")),
False,
False,
(),
(),
True,
True,
"mystack",
"myregion",
None,
"path",
{"Key1": "Value1", "Key2": "Multiple spaces in the value"},
None,
"123456789012.dkr.ecr.us-east-1.amazonaws.com/test1",
None,
"mybucket",
"myprefix",
"mykms",
["cap1", "cap2"],
"arn",
["notify1", "notify2"],
{"a": "tag1", "b": "tag with spaces"},
{"m1": "value1", "m2": "value2"},
False,
"file",
(),
"samconfig.toml",
"default",
False,
{"HelloWorld": ["file.txt", "other.txt"], "HelloMars": ["single.file"]},
)


class TestSamConfigWithOverrides(TestCase):
def setUp(self):
Expand Down

0 comments on commit 9c30c76

Please sign in to comment.