Skip to content

Commit

Permalink
feat: remove Result struct
Browse files Browse the repository at this point in the history
  • Loading branch information
vvatanabe committed Dec 9, 2023
1 parent 48ba250 commit 80ef6cf
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 70 deletions.
34 changes: 2 additions & 32 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ type SendMessageInput[T any] struct {
}

type SendMessageOutput[T any] struct {
*Result
Message *Message[T] `json:"-"`
}

Expand Down Expand Up @@ -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
}
Expand All @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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"`
}
27 changes: 1 addition & 26 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 0 additions & 7 deletions dynamomq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions internal/cmd/interactive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
3 changes: 0 additions & 3 deletions internal/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down

0 comments on commit 80ef6cf

Please sign in to comment.