Skip to content

Commit

Permalink
Product Version Creation: Made sure template format is taken into acc…
Browse files Browse the repository at this point in the history
…ount
  • Loading branch information
Giacomo Margaria committed Jan 7, 2022
1 parent dc8945b commit cfb05b5
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
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

0 comments on commit cfb05b5

Please sign in to comment.