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

Issue 4837: chore: main_test.go unit-tests #6314

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mrajagopal
Copy link
Contributor

This is the first of potentially a few to get testability for main.go:

  • Added unit-tests for the following functions:
  • mustCreateConfigClient, mustValidateIngressClass, mustConfirmMinimumK8sVersionCriteria
  • Some of the function names were ported from a PR based off an earlier revision of main branch

NOTE: At present there isn't any test for mustCreateDynamicClient as it doesn't seem testable

Proposed changes

The objective of this PR is to give test coverage for main.go as outlined in #4837.
This includes improving functions by:

returning the error instead of throwing a fatal error
Split functions to improve readability and testability

Checklist

Before creating a PR, run through this checklist and mark each as complete.

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked that all unit tests pass after adding my changes
  • I have updated necessary documentation
  • I have rebased my branch onto main
  • I will ensure my PR is targeting the main branch and pulling from my branch from my own fork

* Added test for mustCreateConfigClient, mustValidateIngressClass, mustConfirmMinimumK8sVersionCriteria
@github-actions github-actions bot added the go Pull requests that update Go code label Aug 30, 2024
Copy link

codecov bot commented Aug 30, 2024

Codecov Report

Attention: Patch coverage is 25.58140% with 32 lines in your changes missing coverage. Please review.

Project coverage is 53.09%. Comparing base (a41fc13) to head (f58aa90).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
cmd/nginx-ingress/main.go 25.58% 32 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6314      +/-   ##
==========================================
+ Coverage   52.98%   53.09%   +0.11%     
==========================================
  Files          77       77              
  Lines       15900    15908       +8     
==========================================
+ Hits         8424     8447      +23     
+ Misses       7071     7048      -23     
- Partials      405      413       +8     

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

Copy link
Contributor

@jjngx jjngx left a comment

Choose a reason for hiding this comment

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

The point of having functions with the prefix must is to communicate that those functions do not return errors (see Go std lib). They either call panic or os.Exit (log.Fatal). They prevent the NIC from starting in a state that would make it impossible to run.

There is no need to add additional error handling (or move call to os.Exit from inside the func) as there is no error returned. The function either validate or set some values or terminate the program.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go Pull requests that update Go code
Projects
Status: Todo ☑
Development

Successfully merging this pull request may close these issues.

2 participants