Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Build graph tests using assertTrue instead of assertEqual + added assertions #2909

Merged
merged 2 commits into from
May 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 29 additions & 14 deletions tests/unit/lib/build_module/test_build_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,13 @@ def generate_function(
layers="layers",
events="events",
codesign_config_arn="codesign_config_arn",
metadata={},
metadata=None,
inlinecode=None,
stack_path="",
):
if metadata is None:
metadata = {}

return Function(
name,
function_name,
Expand All @@ -76,10 +79,15 @@ def generate_function(
def generate_layer(
arn="arn:aws:lambda:region:account-id:layer:layer-name:1",
codeuri="codeuri",
compatible_runtimes=["runtime"],
metadata={},
compatible_runtimes=None,
metadata=None,
stack_path="",
):
if compatible_runtimes is None:
compatible_runtimes = ["runtime"]
if metadata is None:
metadata = {}

return LayerVersion(arn, codeuri, compatible_runtimes, metadata, stack_path)


Expand Down Expand Up @@ -314,11 +322,11 @@ def test_functions_should_be_added_existing_build_graph(self):
)
build_graph.put_function_build_definition(build_definition1, function1)

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

build_definition2 = FunctionBuildDefinition(
"another_runtime",
Expand All @@ -330,7 +338,11 @@ def test_functions_should_be_added_existing_build_graph(self):
)
function2 = generate_function(name="another_function")
build_graph.put_function_build_definition(build_definition2, function2)
self.assertTrue(len(build_graph.get_function_build_definitions()), 2)

build_definitions = build_graph.get_function_build_definitions()
self.assertEqual(len(build_definitions), 2)
self.assertEqual(len(build_definitions[1].functions), 1)
self.assertEqual(build_definitions[1].functions[0], function2)

def test_layers_should_be_added_existing_build_graph(self):
with osutils.mkdir_temp() as temp_base_dir:
Expand All @@ -357,10 +369,10 @@ def test_layers_should_be_added_existing_build_graph(self):
)
build_graph.put_layer_build_definition(build_definition1, layer1)

self.assertTrue(len(build_graph.get_layer_build_definitions()), 1)
for build_definition in build_graph.get_layer_build_definitions():
self.assertTrue(build_definition.layer, layer1)
self.assertEqual(build_definition.uuid, TestBuildGraph.LAYER_UUID)
build_definitions = build_graph.get_layer_build_definitions()
self.assertEqual(len(build_definitions), 1)
self.assertEqual(build_definitions[0].layer, layer1)
self.assertEqual(build_definitions[0].uuid, TestBuildGraph.LAYER_UUID)

build_definition2 = LayerBuildDefinition(
"another_layername",
Expand All @@ -372,7 +384,10 @@ def test_layers_should_be_added_existing_build_graph(self):
)
layer2 = generate_layer(arn="arn:aws:lambda:region:account-id:layer:another-layer-name:1")
build_graph.put_layer_build_definition(build_definition2, layer2)
self.assertTrue(len(build_graph.get_layer_build_definitions()), 2)

build_definitions = build_graph.get_layer_build_definitions()
self.assertEqual(len(build_definitions), 2)
self.assertEqual(build_definitions[1].layer, layer2)


class TestBuildDefinition(TestCase):
Expand Down