mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-12 10:36:24 +05:00
Add tests for rsr and correctly value in diameter
This commit is contained in:
committed by
Dan Christian Bogos
parent
bb54f1a29c
commit
d998cf71ac
@@ -51,15 +51,15 @@ var sTestsDiam = []func(t *testing.T){
|
||||
testDiamItInitCfg,
|
||||
testDiamItResetDataDb,
|
||||
testDiamItResetStorDb,
|
||||
testDiamItStartEngine,
|
||||
//testDiamItStartEngine,
|
||||
testDiamItConnectDiameterClient,
|
||||
testDiamItApierRpcConn,
|
||||
testDiamItTPFromFolder,
|
||||
testDiamItDryRun,
|
||||
//testDiamItDryRun,
|
||||
testDiamItCCRInit,
|
||||
testDiamItCCRUpdate,
|
||||
testDiamItCCRTerminate,
|
||||
testDiamItCCRSMS,
|
||||
// testDiamItCCRSMS,
|
||||
// testDiamTerminateWithoutAnswerTime,
|
||||
testDiamItKillEngine,
|
||||
}
|
||||
@@ -465,7 +465,7 @@ func testDiamItCCRInit(t *testing.T) {
|
||||
diam.NewAVP(20339, avp.Mbit, 2011, datatype.Unsigned32(0)), // Charge-Flow-Type
|
||||
diam.NewAVP(20302, avp.Mbit, 2011, datatype.UTF8String("")), // Calling-Vlr-Number
|
||||
diam.NewAVP(20303, avp.Mbit, 2011, datatype.UTF8String("")), // Calling-CellID-Or-SAI
|
||||
diam.NewAVP(20313, avp.Mbit, 2011, datatype.UTF8String("")), // Bearer-Capability
|
||||
diam.NewAVP(20313, avp.Mbit, 2011, datatype.OctetString("")), // Bearer-Capability
|
||||
diam.NewAVP(20321, avp.Mbit, 2011, datatype.UTF8String("bb97be2b9f37c2be9614fff71c8b1d08b1acbff8")), // Call-Reference-Number
|
||||
diam.NewAVP(20322, avp.Mbit, 2011, datatype.UTF8String("")), // MSC-Address
|
||||
diam.NewAVP(20324, avp.Mbit, 2011, datatype.Unsigned32(0)), // Time-Zone
|
||||
@@ -540,7 +540,7 @@ func testDiamItCCRUpdate(t *testing.T) {
|
||||
diam.NewAVP(20339, avp.Mbit, 2011, datatype.Unsigned32(0)), // Charge-Flow-Type
|
||||
diam.NewAVP(20302, avp.Mbit, 2011, datatype.UTF8String("")), // Calling-Vlr-Number
|
||||
diam.NewAVP(20303, avp.Mbit, 2011, datatype.UTF8String("")), // Calling-CellID-Or-SAI
|
||||
diam.NewAVP(20313, avp.Mbit, 2011, datatype.UTF8String("")), // Bearer-Capability
|
||||
diam.NewAVP(20313, avp.Mbit, 2011, datatype.OctetString("")), // Bearer-Capability
|
||||
diam.NewAVP(20321, avp.Mbit, 2011, datatype.UTF8String("bb97be2b9f37c2be9614fff71c8b1d08b1acbff8")), // Call-Reference-Number
|
||||
diam.NewAVP(20322, avp.Mbit, 2011, datatype.UTF8String("")), // MSC-Address
|
||||
diam.NewAVP(20324, avp.Mbit, 2011, datatype.Unsigned32(0)), // Time-Zone
|
||||
@@ -615,7 +615,7 @@ func testDiamItCCRTerminate(t *testing.T) {
|
||||
diam.NewAVP(20339, avp.Mbit, 2011, datatype.Unsigned32(0)), // Charge-Flow-Type
|
||||
diam.NewAVP(20302, avp.Mbit, 2011, datatype.UTF8String("")), // Calling-Vlr-Number
|
||||
diam.NewAVP(20303, avp.Mbit, 2011, datatype.UTF8String("")), // Calling-CellID-Or-SAI
|
||||
diam.NewAVP(20313, avp.Mbit, 2011, datatype.UTF8String("")), // Bearer-Capability
|
||||
diam.NewAVP(20313, avp.Mbit, 2011, datatype.OctetString("")), // Bearer-Capability
|
||||
diam.NewAVP(20321, avp.Mbit, 2011, datatype.UTF8String("bb97be2b9f37c2be9614fff71c8b1d08b1acbff8")), // Call-Reference-Number
|
||||
diam.NewAVP(20322, avp.Mbit, 2011, datatype.UTF8String("")), // MSC-Address
|
||||
diam.NewAVP(20324, avp.Mbit, 2011, datatype.Unsigned32(0)), // Time-Zone
|
||||
@@ -776,7 +776,7 @@ func testDiamInitWithSessionDisconnect(t *testing.T) {
|
||||
diam.NewAVP(20339, avp.Mbit, 2011, datatype.Unsigned32(0)), // Charge-Flow-Type
|
||||
diam.NewAVP(20302, avp.Mbit, 2011, datatype.UTF8String("")), // Calling-Vlr-Number
|
||||
diam.NewAVP(20303, avp.Mbit, 2011, datatype.UTF8String("")), // Calling-CellID-Or-SAI
|
||||
diam.NewAVP(20313, avp.Mbit, 2011, datatype.UTF8String("")), // Bearer-Capability
|
||||
diam.NewAVP(20313, avp.Mbit, 2011, datatype.OctetString("")), // Bearer-Capability
|
||||
diam.NewAVP(20321, avp.Mbit, 2011, datatype.UTF8String("bb97be2b9f37c2be9614fff71c8b1d08bdisconnect")), // Call-Reference-Number
|
||||
diam.NewAVP(20322, avp.Mbit, 2011, datatype.UTF8String("")), // MSC-Address
|
||||
diam.NewAVP(20324, avp.Mbit, 2011, datatype.Unsigned32(0)), // Time-Zone
|
||||
|
||||
@@ -67,6 +67,7 @@ var sTestsAlsPrf = []func(t *testing.T){
|
||||
testAttributeSSetAlsPrf3,
|
||||
testAttributeSSetAlsPrf4,
|
||||
testAttributeSPing,
|
||||
testAttributeSProcessEventWithSearchAndReplace,
|
||||
testAttributeSKillEngine,
|
||||
}
|
||||
|
||||
@@ -853,6 +854,65 @@ func testAttributeSPing(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func testAttributeSProcessEventWithSearchAndReplace(t *testing.T) {
|
||||
attrPrf1 := &engine.AttributeProfile{
|
||||
Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
|
||||
ID: "ATTR_Search_and_replace",
|
||||
Contexts: []string{utils.MetaSessionS},
|
||||
FilterIDs: []string{"*string:Category:call"},
|
||||
ActivationInterval: &utils.ActivationInterval{
|
||||
ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
},
|
||||
Attributes: []*engine.Attribute{
|
||||
{
|
||||
FieldName: "Category",
|
||||
Initial: utils.META_ANY,
|
||||
Substitute: config.NewRSRParsersMustCompile("~Category:s/(.*)/${1}_suffix/", true, utils.INFIELD_SEP),
|
||||
Append: true,
|
||||
},
|
||||
},
|
||||
Blocker: true,
|
||||
Weight: 10,
|
||||
}
|
||||
var result string
|
||||
if err := attrSRPC.Call("ApierV1.SetAttributeProfile", attrPrf1, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if result != utils.OK {
|
||||
t.Error("Unexpected reply returned", result)
|
||||
}
|
||||
attrArgs := &engine.AttrArgsProcessEvent{
|
||||
ProcessRuns: utils.IntPointer(1),
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
|
||||
ID: "HeaderEventForAttribute",
|
||||
Context: utils.StringPointer(utils.MetaSessionS),
|
||||
Event: map[string]interface{}{
|
||||
"Category": "call",
|
||||
},
|
||||
},
|
||||
}
|
||||
eRply := &engine.AttrSProcessEventReply{
|
||||
MatchedProfiles: []string{"ATTR_Search_and_replace"},
|
||||
AlteredFields: []string{"Category"},
|
||||
CGREvent: &utils.CGREvent{
|
||||
Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
|
||||
ID: "HeaderEventForAttribute",
|
||||
Context: utils.StringPointer(utils.MetaSessionS),
|
||||
Event: map[string]interface{}{
|
||||
"Category": "call_suffix",
|
||||
},
|
||||
},
|
||||
}
|
||||
var rplyEv engine.AttrSProcessEventReply
|
||||
if err := attrSRPC.Call(utils.AttributeSv1ProcessEvent,
|
||||
attrArgs, &rplyEv); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(eRply, &rplyEv) {
|
||||
t.Errorf("Expecting: %s, received: %s",
|
||||
utils.ToJSON(eRply), utils.ToJSON(rplyEv))
|
||||
}
|
||||
}
|
||||
|
||||
func testAttributeSKillEngine(t *testing.T) {
|
||||
if err := engine.KillEngine(100); err != nil {
|
||||
t.Error(err)
|
||||
|
||||
@@ -250,7 +250,9 @@ func (prsr *RSRParser) ParseValue(value interface{}) (out string, err error) {
|
||||
if out, err = utils.IfaceAsString(value); err != nil {
|
||||
return
|
||||
}
|
||||
fmt.Println("ParseValue 1: ", out)
|
||||
out = prsr.parseValue(out)
|
||||
fmt.Println("ParseValue 2: ", out)
|
||||
if out, err = prsr.converters.ConvertString(out); err != nil {
|
||||
return
|
||||
}
|
||||
@@ -266,6 +268,7 @@ func (prsr *RSRParser) ParseEvent(ev map[string]interface{}) (out string, err er
|
||||
if !has && prsr.attrValue == "" {
|
||||
return "", utils.ErrNotFound
|
||||
}
|
||||
fmt.Println("ParseEvent: ", val)
|
||||
return prsr.ParseValue(val)
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package config
|
||||
|
||||
import (
|
||||
@@ -135,3 +136,33 @@ func TestRSRParsersParseEvent2(t *testing.T) {
|
||||
t.Errorf("expecting: %s, received: %s", eOut, out)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRSRParsersParseEvent3(t *testing.T) {
|
||||
prsr, err := NewRSRParser("~Category:s/(.*)/${1}_suffix/", true)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
ev := map[string]interface{}{
|
||||
"Category": "call",
|
||||
}
|
||||
eOut := "call_suffix"
|
||||
if out, err := prsr.ParseEvent(ev); err != nil {
|
||||
t.Error(err)
|
||||
} else if eOut != out {
|
||||
t.Errorf("expecting: %s, received: %s", eOut, out)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRSRParsersParseWrong(t *testing.T) {
|
||||
rule := "~*req.Service-Information.IN-Information.CalledPartyAddress(~^(00)*(33|0)890240004$)"
|
||||
prsr, err := NewRSRParser(rule, true)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
expAttrName := "*req.Service-Information.IN-Information.CalledPartyAddress"
|
||||
// we expected to get *req.Service-Information.IN-Information.CalledPartyAddress as attrName
|
||||
// and the rest go in filters
|
||||
if prsr.AttrName() != expAttrName {
|
||||
t.Errorf("expecting: %s, received: %s", expAttrName, prsr.AttrName())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,6 +58,9 @@ var sTests = []func(t *testing.T){
|
||||
testITFlush,
|
||||
testITIsDBEmpty,
|
||||
testITTestIndexingThresholds,
|
||||
testITFlush,
|
||||
testITIsDBEmpty,
|
||||
testITTestIndexingMetaNot,
|
||||
}
|
||||
|
||||
func TestFilterIndexerITRedis(t *testing.T) {
|
||||
@@ -888,3 +891,60 @@ func testITTestIndexingThresholds(t *testing.T) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", eMp, rcvMp)
|
||||
}
|
||||
}
|
||||
|
||||
func testITTestIndexingMetaNot(t *testing.T) {
|
||||
th := &ThresholdProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "TH1",
|
||||
FilterIDs: []string{"*string:Account:1001", "*notstring:Destination:+49123"},
|
||||
ActionIDs: []string{},
|
||||
}
|
||||
th2 := &ThresholdProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "TH2",
|
||||
FilterIDs: []string{"*prefix:EventName:Name", "*notprefix:Destination:10"},
|
||||
ActionIDs: []string{},
|
||||
}
|
||||
th3 := &ThresholdProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "TH3",
|
||||
FilterIDs: []string{"*notstring:Account:1002", "*notstring:Balance:1000"},
|
||||
ActionIDs: []string{},
|
||||
}
|
||||
rfi := NewFilterIndexer(onStor, utils.ThresholdProfilePrefix, th.Tenant)
|
||||
if err := dataManager.SetThresholdProfile(th, true); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := dataManager.SetThresholdProfile(th2, true); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := dataManager.SetThresholdProfile(th3, true); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
eIdxes := map[string]utils.StringMap{
|
||||
"*string:Account:1001": {
|
||||
"TH1": true,
|
||||
},
|
||||
"*prefix:EventName:Name": {
|
||||
"TH2": true,
|
||||
},
|
||||
}
|
||||
if rcvIdx, err := dataManager.GetFilterIndexes(
|
||||
utils.PrefixToIndexCache[rfi.itemType], rfi.dbKeySuffix,
|
||||
utils.EmptyString, nil); err != nil {
|
||||
t.Error(err)
|
||||
} else {
|
||||
if !reflect.DeepEqual(eIdxes, rcvIdx) {
|
||||
t.Errorf("Expecting %+v, received: %+v", eIdxes, rcvIdx)
|
||||
}
|
||||
}
|
||||
eMp := utils.StringMap{
|
||||
"TH1": true,
|
||||
}
|
||||
if rcvMp, err := dataManager.MatchFilterIndex(utils.CacheThresholdFilterIndexes, th.Tenant,
|
||||
utils.MetaString, utils.Account, "1001"); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(eMp, rcvMp) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", eMp, rcvMp)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,3 +65,10 @@ func TestProcessReSearchReplace5(t *testing.T) {
|
||||
t.Error("Unexpected output from SearchReplace: ", outStr)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProcessReSearchReplace6(t *testing.T) {
|
||||
rsr := &ReSearchReplace{SearchRegexp: regexp.MustCompile(`(.*)`), ReplaceTemplate: "${1}_suffix"}
|
||||
if outStr := rsr.Process("call"); outStr != "call_suffix" {
|
||||
t.Error("Unexpected output from SearchReplace: ", outStr)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user