Skip to content

Inject initFatal as a package-level var (#33370)#45343

Merged
getvictor merged 1 commit into
fleetdm:mainfrom
raju249:33370-inject-initfatal
May 13, 2026
Merged

Inject initFatal as a package-level var (#33370)#45343
getvictor merged 1 commit into
fleetdm:mainfrom
raju249:33370-inject-initfatal

Conversation

@raju249
Copy link
Copy Markdown
Contributor

@raju249 raju249 commented May 13, 2026

Second PR in the staged plan from #33370. Per @getvictor's confirmation, takes the package-level var approach so tests can swap initFatal without terminating the test binary.

The new TestGetTLSConfigInvalidProfile covers getTLSConfig's default case (previously unreachable in tests because it calls initFatal)

Related issue: Part of #33370.

Checklist for submitter

If some of the following don't apply, delete the relevant line.

Testing

  • Added/updated automated tests

Database migrations

N/A — no database migrations in this PR.

New Fleet configuration settings

N/A — no new configuration settings.

fleetd/orbit/Fleet Desktop

N/A — no agent code changes.

Summary by CodeRabbit

  • Tests
    • Improved test coverage for TLS configuration error handling.

Review Change Stack

Replace the initFatal function with a package-level var so tests can
swap it without terminating the test binary via os.Exit. Add a test
for getTLSConfig's default case to exercise the new seam.
@raju249 raju249 requested a review from a team as a code owner May 13, 2026 04:53
Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 13, 2026

Walkthrough

This PR makes initFatal, a package-level fatal error handler in cmd/fleet/main.go, overridable in tests by converting it from a direct function to a function variable. The refactor allows tests to temporarily replace the handler to capture error messages without triggering os.Exit. A new test, TestGetTLSConfigInvalidProfile, demonstrates this capability by overriding initFatal to verify that getTLSConfig correctly emits an error and fatal message when given an invalid TLS profile string.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Inject initFatal as a package-level var (#33370)' clearly and specifically summarizes the main change: refactoring initFatal from a function to a package-level variable.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The pull request description includes a clear reference to the related issue (#33370), explains the rationale for using a package-level var approach, and documents all testing changes. Required sections are present and substantive.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@raju249
Copy link
Copy Markdown
Contributor Author

raju249 commented May 13, 2026

Hello @getvictor - Do you mind taking a look, please?

Thanks! 🙏 🙇

@codecov
Copy link
Copy Markdown

codecov Bot commented May 13, 2026

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 66.70%. Comparing base (7e54e10) to head (f90cc28).
⚠️ Report is 52 commits behind head on main.

Files with missing lines Patch % Lines
cmd/fleet/main.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #45343      +/-   ##
==========================================
- Coverage   66.81%   66.70%   -0.12%     
==========================================
  Files        2724     2728       +4     
  Lines      219027   218328     -699     
  Branches    10590    10590              
==========================================
- Hits       146342   145631     -711     
+ Misses      59521    59483      -38     
- Partials    13164    13214      +50     
Flag Coverage Δ
backend 68.55% <0.00%> (-0.13%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Member

@getvictor getvictor left a comment

Choose a reason for hiding this comment

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

Looks good. thank you

@getvictor getvictor merged commit 363b01d into fleetdm:main May 13, 2026
47 of 48 checks passed
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