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

Fix: Product Version Creation: Made sure template format is taken into account #238

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion servicecatalog_factory/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
build:
commands:
{% for region in ALL_REGIONS %}
- aws cloudformation package --region {{ region }} --template $(pwd)/product.template.yaml --s3-bucket sc-factory-artifacts-${ACCOUNT_ID}-{{ region }} --s3-prefix ${STACK_NAME} --output-template-file product.template-{{ region }}.yaml
- aws cloudformation package --region {{ region }} --template $(pwd)/product.template.{{ template_format }} --s3-bucket sc-factory-artifacts-${ACCOUNT_ID}-{{ region }} --s3-prefix ${STACK_NAME} --output-template-file product.template-{{ region }}.{{ template_format }}

{% endfor %}
artifacts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ def handle_cloudformation_provisioner(
friendly_uid=f"{friendly_uid}-{self.version.get('Name')}",
version=self.version,
product=self.product,
template_format=self.provisioner.get("Format", "yaml"),
Options=utils.merge(
self.product.get("Options", {}), self.version.get("Options", {})
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
# Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

from unittest import skip
from unittest import mock, skip
from servicecatalog_factory.workflow import tasks_unit_tests_helper

import os

class CreateVersionPipelineTemplateTaskTest(
tasks_unit_tests_helper.FactoryTaskUnitTest
):
all_regions = []
version = {}
all_regions = ["region"]
version = {}
product = {}
provisioner = {}
provisioner = {"Type": "Cloudformation"}
template = {}
factory_version = "factory_version"
products_args_by_region = {}
Expand Down Expand Up @@ -51,6 +53,25 @@ def test_params_for_results_display(self):
# verify
self.assertEqual(expected_result, actual_result)


@mock.patch.dict(os.environ, {"ACCOUNT_ID": "account_id", "REGION": "region"}, clear=True)
def test_handle_cloudformation_provisioner_format(self):
for provisioner_format in [None, "json", "yaml"]:
# setup
self.sut.provisioner = {"Type": "Cloudformation", "Format": provisioner_format}

# exercise
rendered = self.sut.handle_cloudformation_provisioner(
product_ids_by_region={},
friendly_uid="",
tags=[],
source={"Provider": "codecommit", "Configuration": { "PollForSourceChanges": "False"} }
)

# verify
self.assertIn(f"product.template.{provisioner_format}", rendered)
self.assertNotIn(f"product.template.{'yaml' if provisioner_format == 'json' else 'json'}", rendered)

@skip
def test_requires(self):
# setup
Expand Down
1 change: 1 addition & 0 deletions servicecatalog_factory/workflow/tasks_unit_tests_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def wire_up_mocks(self):

self.hub_client_mock, self.sut.hub_client = mocked_client()
self.hub_regional_client_mock, self.sut.hub_regional_client = mocked_client()
self.sut.client = mock.MagicMock()

self.sut.write_output = mock.MagicMock()
self.sut.input = mock.MagicMock()
Expand Down