Skip to content

Commit

Permalink
tests: adapt unit tests to cover this case
Browse files Browse the repository at this point in the history
  • Loading branch information
aruiz14 committed Jun 28, 2024
1 parent 1fdf480 commit a409494
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions session_serve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ func TestSession_closeConnection(t *testing.T) {
s := setupDummySession(t, 0)
var msg *message
s.conn = &fakeWSConn{
writeMessageCallback: func(msgType int, _ time.Time, data []byte) (err error) {
writeMessageCallback: func(msgType int, deadline time.Time, data []byte) (err error) {
if !deadline.IsZero() && deadline.Before(time.Now()) {
return errors.New("deadline exceeded")
}
msg, err = newServerMessage(bytes.NewReader(data))
return
},
Expand All @@ -118,13 +121,16 @@ func TestSession_closeConnection(t *testing.T) {
conn := newConnection(connID, s, "test", "test")
s.addConnection(connID, conn)

// Ensure Error message is sent regardless of the WriteDeadline value, see https://github.com/rancher/remotedialer/pull/79
_ = conn.SetWriteDeadline(time.Now())

expectedErr := errors.New("connection closed")
s.closeConnection(connID, expectedErr)

if s.getConnection(connID) != nil {
t.Errorf("connection was not closed correctly")
}
if conn.err == nil {
if conn.err == nil || msg == nil {
t.Fatal("message not sent on closed connection")
} else if msg.messageType != Error {
t.Errorf("incorrect message type sent")
Expand Down

0 comments on commit a409494

Please sign in to comment.