From 87aa2a369ffd36d9a59a0d5010c71040d2d1aef5 Mon Sep 17 00:00:00 2001 From: Vladimir Rachkin Date: Tue, 5 Nov 2024 10:13:10 +0300 Subject: [PATCH] Add test for ErrorMessage --- pkg/message/error_message.go | 2 +- pkg/message/message_test.go | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/pkg/message/error_message.go b/pkg/message/error_message.go index c483e79..4cc6abc 100644 --- a/pkg/message/error_message.go +++ b/pkg/message/error_message.go @@ -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...) diff --git a/pkg/message/message_test.go b/pkg/message/message_test.go index 2ea1c85..3aa6e49 100644 --- a/pkg/message/message_test.go +++ b/pkg/message/message_test.go @@ -2,6 +2,7 @@ package message_test import ( "encoding/binary" + "fmt" "testing" "github.com/stretchr/testify/assert" @@ -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) +}