increase coverage #8
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request introduces enhanced error handling for command execution, adds extensive unit tests for critical functions, and improves testability by allowing dependency injection in the SSH connection logic. The most important changes are grouped below by theme.
Error handling improvements:
cmd/root.goto useRunEfor the root command, returning errors instead of callingos.Exit, and updated theExecutefunction to return errors. This allows errors to be handled gracefully and improves testability. [1] [2] [3] [4] [5] [6]main.goto handle errors fromcmd.Execute()by printing the error and exiting with a non-zero status.Test coverage additions:
cmd/root_test.go.cmd/hosts_test.go.internal/shell/model_test.go, as well as for shell view rendering ininternal/shell/view_test.go. [1] [2]internal/sshConn/message_test.goandinternal/sshConn/output_test.go. [1] [2] [3]internal/sshConn/ssh_test.go.Testability enhancements:
internal/sshConn/message.goto allow injection of connection, session, and worker functions, making it easier to stub dependencies in tests. [1] [2] [3] [4]