Skip to content

test(schedule): ignore pre-existing schedules in the final assertion - #672

Closed
l1a wants to merge 1 commit into
creativeprojects:masterfrom
l1a:test/systemd-scheduled-isolation
Closed

test(schedule): ignore pre-existing schedules in the final assertion#672
l1a wants to merge 1 commit into
creativeprojects:masterfrom
l1a:test/systemd-scheduled-isolation

Conversation

@l1a

@l1a l1a commented Jul 30, 2026

Copy link
Copy Markdown

Problem

TestReadingSystemdScheduled fails on any machine that has a real resticprofile schedule installed:

    Error Trace:  schedule/handler_systemd_test.go:133
    Error:        Should be empty, but was [{dot-files backup [hourly] user_logged_on  /home/user/.config/resticprofile
                  /home/user/go/bin/resticprofile --no-ansi --config /home/user/.config/resticprofile/profiles.yaml
                  run-schedule backup@dot-files ...}]
    Test:         TestReadingSystemdScheduled

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 whose ConfigFile isn't one of its own fixtures. But the final assert.Empty check 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:

--- FAIL: TestReadingSystemdScheduled (1.32s)

After:

=== RUN   TestReadingSystemdScheduled
    handler_systemd_test.go:114: Ignoring config file /home/user/.config/resticprofile/profiles.yaml
    handler_systemd_test.go:124: Ignoring config file /home/user/.config/resticprofile/profiles.yaml
--- PASS: TestReadingSystemdScheduled (1.95s)
ok      github.com/creativeprojects/resticprofile/schedule

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 build and make lint pass (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

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
@l1a l1a closed this by deleting the head repository Aug 1, 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.

1 participant