SMGeneric simplified active/passive table management, unified SMGenericV1.ActiveSessions and SMGenericV1.PassiveSessions logic

This commit is contained in:
DanB
2016-11-10 13:32:30 +01:00
parent 9784dc7c38
commit 12bf0667ef
10 changed files with 221 additions and 327 deletions

View File

@@ -1140,86 +1140,6 @@ type AliasValue struct {
Weight float64
}
// AttrSMGGetActiveSessions will filter returned sessions by SMGenericV1
type AttrSMGGetActiveSessions struct {
ToR *string
OriginID *string
RunID *string
RequestType *string
Tenant *string
Category *string
Account *string
Subject *string
Destination *string
Supplier *string
}
// Used for easier filtering, keep struct format to mark filter fields clearly
func (attrs *AttrSMGGetActiveSessions) AsMapStringString() map[string]string {
out := make(map[string]string)
if attrs.ToR != nil {
if *attrs.ToR == "" {
*attrs.ToR = MetaEmpty
}
out[TOR] = *attrs.ToR
}
if attrs.OriginID != nil {
if *attrs.OriginID == "" {
*attrs.OriginID = MetaEmpty
}
out[ACCID] = *attrs.OriginID
}
if attrs.RunID != nil {
if *attrs.RunID == "" {
*attrs.RunID = MetaEmpty
}
out[MEDI_RUNID] = *attrs.RunID
}
if attrs.RequestType != nil {
if *attrs.RequestType == "" {
*attrs.RequestType = MetaEmpty
}
out[REQTYPE] = *attrs.RequestType
}
if attrs.Tenant != nil {
if *attrs.Tenant == "" {
*attrs.Tenant = MetaEmpty
}
out[TENANT] = *attrs.Tenant
}
if attrs.Category != nil {
if *attrs.Category == "" {
*attrs.Category = MetaEmpty
}
out[CATEGORY] = *attrs.Category
}
if attrs.Account != nil {
if *attrs.Account == "" {
*attrs.Account = MetaEmpty
}
out[ACCOUNT] = *attrs.Account
}
if attrs.Subject != nil {
if *attrs.Subject == "" {
*attrs.Subject = MetaEmpty
}
out[SUBJECT] = MetaEmpty
}
if attrs.Destination != nil {
if *attrs.Destination == "" {
*attrs.Destination = MetaEmpty
}
out[DESTINATION] = *attrs.Destination
}
if attrs.Supplier != nil {
if *attrs.Supplier == "" {
*attrs.Supplier = MetaEmpty
}
out[SUPPLIER] = *attrs.Supplier
}
return out
}
type AttrRateCDRs struct {
RPCCDRsFilter
StoreCDRs *bool

View File

@@ -30,33 +30,3 @@ func TestNewDTCSFromRPKey(t *testing.T) {
t.Error("Received: ", dtcs)
}
}
func TestAPIAttrSMGGetActiveSessionsAsMapStr(t *testing.T) {
attrs := &AttrSMGGetActiveSessions{
ToR: StringPointer(""),
OriginID: StringPointer(""),
RunID: StringPointer(""),
RequestType: StringPointer(""),
Tenant: StringPointer(""),
Category: StringPointer(""),
Account: StringPointer(""),
Subject: StringPointer(""),
Destination: StringPointer(""),
Supplier: StringPointer(""),
}
expectMP := map[string]string{
TOR: MetaEmpty,
ACCID: MetaEmpty,
MEDI_RUNID: MetaEmpty,
REQTYPE: MetaEmpty,
TENANT: MetaEmpty,
CATEGORY: MetaEmpty,
ACCOUNT: MetaEmpty,
SUBJECT: MetaEmpty,
DESTINATION: MetaEmpty,
SUPPLIER: MetaEmpty,
}
if mp := attrs.AsMapStringString(); !reflect.DeepEqual(expectMP, mp) {
t.Errorf("Expecting: %+v, received: %+v", expectMP, mp)
}
}