Add ErrResourceUnalocated and update tests

This commit is contained in:
TeoV
2018-01-12 13:41:26 +02:00
committed by Dan Christian Bogos
parent 63c496c1a1
commit a653517f5b
3 changed files with 11 additions and 4 deletions

View File

@@ -221,7 +221,7 @@ func testV1RsTTL0(t *testing.T) {
Units: 2,
}
if err := rlsV1Rpc.Call(utils.ResourceSv1AllocateResource, argsRU, &reply); err == nil ||
err.Error() != utils.ErrResourceUnavailable.Error() {
err.Error() != utils.ErrResourceUnalocated.Error() {
t.Error(err)
}
// make sure no usage was recorded
@@ -330,7 +330,8 @@ func testV1RsAllocateResource(t *testing.T) {
"Destination": "1002"},
}, Units: 1,
}
if err := rlsV1Rpc.Call(utils.ResourceSv1AllocateResource, argsRU, &reply); err == nil || err.Error() != utils.ErrResourceUnavailable.Error() {
if err := rlsV1Rpc.Call(utils.ResourceSv1AllocateResource,
argsRU, &reply); err == nil || err.Error() != utils.ErrResourceUnalocated.Error() {
t.Error(err)
}
eAllocationMsg = "ResGroup1"
@@ -386,7 +387,7 @@ func testV1RsAuthorizeResources(t *testing.T) {
Units: 7,
}
if err := rlsV1Rpc.Call(utils.ResourceSv1AuthorizeResources,
argsRU, &reply); err.Error() != utils.ErrResourceUnavailable.Error() {
argsRU, &reply); err.Error() != utils.ErrResourceUnauthorized.Error() {
t.Error(err)
}
}

View File

@@ -549,6 +549,7 @@ func (rS *ResourceService) V1AuthorizeResources(args utils.ArgRSv1ResourceUsage,
ID: args.UsageID,
Units: args.Units}, true); err != nil {
if err == utils.ErrResourceUnavailable {
err = utils.ErrResourceUnauthorized
cache.Set(utils.EventResourcesPrefix+args.UsageID, nil, true, "")
return
}
@@ -574,7 +575,10 @@ func (rS *ResourceService) V1AllocateResource(args utils.ArgRSv1ResourceUsage, r
alcMsg, err := mtcRLs.allocateResource(
&ResourceUsage{Tenant: args.CGREvent.Tenant, ID: args.UsageID, Units: args.Units}, false)
if err != nil {
return err
if err == utils.ErrResourceUnavailable {
err = utils.ErrResourceUnalocated
}
return
}
// index it for matching out of cache

View File

@@ -44,6 +44,8 @@ var (
ErrInsufficientCredit = errors.New("INSUFFICIENT_CREDIT")
ErrNotConvertible = errors.New("NOT_CONVERTIBLE")
ErrResourceUnavailable = errors.New("RESOURCE_UNAVAILABLE")
ErrResourceUnauthorized = errors.New("RESOURCE_UNAUTHORIZED")
ErrResourceUnalocated = errors.New("RESOURCE_UNALOCATED")
ErrNoActiveSession = errors.New("NO_ACTIVE_SESSION")
ErrPartiallyExecuted = errors.New("PARTIALLY_EXECUTED")
ErrMaxUsageExceeded = errors.New("MAX_USAGE_EXCEEDED")