Skip to content

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

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

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 added a commit to l1a/resticprofile that referenced this pull request Jul 30, 2026
- PRs 1, 3 and 5 are now open upstream as creativeprojects#670, creativeprojects#672 and creativeprojects#671. Note that
  they are opened with ghpub, since the default fine-grained PAT cannot
  create pull requests on repositories we do not own.
- Flag that creativeprojects#672 conflicts with our own master: the fork already fixed
  that same test differently in 1282c8d (before/after count rather than
  filtering). Records how to resolve it on the next merge.
- Quote issue creativeprojects#331, where the maintainer states linger is not something
  resticprofile should set up automatically and drop-in files are the
  sanctioned mechanism. Wave 4A must not be opened as-is; notes the
  warning-instead-of-enforcement slice that could land.
- Correct the mock drift note: mockery v3.7.0 vs upstream's pinned
  v3.7.1 is the likelier cause, and mark the check as unconfirmed.
- Keep PR 3 and 5 bodies alongside PR 1's in upstream-prs/.

Assisted-By: Claude Opus 5
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