diff --git a/engine/actions_test.go b/engine/actions_test.go index f43da16ee..d438b4949 100644 --- a/engine/actions_test.go +++ b/engine/actions_test.go @@ -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) + } +} diff --git a/engine/attributes_test.go b/engine/attributes_test.go index 068f94492..2ce04b3d3 100644 --- a/engine/attributes_test.go +++ b/engine/attributes_test.go @@ -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)) + } +} diff --git a/engine/balances_test.go b/engine/balances_test.go index d399dd791..54ac304fd 100644 --- a/engine/balances_test.go +++ b/engine/balances_test.go @@ -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) + } } diff --git a/engine/dispatcherprfl_test.go b/engine/dispatcherprfl_test.go index 5bdd7578f..0b3dd43d3 100644 --- a/engine/dispatcherprfl_test.go +++ b/engine/dispatcherprfl_test.go @@ -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) { diff --git a/engine/exportrequest_test.go b/engine/exportrequest_test.go index 445731e07..24a09e648 100644 --- a/engine/exportrequest_test.go +++ b/engine/exportrequest_test.go @@ -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) + } + +} diff --git a/engine/safevent_test.go b/engine/safevent_test.go index 209ba7f80..1c2a0624a 100644 --- a/engine/safevent_test.go +++ b/engine/safevent_test.go @@ -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)) + } +}