2019-02-13 18:17:32 +03:00
|
|
|
package servicebus
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2019-05-29 22:39:19 +03:00
|
|
|
"fmt"
|
2019-02-13 18:17:32 +03:00
|
|
|
"testing"
|
|
|
|
|
2019-12-16 20:58:02 +03:00
|
|
|
"github.com/Azure/azure-amqp-common-go/v3/uuid"
|
2019-02-13 18:17:32 +03:00
|
|
|
"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)
|
2019-03-13 01:46:25 +03:00
|
|
|
id := uuid.UUID{}
|
2019-02-13 18:17:32 +03:00
|
|
|
bdi := BatchDispositionIterator{
|
|
|
|
LockTokenIDs: []*uuid.UUID{
|
2019-05-29 22:39:19 +03:00
|
|
|
&id, &id, &id,
|
2019-02-13 18:17:32 +03:00
|
|
|
},
|
|
|
|
Status: status,
|
|
|
|
}
|
|
|
|
|
2019-07-13 00:16:25 +03:00
|
|
|
subscription := Subscription{
|
|
|
|
receivingEntity: newReceivingEntity(newEntity("foo", "bar", nil)),
|
|
|
|
}
|
2019-05-29 22:39:19 +03:00
|
|
|
err := subscription.SendBatchDisposition(context.Background(), bdi)
|
2019-09-12 03:36:35 +03:00
|
|
|
be := err.(*BatchDispositionError)
|
2019-05-29 22:39:19 +03:00
|
|
|
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())
|
|
|
|
}
|
2019-02-13 18:17:32 +03:00
|
|
|
}
|
2019-09-12 03:36:35 +03:00
|
|
|
|
|
|
|
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))
|
|
|
|
}
|