chore(transport/ssh): Increase test coverage (+bug fixes) #109
No reviewers
Labels
No labels
breaking-change
bug
dependencies
duplicate
enhancement
go
good first issue
help wanted
invalid
investigation
proposal
proposal-accepted
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
nemith/netconf!109
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "brb/push-ovpyszutzvwz"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The original transport/ssh tests were limited. This expands the test coverage to more coverage. In the process a couple bugs were found and fixed.
Pull request overview
This PR significantly expands test coverage for the SSH transport module from limited coverage to 82.2%, while fixing two critical bugs discovered during the testing process:
newTransportfails, the SSH client is now properly closed to prevent resource leaksClose()call in the error pathKey Changes
testServerhelper using dynamically generated ED25519 keysnewTransportfails by ensuring the client connection is closederrors.Jointo properly aggregate multiple close errorsReviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.
errors.Join, and updated context handling commentstestServerhelper, added 5 new test cases covering error scenarios, and improved test structure for better maintainability💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
@ -22,7 +23,7 @@ type Transport struct {// set to true if the transport is managing the underlying ssh connectionThe field name "mangedConn" contains a typo - it should be "managedConn" with an 'a'. This typo appears in the field declaration and is consistently used throughout the file.
@ -105,10 +112,10 @@ func newTransport(client *ssh.Client, managed bool) (*Transport, error) {}The field name "mangedConn" contains a typo - it should be "managedConn" with an 'a'.
@ -118,22 +125,23 @@ func newTransport(client *ssh.Client, managed bool) (*Transport, error) {// with Dial then then underlying ssh.Client is closed as well. If not onlyThe word "connnection" has an extra 'n' - it should be "connection".
The field name "mangedConn" contains a typo - it should be "managedConn" with an 'a'.
@ -134,2 +132,3 @@r, err := tr.MsgReader()assert.NoError(t, err)require.NoError(t, err)greeting, _ := io.ReadAll(r)Error handling is incomplete - the returned errors from io.WriteString and io.ReadAll are being ignored. While this may be acceptable in a test handler, it's better to check these errors or explicitly ignore them with a comment explaining why.
Error handling is incomplete - the returned errors from tr.MsgReader(), io.ReadAll, tr.MsgWriter(), io.WriteString, w.Close(), and tr.Close() are being ignored. While this may be acceptable in a test, it's better to check these errors or use require.NoError/assert.NoError to catch unexpected failures.
The return value from io.ReadAll is being ignored. While this may be intentional in this test context, it's better to explicitly check the error or add a comment explaining why it's safe to ignore.