mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-19 22:28:45 +05:00
Updated resources unit tests
This commit is contained in:
committed by
Dan Christian Bogos
parent
ca7f354434
commit
f3ff3d3023
@@ -297,7 +297,7 @@ func (rs Resources) resIDsMp() (mp utils.StringSet) {
|
||||
return mp
|
||||
}
|
||||
|
||||
func (rs Resources) tenatIDs() []string {
|
||||
func (rs Resources) tenantIDs() []string {
|
||||
ids := make([]string, len(rs))
|
||||
for i, r := range rs {
|
||||
ids[i] = r.TenantID()
|
||||
@@ -453,6 +453,7 @@ func (rS *ResourceService) storeResources(ctx *context.Context) {
|
||||
rIf, ok := Cache.Get(utils.CacheResources, rID)
|
||||
if !ok || rIf == nil {
|
||||
utils.Logger.Warning(fmt.Sprintf("<%s> failed retrieving from cache resource with ID: %s", utils.ResourceS, rID))
|
||||
continue
|
||||
}
|
||||
r := rIf.(*Resource)
|
||||
r.lock(utils.EmptyString)
|
||||
@@ -562,7 +563,6 @@ func (rS *ResourceService) matchingResourcesForEvent(ctx *context.Context, tnt s
|
||||
err = errCh
|
||||
}
|
||||
}
|
||||
return
|
||||
}()
|
||||
|
||||
} else { // select the resourceIDs out of dataDB
|
||||
|
||||
@@ -137,7 +137,7 @@ func TestResourceTotalUsage1(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
result := testStruct.totalUsage()
|
||||
result := testStruct.TotalUsage()
|
||||
if reflect.DeepEqual(3, result) {
|
||||
t.Errorf("\nExpecting <3>,\n Received <%+v>", result)
|
||||
}
|
||||
@@ -433,7 +433,7 @@ func TestResourceUsedUnits(t *testing.T) {
|
||||
ru1.ID: ru1,
|
||||
}
|
||||
r1.tUsage = nil
|
||||
if usedUnits := r1.totalUsage(); usedUnits != 1 {
|
||||
if usedUnits := r1.TotalUsage(); usedUnits != 1 {
|
||||
t.Errorf("Expecting: %+v, received: %+v", 1, usedUnits)
|
||||
}
|
||||
}
|
||||
@@ -603,7 +603,7 @@ func TestResourceClearUsage(t *testing.T) {
|
||||
if len(r1.Usages) != 0 {
|
||||
t.Errorf("Expecting: %+v, received: %+v", 0, len(r1.Usages))
|
||||
}
|
||||
if r1.totalUsage() != 0 {
|
||||
if r1.TotalUsage() != 0 {
|
||||
t.Errorf("Expecting: %+v, received: %+v", 0, r1.tUsage)
|
||||
}
|
||||
if err := r2.clearUsage(ru2.ID); err != nil {
|
||||
@@ -1223,6 +1223,7 @@ func TestResourceMatchingResourcesForEvent(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Errorf("Error: %+v", err)
|
||||
}
|
||||
mres.unlock()
|
||||
if !reflect.DeepEqual(resourceTest[0].Tenant, mres[0].Tenant) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", resourceTest[0].Tenant, mres[0].Tenant)
|
||||
} else if !reflect.DeepEqual(resourceTest[0].ID, mres[0].ID) {
|
||||
@@ -1236,6 +1237,7 @@ func TestResourceMatchingResourcesForEvent(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Errorf("Error: %+v", err)
|
||||
}
|
||||
mres.unlock()
|
||||
if !reflect.DeepEqual(resourceTest[1].Tenant, mres[0].Tenant) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", resourceTest[1].Tenant, mres[0].Tenant)
|
||||
} else if !reflect.DeepEqual(resourceTest[1].ID, mres[0].ID) {
|
||||
@@ -1249,6 +1251,7 @@ func TestResourceMatchingResourcesForEvent(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Errorf("Error: %+v", err)
|
||||
}
|
||||
mres.unlock()
|
||||
if !reflect.DeepEqual(resourceTest[2].Tenant, mres[0].Tenant) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", resourceTest[2].Tenant, mres[0].Tenant)
|
||||
} else if !reflect.DeepEqual(resourceTest[2].ID, mres[0].ID) {
|
||||
@@ -1442,6 +1445,7 @@ func TestResourceUsageTTLCase1(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Errorf("Error: %+v", err)
|
||||
}
|
||||
mres.unlock()
|
||||
if !reflect.DeepEqual(resourceTest[0].Tenant, mres[0].Tenant) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", resourceTest[0].Tenant, mres[0].Tenant)
|
||||
} else if !reflect.DeepEqual(resourceTest[0].ID, mres[0].ID) {
|
||||
@@ -1635,6 +1639,7 @@ func TestResourceUsageTTLCase2(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Errorf("Error: %+v", err)
|
||||
}
|
||||
mres.unlock()
|
||||
if !reflect.DeepEqual(resourceTest[0].Tenant, mres[0].Tenant) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", resourceTest[0].Tenant, mres[0].Tenant)
|
||||
} else if !reflect.DeepEqual(resourceTest[0].ID, mres[0].ID) {
|
||||
@@ -1828,6 +1833,7 @@ func TestResourceUsageTTLCase3(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Errorf("Error: %+v", err)
|
||||
}
|
||||
mres.unlock()
|
||||
if !reflect.DeepEqual(resourceTest[0].Tenant, mres[0].Tenant) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", resourceTest[0].Tenant, mres[0].Tenant)
|
||||
} else if !reflect.DeepEqual(resourceTest[0].ID, mres[0].ID) {
|
||||
@@ -2022,6 +2028,7 @@ func TestResourceUsageTTLCase4(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Errorf("Error: %+v", err)
|
||||
}
|
||||
mres.unlock()
|
||||
if !reflect.DeepEqual(resourceTest[0].Tenant, mres[0].Tenant) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", resourceTest[0].Tenant, mres[0].Tenant)
|
||||
} else if !reflect.DeepEqual(resourceTest[0].ID, mres[0].ID) {
|
||||
@@ -2410,6 +2417,7 @@ func TestResourceMatchWithIndexFalse(t *testing.T) {
|
||||
t.Errorf("Error: %+v", err)
|
||||
}
|
||||
|
||||
mres.unlock()
|
||||
if !reflect.DeepEqual(resourceTest[0].Tenant, mres[0].Tenant) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", resourceTest[0].Tenant, mres[0].Tenant)
|
||||
} else if !reflect.DeepEqual(resourceTest[0].ID, mres[0].ID) {
|
||||
@@ -2423,6 +2431,7 @@ func TestResourceMatchWithIndexFalse(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Errorf("Error: %+v", err)
|
||||
}
|
||||
mres.unlock()
|
||||
if !reflect.DeepEqual(resourceTest[1].Tenant, mres[0].Tenant) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", resourceTest[1].Tenant, mres[0].Tenant)
|
||||
} else if !reflect.DeepEqual(resourceTest[1].ID, mres[0].ID) {
|
||||
@@ -2436,6 +2445,7 @@ func TestResourceMatchWithIndexFalse(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Errorf("Error: %+v", err)
|
||||
}
|
||||
mres.unlock()
|
||||
if !reflect.DeepEqual(resourceTest[2].Tenant, mres[0].Tenant) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", resourceTest[2].Tenant, mres[0].Tenant)
|
||||
} else if !reflect.DeepEqual(resourceTest[2].ID, mres[0].ID) {
|
||||
@@ -2636,6 +2646,7 @@ func TestResourceCaching(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Errorf("Error: %+v", err)
|
||||
}
|
||||
mres.unlock()
|
||||
if !reflect.DeepEqual(resources[0].Tenant, mres[0].Tenant) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", resources[0].Tenant, mres[0].Tenant)
|
||||
} else if !reflect.DeepEqual(resources[0].ID, mres[0].ID) {
|
||||
@@ -3319,7 +3330,7 @@ func TestResourcesProcessThresholdsNoConns(t *testing.T) {
|
||||
}
|
||||
opts := map[string]interface{}{}
|
||||
|
||||
err := rS.processThresholds(context.TODO(), r, opts)
|
||||
err := rS.processThresholds(context.TODO(), Resources{r}, opts)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("\nexpected nil, received %+v", err)
|
||||
@@ -3380,7 +3391,7 @@ func TestResourcesProcessThresholdsOK(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
err := rS.processThresholds(context.TODO(), r, nil)
|
||||
err := rS.processThresholds(context.TODO(), Resources{r}, nil)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("\nexpected nil, received %+v", err)
|
||||
@@ -3454,8 +3465,8 @@ func TestResourcesProcessThresholdsCallErr(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
experr := utils.ErrExists
|
||||
err := rS.processThresholds(context.TODO(), r, nil)
|
||||
experr := utils.ErrPartiallyExecuted
|
||||
err := rS.processThresholds(context.TODO(), Resources{r}, nil)
|
||||
|
||||
if err == nil || err != experr {
|
||||
t.Errorf("\nexpected: <%+v>, \nreceived: <%+v>", experr, err)
|
||||
@@ -3481,7 +3492,7 @@ func TestResourcesProcessThresholdsThdConnMetaNone(t *testing.T) {
|
||||
}
|
||||
opts := map[string]interface{}{}
|
||||
|
||||
err := rS.processThresholds(context.TODO(), r, opts)
|
||||
err := rS.processThresholds(context.TODO(), Resources{r}, opts)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("\nexpected nil, received: %+v", err)
|
||||
@@ -5489,8 +5500,8 @@ func TestResourcesV1AllocateResourcesProcessThErr(t *testing.T) {
|
||||
var reply string
|
||||
|
||||
if err := rS.V1AllocateResources(context.Background(), args, &reply); err == nil ||
|
||||
err != utils.ErrExists {
|
||||
t.Errorf("expected: <%+v>, \nreceived: <%+v>", utils.ErrExists, err)
|
||||
err != utils.ErrPartiallyExecuted {
|
||||
t.Errorf("expected: <%+v>, \nreceived: <%+v>", utils.ErrPartiallyExecuted, err)
|
||||
}
|
||||
dm.DataDB().Flush(utils.EmptyString)
|
||||
}
|
||||
@@ -6016,8 +6027,8 @@ func TestResourcesV1ReleaseResourcesProcessThErr(t *testing.T) {
|
||||
}
|
||||
|
||||
if err := rS.V1ReleaseResources(context.Background(), args, &reply); err == nil ||
|
||||
err != utils.ErrExists {
|
||||
t.Errorf("expected: <%+v>, \nreceived: <%+v>", utils.ErrExists, err)
|
||||
err != utils.ErrPartiallyExecuted {
|
||||
t.Errorf("expected: <%+v>, \nreceived: <%+v>", utils.ErrPartiallyExecuted, err)
|
||||
}
|
||||
|
||||
dm.DataDB().Flush(utils.EmptyString)
|
||||
|
||||
Reference in New Issue
Block a user