test(schedule): ignore pre-existing schedules in the final assertion - #672
Closed
l1a wants to merge 1 commit into
Closed
test(schedule): ignore pre-existing schedules in the final assertion#672l1a wants to merge 1 commit into
l1a wants to merge 1 commit into
Conversation
TestReadingSystemdScheduled fails on any machine that has a real
resticprofile schedule installed:
Error: Should be empty, but was [{dot-files backup [hourly] ...}]
Test: TestReadingSystemdScheduled
Scheduled() reads the user's real systemd unit directory, so it returns
the developer's own schedules alongside the ones the test creates. The
test already accounts for that when building the list it compares with
ElementsMatch, but the final assert.Empty check uses the unfiltered
slice, so it sees whatever else is installed.
Extract the existing filter into a helper and use it in both places.
Assisted-By: Claude Opus 5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
TestReadingSystemdScheduledfails on any machine that has a real resticprofile schedule installed:Scheduled()reads the user's real systemd unit directory, so it returns the developer's own schedules alongside the two the test creates.The test already accounts for this when it builds the list it compares with
ElementsMatch— it skips anything whoseConfigFileisn't one of its own fixtures. But the finalassert.Emptycheck a few lines later uses the raw, unfiltered slice, so it sees whatever else happens to be installed on the machine.Net effect: the suite passes on a clean CI runner and fails locally for anyone who actually uses resticprofile.
Fix
Extract the filter the test already contains into a small helper and use it in both assertions. No production code touched.
Verification
Before, on a machine with one real hourly schedule installed:
After:
The two log lines are the same real schedule being skipped at each of the two filter points, which is exactly the case that was failing.
make buildandmake lintpass (0 issues on darwin, linux and windows), and the pre-existing schedule I had installed was still present and enabled afterwards.🤖 Generated with Claude Code