Skip to content

Commit

Permalink
Add test for ErrorMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
robozmey committed Nov 5, 2024
1 parent 1f778c8 commit 87aa2a3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/message/error_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (c *ErrorMessage) Encode() []byte {
encodedMessage = append(encodedMessage, byteLen...)
encodedMessage = append(encodedMessage, byteError...)

byteMessage := []byte(c.Error)
byteMessage := []byte(c.Message)
binary.BigEndian.PutUint64(byteLen, uint64(len(byteMessage)))
encodedMessage = append(encodedMessage, byteLen...)
encodedMessage = append(encodedMessage, byteMessage...)
Expand Down
20 changes: 20 additions & 0 deletions pkg/message/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package message_test

import (
"encoding/binary"
"fmt"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -303,3 +304,22 @@ func TestDeleteMsg(t *testing.T) {
assert.True(msg2.Confirm)
assert.True(msg2.Garbage)
}

func TestErrorMsg(t *testing.T) {
assert := assert.New(t)

errString := "could not list objects: NoCredentialProviders: no valid providers in chain."
messageString := "Deprecated. For verbose messaging see aws.Config.CredentialsChainVerboseErrors"
err := fmt.Errorf("%s", errString)

msg := message.NewErrorMessage(err, messageString)
body := msg.Encode()

assert.Equal(body[8], byte(message.MessageTypeError))

msg2 := message.ErrorMessage{}
msg2.Decode(body[8:])

assert.Equal(errString, msg2.Error)
assert.Equal(messageString, msg2.Message)
}

0 comments on commit 87aa2a3

Please sign in to comment.