Skip to content

Add unit tests for disk calculation logic (PR #364 test plan)#365

Closed
Copilot wants to merge 2 commits intomasterfrom
copilot/create-test-plan-for-pr-364
Closed

Add unit tests for disk calculation logic (PR #364 test plan)#365
Copilot wants to merge 2 commits intomasterfrom
copilot/create-test-plan-for-pr-364

Conversation

Copy link
Contributor

Copilot AI commented Mar 9, 2026

PR #364 refactors disk space reporting (SI vs IEC divisors, physical disk deduplication). The disk calculation logic was untestable because it was inlined against live OS APIs. This PR extracts it into a pure, testable function and adds coverage.

Refactor: extract calc_hdd_stats

Pulls the disk aggregation logic out of sample() into a standalone function:

pub(crate) fn calc_hdd_stats(disks: &[DiskCalcInput], si: bool, is_windows: bool) -> (u64, u64)
  • DiskCalcInput captures only name, fs_type, total, avail — no sysinfo dependency
  • Divisor is now explicit: 1_000_000 (SI/macOS) vs 1_048_576 (IEC/Linux+Windows) based on stat.si
  • Dedup HashSet allocated only on non-Windows paths
  • Removes the now-unused unit: u64 variable from sample()

Tests added (sys_info::tests, 10 cases)

Category Tests
Unit conversion SI (÷1 000 000) and IEC (÷1 048 576) divisors produce correct MB/MiB values
FS filtering Unknown types (tmpfs, devtmpfs) excluded; all-unknown → zero
Dedup (non-Windows) Same disk name counted once; distinct names both counted
Windows Dedup skipped — duplicate names counted independently
Edge cases Empty list, fully-used disk, case-insensitive FS match (EXT4ext4)

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: zdz <152173+zdz@users.noreply.github.com>
Copilot AI changed the title [WIP] Create test plan based on PR #364 Add unit tests for disk calculation logic (PR #364 test plan) Mar 9, 2026
Copilot finished work on behalf of zdz March 9, 2026 12:29
@zdz zdz closed this Mar 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants