Skip to content
This repository was archived by the owner on Oct 12, 2023. It is now read-only.

Commit e8de306

Browse files
authored
Merge pull request #148 from JakeBjorke/batch-disposition-update
Batch disposition calls return nil rather than 0 value
2 parents bc449e6 + 7332028 commit e8de306

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

batch_disposition.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ func (bdi *BatchDispositionIterator) Next() (uuid *uuid.UUID) {
6565
return uuid
6666
}
6767

68-
func (bdi *BatchDispositionIterator) doUpdate(ctx context.Context, ec entityConnector) BatchDispositionError {
69-
batchError := BatchDispositionError{}
68+
func (bdi *BatchDispositionIterator) doUpdate(ctx context.Context, ec entityConnector) *BatchDispositionError {
69+
var batchError *BatchDispositionError
7070
for !bdi.Done() {
7171
if id := bdi.Next(); id != nil {
7272
m := &Message{
@@ -75,6 +75,9 @@ func (bdi *BatchDispositionIterator) doUpdate(ctx context.Context, ec entityConn
7575
m.ec = ec
7676
err := m.sendDisposition(ctx, bdi.Status)
7777
if err != nil {
78+
if batchError == nil {
79+
batchError = new(BatchDispositionError)
80+
}
7881
batchError.Errors = append(batchError.Errors, DispositionError{
7982
LockTokenID: id,
8083
err: err,

batch_disposition_test.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func TestBatchDispositionUnsupportedStatus(t *testing.T) {
4646
receivingEntity: newReceivingEntity(newEntity("foo", "bar", nil)),
4747
}
4848
err := subscription.SendBatchDisposition(context.Background(), bdi)
49-
be := err.(BatchDispositionError)
49+
be := err.(*BatchDispositionError)
5050
assert.NotNil(t, be, fmt.Sprintf("Wrong error type %T", err))
5151
assert.EqualErrorf(t, err, fmt.Sprintf("Operation failed, %d error(s) reported.", len(be.Errors)), err.Error())
5252

@@ -55,3 +55,17 @@ func TestBatchDispositionUnsupportedStatus(t *testing.T) {
5555
assert.EqualErrorf(t, innerErr, "unsupported bulk disposition status \"suspended\"", innerErr.Error())
5656
}
5757
}
58+
59+
func TestBatchDispositiondoUpdateNoError(t *testing.T) {
60+
//want done to return immediately on a call to Done
61+
//so no error can be generated, we can do that by
62+
//placing an empty slice for the lock tokens
63+
bdi := BatchDispositionIterator{
64+
LockTokenIDs: []*uuid.UUID{},
65+
}
66+
67+
//using nil for the entity connector as it will never be called
68+
result := bdi.doUpdate(context.Background(), nil)
69+
70+
assert.Nil(t, result, fmt.Sprintf("Expected a nil error to be returned got %v", result))
71+
}

0 commit comments

Comments
 (0)