Skip to content

Make runRebootRemediation testable via dependency injection; add coverage#134

Draft
Copilot wants to merge 2 commits intorunzhen/npd3from
copilot/sub-pr-131
Draft

Make runRebootRemediation testable via dependency injection; add coverage#134
Copilot wants to merge 2 commits intorunzhen/npd3from
copilot/sub-pr-131

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 23, 2026

runRebootRemediation hard-coded systemd.New() and exec.CommandContext internally, making it untestable without a live systemd. Addresses the review feedback on #131.

Changes

pkg/drift/remediation.go

  • Introduces rebootCommandRunner func type for the exec dependency
  • Adds defaultRebootRunner wrapping exec.CommandContext (annotated #nosec G204)
  • Extracts runRebootRemediationWithDeps(ctx, logger, mgr systemd.Manager, runner rebootCommandRunner) — the injectable, testable core
  • runRebootRemediation becomes a one-liner wrapper providing the real deps:
    func runRebootRemediation(ctx context.Context, logger *logrus.Logger) error {
        return runRebootRemediationWithDeps(ctx, logger, systemd.New(), defaultRebootRunner)
    }
  • Renames local statusunitStatus to avoid shadowing the status package

pkg/drift/remediation_test.go

  • Adds stubSystemdManager (full systemd.Manager implementation) and stubRebootRunner test doubles
  • Adds table-driven TestRunRebootRemediationWithDeps with 6 parallel subtests:
    Subtest Expected behaviour
    unit-not-found/no-op ErrUnitNotFound → nil, runner not called
    inactive/no-op inactive state → nil, runner not called
    active/executes-reboot active state → runner called, nil error
    get-unit-status-error/surfaced non-ErrUnitNotFound error → wrapped and returned
    reboot-command-fails/surfaced runner error → wrapped and returned
    reboot-command-times-out/surfaced expired-deadline context → "timed out" path exercised

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] [WIP] Address feedback on node condition remediation PR Make runRebootRemediation testable via dependency injection; add coverage Mar 23, 2026
Copilot AI requested a review from runzhen March 23, 2026 23:08
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