From 80ef6cf5d9059ec669a9a1dde5901eb8181adb0a Mon Sep 17 00:00:00 2001 From: vvatanabe Date: Sat, 9 Dec 2023 17:43:07 +0900 Subject: [PATCH] feat: remove Result struct --- client.go | 34 ++------------------------------ client_test.go | 27 +------------------------ dynamomq_test.go | 7 ------- internal/cmd/interactive_test.go | 2 -- internal/mock/mock.go | 3 --- 5 files changed, 3 insertions(+), 70 deletions(-) diff --git a/client.go b/client.go index b0eaa02..7ab32a7 100644 --- a/client.go +++ b/client.go @@ -206,7 +206,6 @@ type SendMessageInput[T any] struct { } type SendMessageOutput[T any] struct { - *Result Message *Message[T] `json:"-"` } @@ -237,12 +236,6 @@ func (c *ClientImpl[T]) SendMessage(ctx context.Context, params *SendMessageInpu return &SendMessageOutput[T]{}, err } return &SendMessageOutput[T]{ - Result: &Result{ - ID: message.ID, - Status: message.GetStatus(now), - UpdatedAt: message.UpdatedAt, - Version: message.Version, - }, Message: message, }, nil } @@ -254,9 +247,7 @@ type ReceiveMessageInput struct { // ReceiveMessageOutput represents the result for the ReceiveMessage() API call. type ReceiveMessageOutput[T any] struct { - *Result // Embedded type for inheritance-like behavior in Go - ReceivedAt string `json:"received_at"` - ReceivedMessage *Message[T] `json:"-"` + ReceivedMessage *Message[T] } // ReceiveMessage retrieves and processes a message from a DynamoDB-based queue using the generic type T. @@ -285,13 +276,6 @@ func (c *ClientImpl[T]) ReceiveMessage(ctx context.Context, params *ReceiveMessa } return &ReceiveMessageOutput[T]{ - Result: &Result{ - ID: updated.ID, - Status: updated.GetStatus(c.clock.Now()), - UpdatedAt: updated.UpdatedAt, - Version: updated.Version, - }, - ReceivedAt: updated.ReceivedAt, ReceivedMessage: updated, }, nil } @@ -392,8 +376,7 @@ type ChangeMessageVisibilityInput struct { // ChangeMessageVisibilityOutput represents the result for the ChangeMessageVisibility() API call. type ChangeMessageVisibilityOutput[T any] struct { - *Result // Embedded type for inheritance-like behavior in Go - Message *Message[T] `json:"-"` + Message *Message[T] } // ChangeMessageVisibility changes the visibility of a specific message in a DynamoDB-based queue. @@ -429,12 +412,6 @@ func (c *ClientImpl[T]) ChangeMessageVisibility(ctx context.Context, params *Cha return &ChangeMessageVisibilityOutput[T]{}, err } return &ChangeMessageVisibilityOutput[T]{ - Result: &Result{ - ID: retried.ID, - Status: retried.GetStatus(c.clock.Now()), - UpdatedAt: retried.UpdatedAt, - Version: retried.Version, - }, Message: retried, }, nil } @@ -940,10 +917,3 @@ func handleDynamoDBError(err error) error { func secToDur(sec int) time.Duration { return time.Duration(sec) * time.Second } - -type Result struct { - ID string `json:"id"` - Status Status `json:"status"` - UpdatedAt string `json:"updated_at"` - Version int `json:"version"` -} diff --git a/client_test.go b/client_test.go index e51dc23..f5afe97 100644 --- a/client_test.go +++ b/client_test.go @@ -218,12 +218,6 @@ func TestDynamoMQClientSendMessage(t *testing.T) { Data: test.NewMessageData("A-101"), }, want: &dynamomq.SendMessageOutput[test.MessageData]{ - Result: &dynamomq.Result{ - ID: "A-101", - Status: dynamomq.StatusReady, - UpdatedAt: clock.FormatRFC3339Nano(test.DefaultTestDate), - Version: 1, - }, Message: func() *dynamomq.Message[test.MessageData] { s := NewTestMessageItemAsReady("A-101", test.DefaultTestDate) return s @@ -242,12 +236,6 @@ func TestDynamoMQClientSendMessage(t *testing.T) { DelaySeconds: 10, }, want: &dynamomq.SendMessageOutput[test.MessageData]{ - Result: &dynamomq.Result{ - ID: "A-101", - Status: dynamomq.StatusReady, - UpdatedAt: clock.FormatRFC3339Nano(test.DefaultTestDate), - Version: 1, - }, Message: func() *dynamomq.Message[test.MessageData] { s := NewTestMessageItemAsReady("A-101", test.DefaultTestDate) s.SentAt = clock.FormatRFC3339Nano(test.DefaultTestDate.Add(10 * time.Second)) @@ -297,13 +285,6 @@ func TestDynamoMQClientReceiveMessage(t *testing.T) { m.Version = 2 m.ReceiveCount = 1 r := &dynamomq.ReceiveMessageOutput[test.MessageData]{ - Result: &dynamomq.Result{ - ID: m.ID, - Status: dynamomq.StatusProcessing, - UpdatedAt: m.UpdatedAt, - Version: m.Version, - }, - ReceivedAt: m.ReceivedAt, ReceivedMessage: m, } return r @@ -364,7 +345,7 @@ func testDynamoMQClientReceiveMessageSequence(t *testing.T, useFIFO bool) { test.AssertError(t, err, &dynamomq.EmptyQueueError{}, fmt.Sprintf("ReceiveMessage() [%d-3]", i)) _, err = client.DeleteMessage(ctx, &dynamomq.DeleteMessageInput{ - ID: result.ID, + ID: result.ReceivedMessage.ID, }) test.AssertError(t, err, nil, fmt.Sprintf("DeleteMessage() [%d]", i)) } @@ -404,12 +385,6 @@ func TestDynamoMQClientChangeMessageVisibility(t *testing.T) { visibilityTimeout: -1, }, want: &dynamomq.ChangeMessageVisibilityOutput[test.MessageData]{ - Result: &dynamomq.Result{ - ID: "A-101", - Status: dynamomq.StatusReady, - UpdatedAt: clock.FormatRFC3339Nano(now), - Version: 2, - }, Message: func() *dynamomq.Message[test.MessageData] { m := NewTestMessageItemAsProcessing("A-101", now) ts := clock.FormatRFC3339Nano(now) diff --git a/dynamomq_test.go b/dynamomq_test.go index 7cba69e..74105e4 100644 --- a/dynamomq_test.go +++ b/dynamomq_test.go @@ -50,13 +50,6 @@ func NewMessageFromReadyToProcessing(id string, m.ReceiveCount = 1 m.InvisibleUntilAt = clock.FormatRFC3339Nano(processingTime.Add(constant.DefaultVisibilityTimeout)) r := &dynamomq.ReceiveMessageOutput[test.MessageData]{ - Result: &dynamomq.Result{ - ID: m.ID, - Status: dynamomq.StatusProcessing, - UpdatedAt: m.UpdatedAt, - Version: m.Version, - }, - ReceivedAt: m.ReceivedAt, ReceivedMessage: m, } return r diff --git a/internal/cmd/interactive_test.go b/internal/cmd/interactive_test.go index 17660d2..edafa0f 100644 --- a/internal/cmd/interactive_test.go +++ b/internal/cmd/interactive_test.go @@ -297,8 +297,6 @@ func TestRunInteractiveReceiveShouldReturnError(t *testing.T) { Client: mock.Client[any]{ ReceiveMessageFunc: func(ctx context.Context, params *dynamomq.ReceiveMessageInput) (*dynamomq.ReceiveMessageOutput[any], error) { return &dynamomq.ReceiveMessageOutput[any]{ - Result: &dynamomq.Result{}, - ReceivedAt: "", ReceivedMessage: dynamomq.NewMessage[any]("A-101", test.NewMessageData("A-101"), clock.Now()), }, nil }, diff --git a/internal/mock/mock.go b/internal/mock/mock.go index dc36752..1866f8e 100644 --- a/internal/mock/mock.go +++ b/internal/mock/mock.go @@ -105,19 +105,16 @@ func (m Client[T]) ReplaceMessage(ctx context.Context, params *dynamomq.ReplaceM var SuccessfulMockClient = &Client[any]{ SendMessageFunc: func(ctx context.Context, params *dynamomq.SendMessageInput[any]) (*dynamomq.SendMessageOutput[any], error) { return &dynamomq.SendMessageOutput[any]{ - Result: &dynamomq.Result{}, Message: &dynamomq.Message[any]{}, }, nil }, ReceiveMessageFunc: func(ctx context.Context, params *dynamomq.ReceiveMessageInput) (*dynamomq.ReceiveMessageOutput[any], error) { return &dynamomq.ReceiveMessageOutput[any]{ - Result: &dynamomq.Result{}, ReceivedMessage: &dynamomq.Message[any]{}, }, nil }, ChangeMessageVisibilityFunc: func(ctx context.Context, params *dynamomq.ChangeMessageVisibilityInput) (*dynamomq.ChangeMessageVisibilityOutput[any], error) { return &dynamomq.ChangeMessageVisibilityOutput[any]{ - Result: &dynamomq.Result{}, Message: &dynamomq.Message[any]{}, }, nil },