diff options
Diffstat (limited to 'packages/meshbay-node/tests/test_index_cache.py')
| -rw-r--r-- | packages/meshbay-node/tests/test_index_cache.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/packages/meshbay-node/tests/test_index_cache.py b/packages/meshbay-node/tests/test_index_cache.py index db0e37e..24e2f76 100644 --- a/packages/meshbay-node/tests/test_index_cache.py +++ b/packages/meshbay-node/tests/test_index_cache.py @@ -60,6 +60,52 @@ async def test_put_overwrites_previous_row_for_same_path(cache): @pytest.mark.asyncio +async def test_count_reflects_number_of_rows(cache): + assert await cache.count() == 0 + + await cache.put("/lib/a.mkv", size=1000, mtime=111.0, hash="a", + type="video", added_at=1) + await cache.put("/lib/b.mkv", size=2000, mtime=222.0, hash="b", + type="video", added_at=2) + + assert await cache.count() == 2 + + +@pytest.mark.asyncio +async def test_all_paths_returns_every_row(cache): + await cache.put("/lib/a.mkv", size=1000, mtime=111.0, hash="a", + type="video", added_at=1) + await cache.put("/lib/b.mkv", size=2000, mtime=222.0, hash="b", + type="video", added_at=2) + + assert set(await cache.all_paths()) == {"/lib/a.mkv", "/lib/b.mkv"} + + +@pytest.mark.asyncio +async def test_remove_many_drops_only_the_given_paths(cache): + await cache.put("/lib/a.mkv", size=1000, mtime=111.0, hash="a", + type="video", added_at=1) + await cache.put("/lib/b.mkv", size=2000, mtime=222.0, hash="b", + type="video", added_at=2) + + await cache.remove_many(["/lib/a.mkv"]) + + assert await cache.lookup("/lib/a.mkv", size=1000, mtime=111.0) is None + assert await cache.lookup("/lib/b.mkv", size=2000, mtime=222.0) is not None + assert await cache.count() == 1 + + +@pytest.mark.asyncio +async def test_remove_many_with_empty_list_is_a_no_op(cache): + await cache.put("/lib/a.mkv", size=1000, mtime=111.0, hash="a", + type="video", added_at=1) + + await cache.remove_many([]) + + assert await cache.count() == 1 + + +@pytest.mark.asyncio async def test_cache_survives_reopen(tmp_path): db_path = tmp_path / "index_cache.db" |