def test_functions_should_be_added_existing_build_graph(self):
        with osutils.mkdir_temp() as temp_base_dir:
            build_dir = Path(temp_base_dir, ".aws-sam", "build")
            build_dir.mkdir(parents=True)

            build_graph_path = Path(build_dir.parent, "build.toml")
            build_graph_path.write_text(TestBuildGraph.BUILD_GRAPH_CONTENTS)

            build_graph = BuildGraph(str(build_dir))

            build_definition1 = BuildDefinition(TestBuildGraph.RUNTIME,
                                                TestBuildGraph.CODEURI,
                                                TestBuildGraph.METADATA)
            function1 = generate_function(runtime=TestBuildGraph.RUNTIME,
                                          codeuri=TestBuildGraph.CODEURI,
                                          metadata=TestBuildGraph.METADATA)
            build_graph.put_build_definition(build_definition1, function1)

            self.assertTrue(len(build_graph.get_build_definitions()), 1)
            for build_definition in build_graph.get_build_definitions():
                self.assertTrue(len(build_definition.functions), 1)
                self.assertTrue(build_definition.functions[0], function1)
                self.assertEqual(build_definition.uuid, TestBuildGraph.UUID)

            build_definition2 = BuildDefinition("another_runtime",
                                                "another_codeuri", None)
            function2 = generate_function(name="another_function")
            build_graph.put_build_definition(build_definition2, function2)
            self.assertTrue(len(build_graph.get_build_definitions()), 2)
Beispiel #2
0
    def _get_build_graph(self):
        """
        Converts list of functions into a build graph, where we can iterate on each unique build and trigger build
        :return: BuildGraph, which represents list of unique build definitions
        """
        build_graph = BuildGraph(self._build_dir)
        functions = self._resources_to_build.functions
        for function in functions:
            build_details = BuildDefinition(function.runtime, function.codeuri, function.metadata)
            build_graph.put_build_definition(build_details, function)

        build_graph.clean_redundant_functions_and_update(not self._is_building_specific_resource)
        return build_graph
    def test_should_instantiate_first_time_and_update(self):
        with osutils.mkdir_temp() as temp_base_dir:
            build_dir = Path(temp_base_dir, ".aws-sam", "build")
            build_dir.mkdir(parents=True)

            # create a build graph and persist it
            build_graph1 = BuildGraph(str(build_dir))
            build_definition1 = BuildDefinition(TestBuildGraph.RUNTIME, TestBuildGraph.CODEURI, TestBuildGraph.METADATA)
            function1 = generate_function(
                runtime=TestBuildGraph.RUNTIME, codeuri=TestBuildGraph.CODEURI, metadata=TestBuildGraph.METADATA
            )
            build_graph1.put_build_definition(build_definition1, function1)
            build_graph1.clean_redundant_functions_and_update(True)

            # read previously persisted graph and compare
            build_graph2 = BuildGraph(str(build_dir))
            self.assertEqual(len(build_graph1.get_build_definitions()), len(build_graph2.get_build_definitions()))
            self.assertEqual(
                list(build_graph1.get_build_definitions())[0], list(build_graph2.get_build_definitions())[0]
            )