예제 #1
0
    def test_build_layers_and_functions(self, mock_copy_tree):
        given_build_function = Mock()
        given_build_function.inlinecode = None
        given_build_layer = Mock()
        given_build_dir = "build_dir"
        default_build_strategy = DefaultBuildStrategy(self.build_graph,
                                                      given_build_dir,
                                                      given_build_function,
                                                      given_build_layer)

        default_build_strategy.build()

        # assert that build function has been called
        given_build_function.assert_has_calls([
            call(
                self.function_build_definition1.get_function_name(),
                self.function_build_definition1.codeuri,
                ZIP,
                self.function_build_definition1.runtime,
                self.function_build_definition1.get_handler_name(),
                self.function_build_definition1.get_build_dir(given_build_dir),
                self.function_build_definition1.metadata,
            ),
            call(
                self.function_build_definition2.get_function_name(),
                self.function_build_definition2.codeuri,
                ZIP,
                self.function_build_definition2.runtime,
                self.function_build_definition2.get_handler_name(),
                self.function_build_definition2.get_build_dir(given_build_dir),
                self.function_build_definition2.metadata,
            ),
        ])

        # assert that layer build function has been called
        given_build_layer.assert_has_calls([
            call(
                self.layer1.name,
                self.layer1.codeuri,
                self.layer1.build_method,
                self.layer1.compatible_runtimes,
                self.layer1.get_build_dir(given_build_dir),
            ),
            call(
                self.layer2.name,
                self.layer2.codeuri,
                self.layer2.build_method,
                self.layer2.compatible_runtimes,
                self.layer2.get_build_dir(given_build_dir),
            ),
        ])
        # previously we also assert artifact dir here.
        # since artifact dir is now determined in samcli/lib/providers/provider.py
        # we will not do assertion here

        # assert that function1_2 artifacts have been copied from already built function1_1
        mock_copy_tree.assert_called_with(
            self.function_build_definition1.get_build_dir(given_build_dir),
            self.function1_2.get_build_dir(given_build_dir),
        )
예제 #2
0
    def build(self):
        """
        Build the entire application

        Returns
        -------
        dict
            Returns the path to where each resource was built as a map of resource's LogicalId to the path string
        """
        build_graph = self._get_build_graph()
        build_strategy = DefaultBuildStrategy(build_graph, self._build_dir,
                                              self._build_function,
                                              self._build_layer)

        if self._parallel:
            if self._cached:
                build_strategy = ParallelBuildStrategy(
                    build_graph,
                    CachedBuildStrategy(build_graph, build_strategy,
                                        self._base_dir, self._build_dir,
                                        self._cache_dir,
                                        self._is_building_specific_resource))
            else:
                build_strategy = ParallelBuildStrategy(build_graph,
                                                       build_strategy)
        elif self._cached:
            build_strategy = CachedBuildStrategy(
                build_graph, build_strategy, self._base_dir, self._build_dir,
                self._cache_dir, self._is_building_specific_resource)

        return build_strategy.build()
예제 #3
0
    def test_build_layers_and_functions(self, mock_copy_tree, mock_path):
        given_build_function = Mock()
        given_build_function.inlinecode = None
        given_build_layer = Mock()
        given_build_dir = "build_dir"
        default_build_strategy = DefaultBuildStrategy(self.build_graph,
                                                      given_build_dir,
                                                      given_build_function,
                                                      given_build_layer)

        default_build_strategy.build()

        # assert that build function has been called
        given_build_function.assert_has_calls([
            call(
                self.function_build_definition1.get_function_name(),
                self.function_build_definition1.codeuri,
                ZIP,
                self.function_build_definition1.runtime,
                self.function_build_definition1.get_handler_name(),
                ANY,
                self.function_build_definition1.metadata,
            ),
            call(
                self.function_build_definition2.get_function_name(),
                self.function_build_definition2.codeuri,
                ZIP,
                self.function_build_definition2.runtime,
                self.function_build_definition2.get_handler_name(),
                ANY,
                self.function_build_definition2.metadata,
            ),
        ])

        # assert that layer build function has been called
        given_build_layer.assert_has_calls([
            call(
                self.layer_build_definition1.layer.name,
                self.layer_build_definition1.layer.codeuri,
                self.layer_build_definition1.layer.build_method,
                self.layer_build_definition1.layer.compatible_runtimes,
            ),
            call(
                self.layer_build_definition2.layer.name,
                self.layer_build_definition2.layer.codeuri,
                self.layer_build_definition2.layer.build_method,
                self.layer_build_definition2.layer.compatible_runtimes,
            ),
        ])

        # assert that mock path has been called
        mock_path.assert_has_calls(
            [
                call(given_build_dir,
                     self.function_build_definition1.get_function_name()),
                call(given_build_dir,
                     self.function_build_definition2.get_function_name()),
            ],
            any_order=True,
        )

        # assert that function1_2 artifacts have been copied from already built function1_1
        mock_copy_tree.assert_called_with(
            str(
                mock_path(
                    given_build_dir,
                    self.function_build_definition1.get_function_name())),
            str(mock_path(given_build_dir, self.function1_2.name)),
        )