mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-15 21:29:52 +05:00
coverage tests at engine
This commit is contained in:
committed by
Dan Christian Bogos
parent
5c8f0e78ea
commit
b1b01a246f
@@ -2816,3 +2816,17 @@ func BenchmarkUUID(b *testing.B) {
|
||||
b.StartTimer()
|
||||
}
|
||||
}
|
||||
|
||||
func TestResetAccountCDR(t *testing.T) {
|
||||
var ub *Account
|
||||
action := &Action{}
|
||||
fltrS := &FilterS{}
|
||||
acts := Actions{}
|
||||
if err := resetAccountCDR(ub, action, acts, fltrS, nil); err == nil {
|
||||
t.Error(err)
|
||||
}
|
||||
ub = &Account{}
|
||||
if err := resetAccountCDR(ub, action, acts, fltrS, nil); err == nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1330,3 +1330,63 @@ func TestAttributesV1ProcessEventMultipleRuns2(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestArgeesUnmarshalJSON(t *testing.T) {
|
||||
cgr := &CGREventWithEeIDs{
|
||||
EeIDs: []string{"eeID1", "eeID2", "eeID3", "eeID$"},
|
||||
clnb: true,
|
||||
CGREvent: &utils.CGREvent{
|
||||
Event: map[string]interface{}{
|
||||
utils.CostDetails: "22",
|
||||
},
|
||||
},
|
||||
}
|
||||
if err := cgr.UnmarshalJSON([]byte("val")); err == nil {
|
||||
t.Error(err)
|
||||
} else if err = cgr.UnmarshalJSON([]byte(`{
|
||||
"EeIDs":["eeid1","eeid2"],
|
||||
"CGREvent":{
|
||||
"Event":{
|
||||
"CostDetails":"22"
|
||||
}
|
||||
}}`)); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestArgeesRPCClone(t *testing.T) {
|
||||
|
||||
attr := &CGREventWithEeIDs{
|
||||
EeIDs: []string{"eeid1", "eeid2"},
|
||||
CGREvent: &utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "id",
|
||||
Time: &time.Time{},
|
||||
Event: map[string]interface{}{},
|
||||
APIOpts: map[string]interface{}{},
|
||||
},
|
||||
clnb: false,
|
||||
}
|
||||
if val, err := attr.RPCClone(); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(val, attr) {
|
||||
t.Errorf("expected %v,received %v", utils.ToJSON(attr), utils.ToJSON(val))
|
||||
}
|
||||
attr.clnb = true
|
||||
exp := &CGREventWithEeIDs{
|
||||
EeIDs: []string{"eeid1", "eeid2"},
|
||||
CGREvent: &utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "id",
|
||||
Time: &time.Time{},
|
||||
Event: map[string]interface{}{},
|
||||
APIOpts: map[string]interface{}{},
|
||||
},
|
||||
}
|
||||
|
||||
if val, err := attr.RPCClone(); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(val, exp) {
|
||||
t.Errorf("expected %v,received %v", utils.ToJSON(exp), utils.ToJSON(val))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -376,6 +376,55 @@ func TestBalanceAsInterface(t *testing.T) {
|
||||
} else if _, err = b.FieldAsInterface([]string{"Factor[factor1]"}); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if _, err = b.FieldAsInterface([]string{utils.Uuid}); err != nil {
|
||||
t.Error(err)
|
||||
} else if _, err = b.FieldAsInterface([]string{utils.ExpirationDate}); err != nil {
|
||||
t.Error(err)
|
||||
} else if _, err = b.FieldAsInterface([]string{utils.Weight}); err != nil {
|
||||
t.Error(err)
|
||||
} else if _, err = b.FieldAsInterface([]string{utils.DestinationIDs}); err != nil {
|
||||
t.Error(err)
|
||||
} else if _, err = b.FieldAsInterface([]string{utils.DestinationIDs}); err != nil {
|
||||
t.Error(err)
|
||||
} else if _, err = b.FieldAsInterface([]string{utils.RatingSubject}); err != nil {
|
||||
t.Error(err)
|
||||
} else if _, err = b.FieldAsInterface([]string{utils.Categories}); err != nil {
|
||||
t.Error(err)
|
||||
} else if _, err = b.FieldAsInterface([]string{utils.SharedGroups}); err != nil {
|
||||
t.Error(err)
|
||||
} else if _, err = b.FieldAsInterface([]string{utils.Timings}); err != nil {
|
||||
t.Error(err)
|
||||
} else if _, err = b.FieldAsInterface([]string{utils.Disabled}); err != nil {
|
||||
t.Error(err)
|
||||
} else if _, err = b.FieldAsInterface([]string{utils.Factor}); err != nil {
|
||||
t.Error(err)
|
||||
} else if _, err = b.FieldAsInterface([]string{utils.Blocker}); err != nil {
|
||||
t.Error(err)
|
||||
} else if _, err = b.FieldAsInterface([]string{utils.TimingIDs}); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if _, err = b.FieldAsInterface([]string{utils.TimingIDs, "val"}); err == nil || err != utils.ErrNotFound {
|
||||
t.Error(err)
|
||||
} else if _, err = b.FieldAsInterface([]string{utils.Uuid, "val"}); err == nil || err != utils.ErrNotFound {
|
||||
t.Error(err)
|
||||
} else if _, err = b.FieldAsInterface([]string{utils.ID, "val"}); err == nil || err != utils.ErrNotFound {
|
||||
t.Error(err)
|
||||
} else if _, err = b.FieldAsInterface([]string{utils.Value, "val"}); err == nil || err != utils.ErrNotFound {
|
||||
t.Error(err)
|
||||
} else if _, err = b.FieldAsInterface([]string{utils.ExpirationDate, "val"}); err == nil || err != utils.ErrNotFound {
|
||||
t.Error(err)
|
||||
} else if _, err = b.FieldAsInterface([]string{utils.Weight, "val"}); err == nil || err != utils.ErrNotFound {
|
||||
t.Error(err)
|
||||
} else if _, err = b.FieldAsInterface([]string{utils.DestinationIDs, "val"}); err == nil || err != utils.ErrNotFound {
|
||||
t.Error(err)
|
||||
} else if _, err = b.FieldAsInterface([]string{utils.RatingSubject, "val"}); err == nil || err != utils.ErrNotFound {
|
||||
t.Error(err)
|
||||
} else if _, err = b.FieldAsInterface([]string{utils.Categories, "val"}); err == nil || err != utils.ErrNotFound {
|
||||
t.Error(err)
|
||||
} else if _, err = b.FieldAsInterface([]string{utils.SharedGroups, "val"}); err == nil || err != utils.ErrNotFound {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -238,7 +238,7 @@ func (v *testRPCHost) Call(serviceMethod string, args interface{}, reply interfa
|
||||
|
||||
func TestDispatcherHostCall(t *testing.T) {
|
||||
tRPC := &testRPCHost{}
|
||||
dspHost := DispatcherHost{}
|
||||
dspHost := &DispatcherHost{}
|
||||
etRPC := &testRPCHost{
|
||||
serviceMethod: utils.AttributeSv1Ping,
|
||||
args: &utils.CGREvent{},
|
||||
@@ -251,6 +251,7 @@ func TestDispatcherHostCall(t *testing.T) {
|
||||
} else if !reflect.DeepEqual(*etRPC, *tRPC) {
|
||||
t.Errorf("Expected: %s , received: %s", utils.ToJSON(etRPC), utils.ToJSON(tRPC))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestDispatcherHostIDsProfilesReorderFromIndex(t *testing.T) {
|
||||
|
||||
@@ -283,6 +283,10 @@ func TestExportReqFieldAsINterfaceOnePath(t *testing.T) {
|
||||
} else if !reflect.DeepEqual(val, mS[utils.MetaReq]) {
|
||||
t.Errorf("Expected %+v \n, received %+v", val, mS[utils.MetaReq])
|
||||
}
|
||||
fldPath = []string{"default"}
|
||||
if _, err = eventReq.FieldAsInterface(fldPath); err == nil {
|
||||
t.Error("expected error")
|
||||
}
|
||||
|
||||
fldPath = []string{utils.MetaOpts}
|
||||
if val, err := eventReq.FieldAsInterface(fldPath); err != nil {
|
||||
@@ -297,6 +301,10 @@ func TestExportReqFieldAsINterfaceOnePath(t *testing.T) {
|
||||
} else if !reflect.DeepEqual(val, mS[utils.MetaVars]) {
|
||||
t.Errorf("Expected %+v \n, received %+v", val, mS[utils.MetaVars])
|
||||
}
|
||||
fldPath = []string{utils.MetaUCH}
|
||||
if _, err = eventReq.FieldAsInterface(fldPath); err == nil || err != utils.ErrNotFound {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
func TestEventReqFieldAsInterface(t *testing.T) {
|
||||
inData := map[string]utils.DataStorage{
|
||||
@@ -353,3 +361,171 @@ func TestEventReqNewEventExporter(t *testing.T) {
|
||||
t.Errorf("Expected %v \n but received \n %v", expected, eventReq)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExportRequestSetAsSlice(t *testing.T) {
|
||||
onm := utils.NewOrderedNavigableMap()
|
||||
fullpath := &utils.FullPath{
|
||||
PathSlice: []string{utils.MetaReq, utils.MetaTenant},
|
||||
Path: utils.MetaTenant,
|
||||
}
|
||||
value := &utils.DataLeaf{
|
||||
Data: "value1",
|
||||
}
|
||||
onm.Append(fullpath, value)
|
||||
expData := map[string]*utils.OrderedNavigableMap{
|
||||
"default": onm,
|
||||
}
|
||||
|
||||
eeR := &ExportRequest{
|
||||
inData: map[string]utils.DataStorage{
|
||||
utils.MetaReq: utils.MapStorage{
|
||||
"Account": "1001",
|
||||
"Usage": "10m",
|
||||
},
|
||||
utils.MetaOpts: utils.MapStorage{},
|
||||
},
|
||||
tnt: "cgrates.org",
|
||||
ExpData: expData,
|
||||
}
|
||||
|
||||
fullPath := &utils.FullPath{
|
||||
PathSlice: []string{utils.MetaUCH, utils.MetaReq, utils.MetaTenant},
|
||||
Path: utils.MetaTenant,
|
||||
}
|
||||
val := &utils.DataLeaf{
|
||||
Data: "value1",
|
||||
}
|
||||
|
||||
if err := eeR.SetAsSlice(fullPath, val); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
fullPath.PathSlice[0] = utils.MetaOpts
|
||||
if err = eeR.SetAsSlice(fullPath, val); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
fullPath.PathSlice[0] = "default"
|
||||
if err = eeR.SetAsSlice(fullPath, val); err != nil {
|
||||
t.Error(err)
|
||||
} else if err = eeR.SetAsSlice(&utils.FullPath{PathSlice: []string{"Val"}}, val); err == nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExportRequestParseField(t *testing.T) {
|
||||
fctTemp := &config.FCTemplate{
|
||||
Type: utils.MetaMaskedDestination,
|
||||
Value: config.NewRSRParsersMustCompile("*month_endTest", utils.InfieldSep),
|
||||
Layout: "“Mon Jan _2 15:04:05 2006”",
|
||||
Timezone: "Local",
|
||||
MaskLen: 3,
|
||||
MaskDestID: "dest",
|
||||
}
|
||||
mS := map[string]utils.DataStorage{
|
||||
utils.MetaReq: utils.MapStorage{
|
||||
utils.AccountField: "1004",
|
||||
utils.Usage: "20m",
|
||||
utils.Destination: "dest",
|
||||
},
|
||||
utils.MetaOpts: utils.MapStorage{
|
||||
utils.APIKey: "attr12345",
|
||||
},
|
||||
utils.MetaVars: utils.MapStorage{
|
||||
utils.RequestType: utils.MetaRated,
|
||||
utils.Subsystems: utils.MetaChargers,
|
||||
},
|
||||
}
|
||||
eventReq := NewExportRequest(mS, "", nil, nil)
|
||||
|
||||
if _, err := eventReq.ParseField(fctTemp); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestExportRequestAppend(t *testing.T) {
|
||||
onm := utils.NewOrderedNavigableMap()
|
||||
fullpath := &utils.FullPath{
|
||||
PathSlice: []string{utils.MetaReq, utils.MetaTenant},
|
||||
Path: utils.MetaTenant,
|
||||
}
|
||||
value := &utils.DataLeaf{
|
||||
Data: "value1",
|
||||
}
|
||||
onm.Append(fullpath, value)
|
||||
expData := map[string]*utils.OrderedNavigableMap{
|
||||
"default": onm,
|
||||
}
|
||||
|
||||
eeR := &ExportRequest{
|
||||
inData: map[string]utils.DataStorage{
|
||||
utils.MetaReq: utils.MapStorage{
|
||||
"Account": "1001",
|
||||
"Usage": "10m",
|
||||
},
|
||||
utils.MetaOpts: utils.MapStorage{},
|
||||
},
|
||||
tnt: "cgrates.org",
|
||||
ExpData: expData,
|
||||
}
|
||||
|
||||
fullPath := &utils.FullPath{
|
||||
PathSlice: []string{utils.MetaUCH, utils.MetaReq, utils.MetaTenant},
|
||||
Path: utils.MetaTenant,
|
||||
}
|
||||
val := &utils.DataLeaf{
|
||||
Data: "value1",
|
||||
}
|
||||
|
||||
if err := eeR.Append(fullPath, val); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
fullPath.PathSlice[0] = utils.MetaOpts
|
||||
if err = eeR.Append(fullPath, val); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
fullPath.PathSlice[0] = "default"
|
||||
if err = eeR.Append(fullPath, val); err != nil {
|
||||
t.Error(err)
|
||||
} else if err = eeR.Append(&utils.FullPath{PathSlice: []string{"Val"}}, val); err == nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestExportRequestCompose(t *testing.T) {
|
||||
onm := utils.NewOrderedNavigableMap()
|
||||
fullPath := &utils.FullPath{
|
||||
PathSlice: []string{utils.MetaReq, utils.MetaTenant},
|
||||
Path: utils.MetaTenant,
|
||||
}
|
||||
val := &utils.DataLeaf{
|
||||
Data: "value1",
|
||||
}
|
||||
onm.Append(fullPath, val)
|
||||
|
||||
eeR := &ExportRequest{
|
||||
inData: map[string]utils.DataStorage{
|
||||
utils.MetaReq: utils.MapStorage{
|
||||
"Account": "1001",
|
||||
"Usage": "10m",
|
||||
},
|
||||
},
|
||||
filterS: nil,
|
||||
tnt: "cgrates.org",
|
||||
ExpData: map[string]*utils.OrderedNavigableMap{
|
||||
utils.MetaReq: onm,
|
||||
},
|
||||
}
|
||||
if err := eeR.Compose(&utils.FullPath{
|
||||
PathSlice: []string{utils.MetaReq},
|
||||
Path: "path"}, &utils.DataLeaf{
|
||||
Data: "Value"}); err == nil {
|
||||
t.Error(err)
|
||||
} else if err = eeR.Compose(&utils.FullPath{
|
||||
PathSlice: []string{"default"},
|
||||
Path: "path"}, &utils.DataLeaf{
|
||||
Data: "Value"}); err == nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -798,3 +798,20 @@ func TestSafEventGetDurationOrDefault(t *testing.T) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestSafEventAsCGREvent(t *testing.T) {
|
||||
se := SafEvent{Me: MapEvent{
|
||||
"ExtraField1": 5,
|
||||
"Source": 1001,
|
||||
"CostSource": "1002",
|
||||
"ExtraField2": "extra",
|
||||
"SetupTime": "2009-11-10T23:00:00Z",
|
||||
"Usage": "42s",
|
||||
"PreRated": "True",
|
||||
"Cost": "42.3",
|
||||
}}
|
||||
|
||||
if cgrEv := se.AsCGREvent("cgrates.org"); reflect.DeepEqual(se.Me, cgrEv.Event) {
|
||||
t.Errorf("expected %v,received %v", utils.ToJSON(se.Me), utils.ToJSON(cgrEv.Event))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user