From 999ce907f1eb8f44779ca0a2345aa03706fbf75f Mon Sep 17 00:00:00 2001 From: Daniel Mil <84205762+mildaniel@users.noreply.github.com> Date: Mon, 4 Mar 2024 09:59:09 -0800 Subject: [PATCH] fix: Rename provided go binary to bootstrap (#621) * fix: Rename provided go binary to bootstrap * Format files * Windows compliant tests --- .../workflows/go_modules/workflow.py | 7 ++++++- .../integration/workflows/go_modules/test_go.py | 17 +++++++++++++++++ .../unit/workflows/go_modules/test_workflow.py | 15 +++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/aws_lambda_builders/workflows/go_modules/workflow.py b/aws_lambda_builders/workflows/go_modules/workflow.py index 9e570937c..84a29a4d3 100644 --- a/aws_lambda_builders/workflows/go_modules/workflow.py +++ b/aws_lambda_builders/workflows/go_modules/workflow.py @@ -32,7 +32,12 @@ def __init__( handler = options.get("artifact_executable_name", None) trim_go_path = options.get("trim_go_path", False) - output_path = osutils.joinpath(artifacts_dir, handler) + # For provided runtimes, the binary must be named "bootstrap" + output_path = ( + osutils.joinpath(artifacts_dir, handler) + if runtime != "provided" + else osutils.joinpath(artifacts_dir, "bootstrap") + ) builder = GoModulesBuilder( osutils, diff --git a/tests/integration/workflows/go_modules/test_go.py b/tests/integration/workflows/go_modules/test_go.py index 3027cae24..53bac35d2 100644 --- a/tests/integration/workflows/go_modules/test_go.py +++ b/tests/integration/workflows/go_modules/test_go.py @@ -8,6 +8,8 @@ from pathlib2 import Path from unittest import TestCase +from parameterized import parameterized + from aws_lambda_builders.builder import LambdaBuilder from aws_lambda_builders.exceptions import WorkflowFailedError @@ -196,3 +198,18 @@ def test_builds_project_with_nested_dir(self): expected_files = {"helloWorld"} output_files = set(os.listdir(self.artifacts_dir)) self.assertEqual(expected_files, output_files) + + @parameterized.expand([("provided", "bootstrap"), ("go1.x", "helloWorld")]) + def test_binary_named_bootstrap_for_provided_runtime(self, runtime, expected_binary): + source_dir = os.path.join(self.TEST_DATA_FOLDER, "no-deps") + self.builder.build( + source_dir, + self.artifacts_dir, + self.scratch_dir, + os.path.join(source_dir, "go.mod"), + runtime=runtime, + options={"artifact_executable_name": "helloWorld"}, + ) + expected_files = {expected_binary} + output_files = set(os.listdir(self.artifacts_dir)) + self.assertEqual(expected_files, output_files) diff --git a/tests/unit/workflows/go_modules/test_workflow.py b/tests/unit/workflows/go_modules/test_workflow.py index 86e42e306..9efaf4a68 100644 --- a/tests/unit/workflows/go_modules/test_workflow.py +++ b/tests/unit/workflows/go_modules/test_workflow.py @@ -1,4 +1,5 @@ from unittest import TestCase +from pathlib import Path from aws_lambda_builders.workflows.go_modules.workflow import GoModulesWorkflow from aws_lambda_builders.workflows.go_modules.actions import GoModulesBuildAction @@ -24,6 +25,20 @@ def test_workflow_sets_up_builder_actions(self): self.assertEqual(len(workflow.actions), 1) self.assertIsInstance(workflow.actions[0], GoModulesBuildAction) + def test_workflow_sets_up_builder_actions_provided(self): + workflow = GoModulesWorkflow( + "source", + "artifacts", + "scratch_dir", + "manifest", + runtime="provided", + options={"artifact_executable_name": "main"}, + ) + + self.assertEqual(len(workflow.actions), 1) + self.assertIsInstance(workflow.actions[0], GoModulesBuildAction) + self.assertEqual(workflow.actions[0].output_path, str(Path("artifacts", "bootstrap"))) + def test_must_validate_architecture(self): workflow = GoModulesWorkflow( "source",