Skip to content
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

tests: improve test coverage for main packages #1010

Merged
merged 8 commits into from
May 31, 2024
Merged

Conversation

GabrielNagy
Copy link
Contributor

I've added details in the individual commit messages, but ultimately this aims to improve coverage for lacking packages such as all main packages for the CLI tools (adsysd/adsysctl, adwatchd, admxgen).

Fixes UDENG-2762

This is hard to explain, but... it's a trick to be able to exercise the
main function from within tests without the logic defaulting to starting
the client and ultimately failing because there's no socket to connect
to. Because `os.Args[0]` is occupied by the Go test runner we can't alter
it, so defaulting to starting the daemon is the next best thing.
We can do a smoke test of the main function by telling it to print the
version and asserting on the output.
@GabrielNagy GabrielNagy marked this pull request as ready for review May 29, 2024 17:31
@GabrielNagy GabrielNagy requested a review from a team as a code owner May 29, 2024 17:31
Copy link
Member

@didrocks didrocks left a comment

Choose a reason for hiding this comment

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

Excellent work as usual :)

2 small questions before approving it.

cmd/admxgen/commands/main.go Show resolved Hide resolved
cmd/adsysd/main_test.go Show resolved Hide resolved
cmd/adwatchd/main_test.go Show resolved Hide resolved
GabrielNagy and others added 6 commits May 30, 2024 15:12
Remove environment prefix since we never used it and it's not documented
anywhere, and use decorate to bind the viper flags.
Similarly to how we handle adsysd and adwatchd, handle the Cobra
configuration in a separate package that we call from the main package,
thus leaving the main package unaware of implementation details.
These tests also cover the commands package as we exercise the main
function directly.
This is no longer needed after the admxgen refactor.
@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 98.71795% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 93.35%. Comparing base (861f5b1) to head (561487d).

Files Patch % Lines
cmd/adsysd/main.go 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1010      +/-   ##
==========================================
+ Coverage   91.40%   93.35%   +1.94%     
==========================================
  Files          78       79       +1     
  Lines        6890     6877      -13     
==========================================
+ Hits         6298     6420     +122     
+ Misses        581      447     -134     
+ Partials       11       10       -1     

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

@GabrielNagy GabrielNagy requested a review from didrocks May 30, 2024 13:49
@GabrielNagy GabrielNagy merged commit 2c0a23f into main May 31, 2024
15 checks passed
@GabrielNagy GabrielNagy deleted the cmd-main-coverage branch May 31, 2024 08:38
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