Skip to content

Test: Improve coverage for auth, cron, factory, run, and rest packages#3296

Open
NitinKumar004 wants to merge 2 commits intogofr-dev:developmentfrom
NitinKumar004:test/improve-core-coverage
Open

Test: Improve coverage for auth, cron, factory, run, and rest packages#3296
NitinKumar004 wants to merge 2 commits intogofr-dev:developmentfrom
NitinKumar004:test/improve-core-coverage

Conversation

@NitinKumar004
Copy link
Copy Markdown
Contributor

@NitinKumar004 NitinKumar004 commented Apr 11, 2026

Summary

Added table-driven unit tests to improve coverage for core framework files: auth.go, cron.go, factory.go, run.go, and rest.go. Only test files modified — no production code changes.

Coverage improvements

Function Before After
EnableBasicAuthWithFunc 0% 100%
EnableAPIKeyAuthWithFunc 0% 100%
EnableBasicAuth 81.8% 100%
errParsing.Error() 66.7% 100%
handleStartupHooks 28.6% 100%
startGRPCServer 20% 100%
rest.go add() 71.4% 85.7%

Overall package coverage: 82.4% → 83.5%

Tests added

  • Test_EnableBasicAuthWithFunc — table-driven: no auth, correct creds, wrong creds
  • Test_EnableAPIKeyAuthWithFunc — table-driven: no key, valid key, invalid key
  • Test_EnableBasicAuth_NoCredentials — edge case with empty credentials
  • TestHandleStartupHooks — table-driven: no hooks, success, error
  • TestHandleStartupHooks_ContextCanceled — context.Canceled path
  • Test_add_RequestTimeout — table-driven: valid, empty, invalid, negative timeout
  • TestErrParsing_Error — both branches (with/without base)
  • TestErrOutOfRange_Error — error message format
  • TestJob_tick_SecNilAndNonZeroSec — nil sec field edge cases
  • TestNoopRequest — all interface methods
  • TestNew_InvalidGRPCPort / TestNew_InvalidHTTPPort — factory error paths
  • TestInitMetricsServer_DefaultPort — default metrics port
  • TestStartGRPCServer_Registered / TestStartGRPCServer_NotRegistered — both paths
  • TestStartSubscriptionManager_NoSubscriptions — empty subscriptions
  • Test_HTTPMethods — table-driven: PUT, POST, DELETE, PATCH

Test plan

  • All new tests pass locally
  • Full pkg/gofr test suite passes
  • Linter passes with 0 new issues
  • Only test files modified — no production code changes

Add table-driven tests for uncovered functions:
- EnableBasicAuthWithFunc (0% -> 100%)
- EnableAPIKeyAuthWithFunc (0% -> 100%)
- EnableBasicAuth with no credentials (81.8% -> 100%)
- handleStartupHooks including context.Canceled path (28.6% -> 100%)
- rest.go add() with REQUEST_TIMEOUT edge cases (71.4% -> 85.7%)

Overall package coverage: 82.4% -> 83.1%
…thods

- errParsing.Error() both branches (66.7% -> 100%)
- errOutOfRange.Error() direct test
- job.tick with nil sec field edge cases
- noopRequest interface methods
- New() with invalid gRPC and HTTP port configs
- initMetricsServer with default port
- startGRPCServer registered and not-registered paths (20% -> 100%)
- startSubscriptionManager with no subscriptions
- PUT/POST/DELETE/PATCH route registration
@NitinKumar004 NitinKumar004 changed the title Test: Improve coverage for auth, run, and rest packages Test: Improve coverage for auth, cron, factory, run, and rest packages Apr 11, 2026
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.

1 participant