Ejemplo n.º 1
0
    def test_different_runtime_codeuri_metadata_should_not_reflect_as_same_object(
            self, runtime1, codeuri1, metadata1, runtime2, codeuri2,
            metadata2):
        build_definition1 = BuildDefinition(runtime1, codeuri1, metadata1)
        build_definition2 = BuildDefinition(runtime2, codeuri2, metadata2)

        self.assertNotEqual(build_definition1, build_definition2)
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
    def test_same_runtime_codeuri_metadata_should_reflect_as_same_object(self):
        build_definition1 = BuildDefinition("runtime", "codeuri",
                                            {"key": "value"})
        build_definition2 = BuildDefinition("runtime", "codeuri",
                                            {"key": "value"})

        self.assertEqual(build_definition1, build_definition2)
Ejemplo n.º 4
0
    def test_build_definition_to_toml_table(self):
        build_definition = BuildDefinition("runtime", "codeuri", {"key": "value"})
        build_definition.add_function(generate_function())

        toml_table = _build_definition_to_toml_table(build_definition)

        self.assertEqual(toml_table[CODE_URI_FIELD], build_definition.codeuri)
        self.assertEqual(toml_table[RUNTIME_FIELD], build_definition.runtime)
        self.assertEqual(toml_table[METADATA_FIELD], build_definition.metadata)
        self.assertEqual(toml_table[FUNCTIONS_FIELD], [f.name for f in build_definition.functions])
Ejemplo n.º 5
0
    def test_no_function_should_raise_exception(self):
        build_definition = BuildDefinition("runtime", "codeuri", "metadata")

        self.assertRaises(InvalidBuildGraphException,
                          build_definition.get_handler_name)
        self.assertRaises(InvalidBuildGraphException,
                          build_definition.get_function_name)
Ejemplo n.º 6
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
Ejemplo n.º 7
0
    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]
            )
Ejemplo n.º 8
0
 def test_str_representation(self):
     build_definition = BuildDefinition("runtime", "codeuri", None)
     self.assertEqual(
         str(build_definition),
         f"BuildDefinition(runtime, codeuri, {build_definition.uuid}, {{}}, [])"
     )
Ejemplo n.º 9
0
 def test_euqality_with_another_object(self):
     build_definition = BuildDefinition("runtime", "codeuri", None)
     self.assertNotEqual(build_definition, {})
Ejemplo n.º 10
0
    def test_single_function_should_return_function_and_handler_name(self):
        build_definition = BuildDefinition("runtime", "codeuri", "metadata")
        build_definition.add_function(generate_function())

        self.assertEqual(build_definition.get_handler_name(), "handler")
        self.assertEqual(build_definition.get_function_name(), "name")