This repository has been archived by the owner on Oct 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 52
/
batch_disposition_test.go
71 lines (58 loc) · 1.82 KB
/
batch_disposition_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package servicebus
import (
"context"
"fmt"
"testing"
"github.com/Azure/azure-amqp-common-go/v3/uuid"
"github.com/stretchr/testify/assert"
)
func TestBatchDispositionIterator(t *testing.T) {
count := 20
fetched := 0
lockIDs := []*uuid.UUID{}
for i := count; i > 0; i-- {
lockIDs = append(lockIDs, &uuid.UUID{})
}
bdi := &BatchDispositionIterator{
LockTokenIDs: lockIDs,
}
assert.Equal(t, 0, bdi.cursor)
for !bdi.Done() {
if uuid := bdi.Next(); uuid != nil {
fetched++
}
}
assert.Equal(t, count, fetched)
}
func TestBatchDispositionUnsupportedStatus(t *testing.T) {
status := MessageStatus(suspendedDisposition)
id := uuid.UUID{}
bdi := BatchDispositionIterator{
LockTokenIDs: []*uuid.UUID{
&id, &id, &id,
},
Status: status,
}
subscription := Subscription{
receivingEntity: newReceivingEntity(newEntity("foo", "bar", nil)),
}
err := subscription.SendBatchDisposition(context.Background(), bdi)
be := err.(*BatchDispositionError)
assert.NotNil(t, be, fmt.Sprintf("Wrong error type %T", err))
assert.EqualErrorf(t, err, fmt.Sprintf("Operation failed, %d error(s) reported.", len(be.Errors)), err.Error())
for _, innerErr := range be.Errors {
assert.NotNil(t, innerErr.UnWrap(), "Unwrapped error is nil")
assert.EqualErrorf(t, innerErr, "unsupported bulk disposition status \"suspended\"", innerErr.Error())
}
}
func TestBatchDispositiondoUpdateNoError(t *testing.T) {
//want done to return immediately on a call to Done
//so no error can be generated, we can do that by
//placing an empty slice for the lock tokens
bdi := BatchDispositionIterator{
LockTokenIDs: []*uuid.UUID{},
}
//using nil for the entity connector as it will never be called
result := bdi.doUpdate(context.Background(), nil)
assert.Nil(t, result, fmt.Sprintf("Expected a nil error to be returned got %v", result))
}