Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate default template.json #2855

Merged
merged 8 commits into from May 13, 2021
19 changes: 13 additions & 6 deletions tests/integration/validate/test_validate_command.py
Expand Up @@ -8,16 +8,22 @@
from pathlib import Path
from typing import List, Optional
from unittest import TestCase
from unittest.case import skipIf

from parameterized import parameterized
from tests.testing_utils import run_command
from tests.testing_utils import RUN_BY_CANARY, RUNNING_ON_CI, RUNNING_TEST_FOR_MASTER_ON_CI, run_command

# Validate tests require credentials and CI/CD will only add credentials to the env if the PR is from the same repo.
# This is to restrict package tests to run outside of CI/CD, when the branch is not master or tests are not run by Canary
SKIP_VALIDATE_TESTS = RUNNING_ON_CI and RUNNING_TEST_FOR_MASTER_ON_CI and not RUN_BY_CANARY


class TemplateFileTypes(Enum):
JSON = auto()
YAML = auto()


@skipIf(SKIP_VALIDATE_TESTS, "Skip deploy tests in CI/CD only")
ssenchenko marked this conversation as resolved.
Show resolved Hide resolved
class TestValidate(TestCase):
@classmethod
def setUpClass(cls):
Expand Down Expand Up @@ -45,7 +51,7 @@ def command_list(
if region:
command_list += ["--region", region]
if config_file:
command_list = ["--config_file", str(config_file)]
command_list += ["--config_file", str(config_file)]
return command_list

@parameterized.expand(
Expand All @@ -59,10 +65,11 @@ def command_list(
), # project with template.json and standard build directory .aws-sam/build/template.yaml
]
)
def test_default_template(self, relative_folder: str, expected_file: TemplateFileTypes):
cwd = f"tests/integration/testdata/validate/{relative_folder}"
command_result = run_command(self.command_list(), cwd=cwd)
def test_default_template_file_choice(self, relative_folder: str, expected_file: TemplateFileTypes):
test_data_path = Path(__file__).resolve().parents[2] / "integration" / "testdata" / "validate"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know / operator can be used in Path, wow!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, it's nice to have operator overloading 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the "/" similar to using pathlib.join ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I tested, it is

process_dir = test_data_path / relative_folder
command_result = run_command(self.command_list(), cwd=str(process_dir))
pattern = self.patterns[expected_file] # type: ignore
output = command_result.stdout.decode("utf-8")
self.assertEqual(command_result.process.returncode, 0)
self.assertIsNotNone(pattern.match(output))
self.assertRegex(output, pattern)