Skip to content

refactor!: Replace log.Fatal with error returns, achieve 93% coverage - #39

Merged
lykinsbd merged 2 commits into
masterfrom
feat/35-100pct-coverage
Feb 26, 2026
Merged

refactor!: Replace log.Fatal with error returns, achieve 93% coverage#39
lykinsbd merged 2 commits into
masterfrom
feat/35-100pct-coverage

Conversation

@lykinsbd

Copy link
Copy Markdown
Collaborator

Summary

Refactor all log.Fatal calls to return errors, making the codebase fully testable. Achieve 93% total test coverage.

Breaking changes

  • InitGeneric now returns (*FakeDevice, error)
  • ParseArgs now returns (int, *int, TranscriptMap, error)
  • GenericListener now returns error

Refactoring

  • readFile → returns (string, error)
  • TranscriptReader → removed log.Fatal, returns errors only
  • GenericCiscoHandler → logs + breaks on TranscriptReader error instead of fatal
  • GenericListener → returns error from ListenAndServe, removed dead code
  • Extracted run() from main() for testability
  • Extracted LoadTranscriptMap() from ParseArgs for testability

Coverage results (28 tests)

Package Coverage
fakedevices 100%
ssh_server/sshlistners 100%
utils 100%
ssh_server/handlers 92.6%
Total 93.0%

Remaining uncovered (7%)

  • main() — 3-line wrapper calling log.Fatal/os.Exit (standard Go convention)
  • run() happy path — goroutine loop + channel wait (blocks forever)
  • GenericCiscoHandler — defensive CmdMatch error branches (CmdMatch never returns errors)

Closes #32

BREAKING CHANGE: InitGeneric now returns (*FakeDevice, error).
ParseArgs now returns (int, *int, TranscriptMap, error).
GenericListener now returns error.

Refactor all log.Fatal calls to return errors, enabling full
testability. Extract run() from main() and add LoadTranscriptMap
for testable YAML parsing.

Coverage by package:
  fakedevices:           100%
  ssh_server/handlers:    92.6%
  ssh_server/sshlistners: 100%
  utils:                  100%
  Total:                  93.0%

Remaining uncovered: main() wrapper (os.Exit), run() happy path
(blocks on channel), and defensive CmdMatch error branches
(CmdMatch never returns errors).

Closes #32
Annotate structurally untestable code paths:
- main(): thin wrapper calling os.Exit via log.Fatal
- run() goroutine loop: blocks forever on <-done
- CmdMatch error branches: CmdMatch never returns errors
@github-actions

Copy link
Copy Markdown
Contributor

Merging this branch will increase overall coverage

Impacted Packages Coverage Δ 🤖
github.com/tbotnz/cisshgo 46.15% (+46.15%) 🌟
github.com/tbotnz/cisshgo/fakedevices 100.00% (+10.34%) 🎉
github.com/tbotnz/cisshgo/ssh_server/handlers 92.59% (+5.80%) 👍
github.com/tbotnz/cisshgo/ssh_server/sshlistners 100.00% (+100.00%) 🌟
github.com/tbotnz/cisshgo/utils 100.00% (+26.53%) 🌟

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/tbotnz/cisshgo/cissh.go 46.15% (+46.15%) 13 (+7) 6 (+6) 7 (+1) 🌟
github.com/tbotnz/cisshgo/fakedevices/genericFakeDevice.go 100.00% (+4.55%) 25 (+3) 25 (+4) 0 (-1) 👍
github.com/tbotnz/cisshgo/fakedevices/transcriptReader.go 100.00% (+28.57%) 7 7 (+2) 0 (-2) 🌟
github.com/tbotnz/cisshgo/ssh_server/handlers/ciscohandlers.go 92.59% (+5.80%) 54 (+1) 50 (+4) 4 (-3) 👍
github.com/tbotnz/cisshgo/ssh_server/sshlistners/sshlistners.go 100.00% (+100.00%) 7 (+1) 7 (+7) 0 (-6) 🌟
github.com/tbotnz/cisshgo/utils/argparsing.go 100.00% (+100.00%) 16 (+3) 16 (+16) 0 (-13) 🌟

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

Changed unit test files

  • github.com/tbotnz/cisshgo/cissh_test.go
  • github.com/tbotnz/cisshgo/fakedevices/genericFakeDevice_test.go
  • github.com/tbotnz/cisshgo/fakedevices/transcriptReader_test.go
  • github.com/tbotnz/cisshgo/ssh_server/handlers/ciscohandlers_test.go
  • github.com/tbotnz/cisshgo/ssh_server/sshlistners/sshlistners_test.go
  • github.com/tbotnz/cisshgo/utils/argparsing_test.go

@lykinsbd
lykinsbd merged commit 585a431 into master Feb 26, 2026
4 checks passed
@lykinsbd
lykinsbd deleted the feat/35-100pct-coverage branch February 26, 2026 18:21
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.

Add comprehensive testing infrastructure and CI/CD workflows

1 participant