Skip to content

Commit

Permalink
fix: Fix integration tests for remote test events
Browse files Browse the repository at this point in the history
  • Loading branch information
valerena committed Sep 28, 2023
1 parent a56b7fc commit 441d826
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
30 changes: 19 additions & 11 deletions tests/integration/remote/test_event/remote_test_event_integ_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,7 @@ def setUpClass(cls):
@classmethod
def tearDownClass(cls):
# Delete remaining test events if there were not deleted during tests
for _, resource in cls.stack_resource_summaries.items():
if resource.resource_type == AWS_LAMBDA_FUNCTION:
schema_name = f"_{resource.physical_resource_id}-schema"
try:
cls.schemas_client.delete_schema(
RegistryName=LAMBDA_TEST_EVENT_REGISTRY,
SchemaName=schema_name,
)
LOG.info("Deleted lingering schema for test events: %s", schema_name)
except Exception as e: # Ignore if it doesn't exist (it was correctly deleted during tests)
pass
cls.delete_all_test_events()
# Delete the deployed stack
cls.cfn_client.delete_stack(StackName=cls.stack_name)

Expand All @@ -59,6 +49,24 @@ def create_resources_and_boto_clients(cls):
cls.cfn_client = boto_client_provider("cloudformation")
cls.schemas_client = boto_client_provider("schemas")

@classmethod
def delete_all_test_events(cls, logical_id=None):
for _, resource in cls.stack_resource_summaries.items():
if resource.resource_type == AWS_LAMBDA_FUNCTION:
# If a logical id is passed, delete only that one
if logical_id and logical_id != resource.logical_resource_id:
continue
schema_name = f"_{resource.physical_resource_id}-schema"
try:
cls.schemas_client.delete_schema(
RegistryName=LAMBDA_TEST_EVENT_REGISTRY,
SchemaName=schema_name,
)
LOG.info("Deleted lingering schema for test events: %s", schema_name)
except Exception as e: # Ignore if it doesn't exist (it was correctly deleted during tests)
LOG.debug("No events deleted (this is good) %s", e)
pass

@staticmethod
def get_command_list(
subcommand,
Expand Down
10 changes: 8 additions & 2 deletions tests/integration/remote/test_event/test_remote_test_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def setUpClass(cls):

def test_no_events(self):
function_name = "HelloWorldFunction1"
# Make sure the state is clean
TestRemoteTestEvent.delete_all_test_events(function_name)
self.list_events_and_check(
self.stack_name,
function_name,
Expand All @@ -41,6 +43,8 @@ def test_no_events(self):

def test_event_workflow(self):
function_to_check = "HelloWorldFunction2"
# Make sure the state is clean
TestRemoteTestEvent.delete_all_test_events(function_to_check)
event_contents1 = {"key1": "Hello", "key2": "serverless", "key3": "world"}
event_contents2 = {"a": "A", "b": "B", "c": "C"}

Expand Down Expand Up @@ -99,7 +103,8 @@ def list_events_and_check(self, stack_name, resource_id, expected_output, expect
output = list_result.stdout.strip()
error_output = list_result.stderr.strip()
self.assertEqual(output.decode("utf-8"), expected_output)
self.assertEqual(error_output.decode("utf-8"), expected_error)
if expected_error:
self.assertIn(expected_error, error_output.decode("utf-8"))

def delete_event_and_check(self, stack_name, resource_id, test_event_name):
command_list = self.get_command_list(
Expand All @@ -121,4 +126,5 @@ def get_event_and_check(self, stack_name, resource_id, event_name, expected_outp
output = list_result.stdout.strip()
error_output = list_result.stderr.strip()
self.assertEqual(output.decode("utf-8"), expected_output)
self.assertEqual(error_output.decode("utf-8"), expected_error)
if expected_error:
self.assertIn(expected_error, error_output.decode("utf-8"))

0 comments on commit 441d826

Please sign in to comment.