Skip to content

cmd: Add unit tests and fix WebSocket path default #1312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 29, 2025

Conversation

TheRealHaoLiu
Copy link
Member

This commit adds unit tests for the cmd package, improving test coverage from 0% to 50.5%. The tests cover configuration parsing, default settings, and command execution flow.

Key changes:

  • Add tests for configuration functions and utility methods
  • Fix bug in SetWSListenerDefaults where it incorrectly set BindAddr instead of Path for empty paths
  • Add test infrastructure including mock implementations
  • Skip complex tests that require additional setup for future implementation

The WebSocket path bug fix ensures that when a WebSocket listener is configured without specifying a path, it correctly defaults to '/' instead of incorrectly setting the BindAddr field.

This commit adds unit tests for the cmd package, improving test coverage
from 0% to 50.5%. The tests cover configuration parsing, default settings,
and command execution flow.

Key changes:
- Add tests for configuration functions and utility methods
- Fix bug in SetWSListenerDefaults where it incorrectly set BindAddr
  instead of Path for empty paths
- Add test infrastructure including mock implementations
- Skip complex tests that require additional setup for future implementation

The WebSocket path bug fix ensures that when a WebSocket listener is
configured without specifying a path, it correctly defaults to '/' instead
of incorrectly setting the BindAddr field.
@TheRealHaoLiu TheRealHaoLiu requested a review from Copilot April 24, 2025 18:58
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds unit tests for the cmd package to boost test coverage to 50.5% while also fixing the bug in SetWSListenerDefaults that incorrectly set the BindAddr instead of the WebSocket path.

  • Added tests for configuration parsing, default settings, and command execution flow
  • Fixed the WebSocket listener default by setting the Path to "/" instead of modifying BindAddr
  • Established test infrastructure with mocking and skipped tests for more complex setups

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
cmd/root_test.go Added tests for config initialization and command execution, with skipped tests where needed
cmd/defaults_test.go Included unit tests for defaults on listeners and peers
cmd/defaults.go Fixed the WebSocket listener default by updating the Path assignment
cmd/config_test.go Added tests for receptor configuration parsing and command phase execution

Copy link

codecov bot commented Apr 24, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 43.59%. Comparing base (0d1b5d8) to head (4e8c370).
Report is 2 commits behind head on devel.

@@            Coverage Diff             @@
##            devel    #1312      +/-   ##
==========================================
+ Coverage   41.70%   43.59%   +1.88%     
==========================================
  Files          45       48       +3     
  Lines        9454    10034     +580     
==========================================
+ Hits         3943     4374     +431     
- Misses       5220     5366     +146     
- Partials      291      294       +3     
Files with missing lines Coverage Δ
cmd/defaults.go 100.00% <100.00%> (+100.00%) ⬆️

... and 10 files with indirect coverage changes

Components Coverage Δ
Go 43.24% <100.00%> (+1.53%) ⬆️
Receptorctl 49.31% <ø> (∅)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

- Add periods to comments
- Add blank lines before return statements
- Replace 'else { if ... }' with 'else if ...'
- Skip tests that require cobra import to avoid depguard violations
Copy link

Copy link
Contributor

@AaronH88 AaronH88 left a comment

Choose a reason for hiding this comment

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

lgtm 1 of 2

Copy link
Collaborator

@matoval matoval left a comment

Choose a reason for hiding this comment

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

lgtm

@matoval matoval merged commit ef6227d into ansible:devel Apr 29, 2025
24 checks passed
arrestle pushed a commit to arrestle/receptor that referenced this pull request Jun 6, 2025
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.

3 participants