mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Updated resources unit tests
This commit is contained in:
committed by
Dan Christian Bogos
parent
2a6f2c140a
commit
d8e44865b2
@@ -299,7 +299,6 @@
|
||||
// "enabled": false, // enable Rating/Accounting service: <true|false>
|
||||
// "thresholds_conns": [], // connections to ThresholdS for account/balance updates, empty to disable thresholds functionality: <""|*internal|$rpc_conns_id>
|
||||
// "stats_conns": [], // connections to StatS for account/balance updates, empty to disable stats functionality: <""|*internal|$rpc_conns_id>
|
||||
// "caches_conns":["*internal"], // connections to CacheS for account/balance updates
|
||||
// "rp_subject_prefix_matching": false, // enables prefix matching for the rating profile subject
|
||||
// "remove_expired":true, // enables automatic removal of expired balances
|
||||
// "max_computed_usage": { // do not compute usage higher than this, prevents memory overload
|
||||
@@ -314,6 +313,7 @@
|
||||
// "*any": "*zero1ns",
|
||||
// "*voice": "*zero1s"
|
||||
// },
|
||||
|
||||
// },
|
||||
|
||||
|
||||
@@ -348,7 +348,7 @@
|
||||
// "opts": {
|
||||
// // Partial
|
||||
// // "partialPath": "/", // the path were the partial events will be sent
|
||||
// // "partialCacheAction": "*none", // the action that will be executed for the partial CSVs that are not matched<*none|*post_cdr|*dump_to_file>
|
||||
// "partialCacheAction": "*none", // the action that will be executed for the partial CSVs that are not matched<*none|*post_cdr|*dump_to_file>
|
||||
// "partialOrderField": "~*req.AnswerTime", // the field after what the events are order when merged
|
||||
// // "partialcsvFieldSeparator": "," // separator used when dumping the fields
|
||||
|
||||
@@ -413,6 +413,27 @@
|
||||
// // "s3FolderPathProcessed": "", // only for S3 event posting
|
||||
|
||||
// // "s3BucketIDProcessed": "cgrates_cdrs", // the bucket id for S3 readers were the events are sent after they are processed
|
||||
|
||||
// // nats
|
||||
// // "natsJetStream": false, // controls if the nats reader uses the JetStream
|
||||
// // "natsConsumerName": "cgrates", // in case of JetStream the name of the consumer
|
||||
// "natsSubject": "cgrates_cdrs", // the subject from were the events are read
|
||||
// // "natsQueueID": "", // the queue id the consumer listen to
|
||||
// // "natsJWTFile": "", // the path to the JWT file( can be the chained file or the user file)
|
||||
// // "natsSeedFile": "", // the path to the seed files( if the JWT file is mention this is used as seedFile for the JWT user mentioned above)
|
||||
// // "natsCertificateAuthority": "", // the path to a custom certificate authority file( used by tls)
|
||||
// // "natsClientCertificate": "", // the path to a client certificate( used by tls)
|
||||
// // "natsClientKey": "", // the path to a client key( used by tls)
|
||||
// // "natsJetStreamMaxWait": "5s", // the maximum amount of time to wait for a response
|
||||
|
||||
// // "natsJetStreamProcessed": false, // controls if the nats poster uses the JetStream
|
||||
// // "natsSubjectProcessed": "cgrates_cdrs", // the subject were the events are posted
|
||||
// // "natsJWTFileProcessed": "", // the path to the JWT file( can be the chained file or the user file)
|
||||
// // "natsSeedFileProcessed": "", // the path to the seed files( if the JWT file is mention this is used as seedFile for the JWT user mentioned above)
|
||||
// // "natsCertificateAuthorityProcessed": "", // the path to a custom certificate authority file( used by tls)
|
||||
// // "natsClientCertificateProcessed": "", // the path to a client certificate( used by tls)
|
||||
// // "natsClientKeyProcessed": "", // the path to a client key( used by tls)
|
||||
// // "natsJetStreamMaxWaitProcessed": "5s ", // the maximum amount of time to wait for a response
|
||||
// },
|
||||
// "tenant": "", // tenant used by import
|
||||
// "timezone": "", // timezone for timestamps where not specified <""|UTC|Local|$IANA_TZ_DB>
|
||||
@@ -503,6 +524,15 @@
|
||||
// // "s3BucketID": "cgrates_cdrs", // the bucket id for S3 readers from where the events that are exported
|
||||
// // "s3FolderPath": "", // S3FolderPath
|
||||
|
||||
// // Nats
|
||||
// // "natsJetStream": false, // controls if the nats poster uses the JetStream
|
||||
// // "natsSubject": "cgrates_cdrs", // the subject were the events are exported
|
||||
// // "natsJWTFile": "", // the path to the JWT file( can be the chained file or the user file)
|
||||
// // "natsSeedFile": "", // the path to the seed files( if the JWT file is mention this is used as seedFile for the JWT user mentioned above)
|
||||
// // "natsCertificateAuthority": "", // the path to a custom certificate authority file( used by tls)
|
||||
// // "natsClientCertificate": "", // the path to a client certificate( used by tls)
|
||||
// // "natsClientKey": "", // the path to a client key( used by tls)
|
||||
// // "natsJetStreamMaxWait": "5s", // the maximum amount of time to wait for a response
|
||||
// }, // extra options for exporter
|
||||
// "timezone": "", // timezone for timestamps where not specified <""|UTC|Local|$IANA_TZ_DB>
|
||||
// "filters": [], // limit parsing based on the filters
|
||||
@@ -660,6 +690,7 @@
|
||||
// "suffix_indexed_fields": [], // query indexes based on these fields for faster processing
|
||||
// "nested_fields": false, // determines which field is checked when matching indexed filters(true: all; false: only the one on the first level)
|
||||
// "process_runs": 1, // number of run loops when processing event
|
||||
// "any_context": true, // if we match the *any context
|
||||
// },
|
||||
|
||||
|
||||
@@ -977,6 +1008,7 @@
|
||||
// "suffix_indexed_fields": [], // query indexes based on these fields for faster processing
|
||||
// "nested_fields": false, // determines which field is checked when matching indexed filters(true: all; false: only the one on the first level)
|
||||
// "attributes_conns": [], // connections to AttributeS for API authorization, empty to disable auth functionality: <""|*internal|$rpc_conns_id>
|
||||
// "any_subsystem": true, // if we match the *any subsystem
|
||||
// },
|
||||
|
||||
|
||||
@@ -984,13 +1016,13 @@
|
||||
// "rpc":{
|
||||
// "enabled": false,
|
||||
// "registrars_conns": [],
|
||||
// "hosts": [],
|
||||
// "hosts": [],
|
||||
// "refresh_interval": "5m",
|
||||
// },
|
||||
// "dispatchers":{
|
||||
// "enabled": false,
|
||||
// "registrars_conns": [],
|
||||
// "hosts": [],
|
||||
// "hosts": [],
|
||||
// "refresh_interval": "5m",
|
||||
// },
|
||||
// },
|
||||
|
||||
@@ -453,6 +453,7 @@ func (rS *ResourceService) storeResources() {
|
||||
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(tnt string, ev *utils.CGREv
|
||||
err = errCh
|
||||
}
|
||||
}
|
||||
return
|
||||
}()
|
||||
|
||||
} else { // select the resourceIDs out of dataDB
|
||||
|
||||
@@ -135,7 +135,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)
|
||||
}
|
||||
@@ -443,7 +443,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)
|
||||
}
|
||||
}
|
||||
@@ -631,7 +631,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 {
|
||||
@@ -1297,6 +1297,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) {
|
||||
@@ -1310,6 +1311,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) {
|
||||
@@ -1323,6 +1325,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) {
|
||||
@@ -1528,6 +1531,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) {
|
||||
@@ -1733,6 +1737,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) {
|
||||
@@ -1938,6 +1943,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) {
|
||||
@@ -2144,6 +2150,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) {
|
||||
@@ -2571,6 +2578,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) {
|
||||
@@ -2584,6 +2592,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) {
|
||||
@@ -2597,6 +2606,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) {
|
||||
@@ -2817,6 +2827,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) {
|
||||
@@ -3500,7 +3511,7 @@ func TestResourcesProcessThresholdsNoConns(t *testing.T) {
|
||||
}
|
||||
opts := map[string]interface{}{}
|
||||
|
||||
err := rS.processThresholds(r, opts)
|
||||
err := rS.processThresholds(Resources{r}, opts)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("\nexpected nil, received %+v", err)
|
||||
@@ -3561,7 +3572,7 @@ func TestResourcesProcessThresholdsOK(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
err := rS.processThresholds(r, nil)
|
||||
err := rS.processThresholds(Resources{r}, nil)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("\nexpected nil, received %+v", err)
|
||||
@@ -3635,8 +3646,8 @@ func TestResourcesProcessThresholdsCallErr(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
experr := utils.ErrExists
|
||||
err := rS.processThresholds(r, nil)
|
||||
experr := utils.ErrPartiallyExecuted
|
||||
err := rS.processThresholds(Resources{r}, nil)
|
||||
|
||||
if err == nil || err != experr {
|
||||
t.Errorf("\nexpected: <%+v>, \nreceived: <%+v>", experr, err)
|
||||
@@ -3662,7 +3673,7 @@ func TestResourcesProcessThresholdsThdConnMetaNone(t *testing.T) {
|
||||
}
|
||||
opts := map[string]interface{}{}
|
||||
|
||||
err := rS.processThresholds(r, opts)
|
||||
err := rS.processThresholds(Resources{r}, opts)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("\nexpected nil, received: %+v", err)
|
||||
@@ -5760,8 +5771,8 @@ func TestResourcesV1AllocateResourcesProcessThErr(t *testing.T) {
|
||||
var reply string
|
||||
|
||||
if err := rS.V1AllocateResources(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)
|
||||
}
|
||||
@@ -6287,8 +6298,8 @@ func TestResourcesV1ReleaseResourcesProcessThErr(t *testing.T) {
|
||||
}
|
||||
|
||||
if err := rS.V1ReleaseResources(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