Skip to content

Commit

Permalink
fix: handle InMemoryDatabase find_schemas latest when no versions ava…
Browse files Browse the repository at this point in the history
…ilable for subject
  • Loading branch information
biggusdonzus committed Mar 8, 2024
1 parent af21074 commit 8f6562a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion karapace/in_memory_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def find_schemas(self, *, include_deleted: bool, latest_only: bool) -> dict[Subj
for subject, subject_data in self.subjects.items():
selected_schemas: list[SchemaVersion] = []
schemas = list(subject_data.schemas.values())
if latest_only:
if latest_only and len(schemas) > 0:
# TODO don't include the deleted here?
selected_schemas = [schemas[-1]]
else:
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/test_in_memory_database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""
Copyright (c) 2024 Aiven Ltd
See LICENSE for details
"""
from karapace.in_memory_database import InMemoryDatabase, Subject


class TestFindSchemas:
def test_returns_empty_list_when_no_schemas(self) -> None:
database = InMemoryDatabase()
subject = Subject("hello_world")
database.insert_subject(subject=subject)
expected = {subject: []}
assert database.find_schemas(include_deleted=True, latest_only=True) == expected

0 comments on commit 8f6562a

Please sign in to comment.