Skip to content

Commit

Permalink
Add test for file blocksize calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
Miauwkeru committed Sep 9, 2024
1 parent f9604f7 commit 13ea27a
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/filesystems/test_btrfs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from unittest.mock import Mock

import pytest
from dissect.btrfs.btrfs import INode
from dissect.btrfs.c_btrfs import c_btrfs

from dissect.target.filesystems.btrfs import BtrfsFilesystemEntry


@pytest.mark.parametrize(
"sector_size, filesize, expected_blocks",
[
(0x1000, 0x343, 0x1),
(0x1000, 0x1000, 0x1),
(0x1000, 0x1001, 0x2),
],
ids=["lower", "equal", "greater"],
)
def test_stat_information_file_blocksize(sector_size: int, filesize: int, expected_blocks: int) -> None:
entry = INode(Mock(), None)
entry.btrfs = Mock(sector_size=sector_size)
timestamp = c_btrfs.btrfs_timespec()
entry.inode = c_btrfs.btrfs_inode_item(
size=filesize, atime=timestamp, ctime=timestamp, otime=timestamp, mtime=timestamp
)

fs_entry = BtrfsFilesystemEntry(Mock(alt_seperator="/"), "unknown_path", entry)

stat_info = fs_entry.lstat()

assert stat_info.st_birthtime_ns == 0
assert stat_info.st_blksize == sector_size
assert stat_info.st_blocks == expected_blocks

0 comments on commit 13ea27a

Please sign in to comment.