Skip to content

testsuite: add borg1_hardlink_master/slave/hardlinkable unit tests, refs #9556#9685

Open
mr-raj12 wants to merge 1 commit into
borgbackup:masterfrom
mr-raj12:testsuite-legacy-helpers
Open

testsuite: add borg1_hardlink_master/slave/hardlinkable unit tests, refs #9556#9685
mr-raj12 wants to merge 1 commit into
borgbackup:masterfrom
mr-raj12:testsuite-legacy-helpers

Conversation

@mr-raj12
Copy link
Copy Markdown
Contributor

@mr-raj12 mr-raj12 commented May 30, 2026

Description

Unit tests for borg1_hardlinkable, borg1_hardlink_master, and borg1_hardlink_slave, refs #9556.

legacy/helpers.py has three predicates that UpgraderFrom12To20.upgrade_item() uses to tell hardlink masters from slaves from regular items. PR #9675 tests the upgrade flow end to end, but these predicates themselves had no coverage. This PR adds src/borg/testsuite/legacy_helpers_test.py with 18 tests covering all three.

src/borg/testsuite/legacy_helpers_test.py -- 18 tests:

borg1_hardlinkable (7 tests):

  • regular file → True
  • block device → True
  • char device → True
  • FIFO → True
  • symlink → False
  • directory → False
  • socket → False

borg1_hardlink_master (5 tests):

  • all conditions met → True
  • hardlink_master key absent → False
  • hardlink_master=False → False
  • source present (even with hardlink_master=True) → False
  • non-hardlinkable mode → False

borg1_hardlink_slave (6 tests):

  • source present, regular file → True
  • source present, FIFO (non-regular hardlinkable type) → True
  • no source → False
  • non-hardlinkable mode → False
  • item with both hardlink_master=True and source: master=False, slave=True (mutual exclusion documented)

Refs #9556

Checklist

  • PR is against master
  • New code has tests
  • Tests pass (run tox or the relevant test subset)
  • Commit messages are clean and reference related issues

@codecov
Copy link
Copy Markdown

codecov Bot commented May 30, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.87%. Comparing base (7f43779) to head (85ed3e9).
⚠️ Report is 5 commits behind head on master.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #9685   +/-   ##
=======================================
  Coverage   83.87%   83.87%           
=======================================
  Files          93       93           
  Lines       15586    15586           
  Branches     2335     2335           
=======================================
  Hits        13073    13073           
  Misses       1785     1785           
  Partials      728      728           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines +64 to +71
def test_hardlink_master_false_when_source_present():
item = _item(hardlink_master=True, source="dir/original")
assert not borg1_hardlink_master(item)


def test_hardlink_master_false_when_mode_not_hardlinkable():
item = _item(hardlink_master=True, mode=stat.S_IFLNK | 0o777)
assert not borg1_hardlink_master(item)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are a bit curious cases. But I'ld hope the code never produces such items.

Comment on lines +93 to +102
def test_hardlink_slave_false_when_mode_not_hardlinkable():
item = _item(source="dir/original", mode=stat.S_IFLNK | 0o777)
assert not borg1_hardlink_slave(item)


def test_master_and_slave_are_mutually_exclusive():
# source present means master check fails; slave check wins
item = _item(hardlink_master=True, source="dir/original")
assert not borg1_hardlink_master(item)
assert borg1_hardlink_slave(item)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also curious cases.

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