mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Continue test for rerating through ers
This commit is contained in:
committed by
Dan Christian Bogos
parent
e3915b2009
commit
d7aabe20e3
@@ -28,7 +28,9 @@
|
||||
|
||||
"cdrs": {
|
||||
"enabled": true,
|
||||
"rals_conns": ["*localhost"]
|
||||
"rals_conns": ["*localhost"],
|
||||
"ees_conns": ["*localhost"],
|
||||
"attributes_conns": ["*localhost"]
|
||||
},
|
||||
|
||||
"sessions": {
|
||||
@@ -47,23 +49,24 @@
|
||||
"id": "file_reader1",
|
||||
"run_delay": "-1",
|
||||
"type": "*file_csv",
|
||||
"flags": ["*cdrs", "*rals", "*rerate","*attributes", "*export"],
|
||||
"flags": ["*log","*cdrs", "*rals", "*rerate","*attributes", "*export"],
|
||||
"source_path": "/tmp/ers/in",
|
||||
"processed_path": "/tmp/ers/out",
|
||||
"fields":[
|
||||
{"tag": "ToR", "path": "*cgreq.ToR", "type": "*variable", "value": "~*req.2", "mandatory": true},
|
||||
{"tag": "OriginID", "path": "*cgreq.OriginID", "type": "*variable", "value": "~*req.3", "mandatory": true},
|
||||
{"tag": "RequestType", "path": "*cgreq.RequestType", "type": "*variable", "value": "~*req.4", "mandatory": true},
|
||||
{"tag": "Tenant", "path": "*cgreq.Tenant", "type": "*variable", "value": "~*req.5", "mandatory": true},
|
||||
{"tag": "Category", "path": "*cgreq.Category", "type": "*variable", "value": "~*req.6", "mandatory": true},
|
||||
{"tag": "Account", "path": "*cgreq.Account", "type": "*variable", "value": "~*req.7", "mandatory": true},
|
||||
{"tag": "Subject", "path": "*cgreq.Subject", "type": "*variable", "value": "~*req.8", "mandatory": true},
|
||||
{"tag": "Destination", "path": "*cgreq.Destination", "type": "*variable", "value": "~*req.9", "mandatory": true},
|
||||
{"tag": "SetupTime", "path": "*cgreq.SetupTime", "type": "*variable", "value": "~*req.10", "mandatory": true},
|
||||
{"tag": "AnswerTime", "path": "*cgreq.AnswerTime", "type": "*variable", "value": "~*req.11", "mandatory": true},
|
||||
{"tag": "Usage", "path": "*cgreq.Usage", "type": "*variable", "value": "~*req.12", "mandatory": true},
|
||||
{"tag": "RunID", "path": "*cgreq.RunID", "type": "*variable", "value": "~*req.13", "mandatory": true},
|
||||
{"tag": "Cost", "path": "*cgreq.Cost", "type": "*variable", "value": "~*req.14", "mandatory": true}
|
||||
"fields":[
|
||||
{"tag": "CGRID", "path": "*cgreq.CGRID", "type": "*variable", "value": "~*req.0", "mandatory": true},
|
||||
{"tag": "ToR", "path": "*cgreq.ToR", "type": "*variable", "value": "~*req.1", "mandatory": true},
|
||||
{"tag": "OriginID", "path": "*cgreq.OriginID", "type": "*variable", "value": "~*req.2", "mandatory": true},
|
||||
{"tag": "RequestType", "path": "*cgreq.RequestType", "type": "*variable", "value": "~*req.3", "mandatory": true},
|
||||
{"tag": "Tenant", "path": "*cgreq.Tenant", "type": "*variable", "value": "~*req.4", "mandatory": true},
|
||||
{"tag": "Category", "path": "*cgreq.Category", "type": "*variable", "value": "~*req.5", "mandatory": true},
|
||||
{"tag": "Account", "path": "*cgreq.Account", "type": "*variable", "value": "~*req.6", "mandatory": true},
|
||||
{"tag": "Subject", "path": "*cgreq.Subject", "type": "*variable", "value": "~*req.7", "mandatory": true},
|
||||
{"tag": "Destination", "path": "*cgreq.Destination", "type": "*variable", "value": "~*req.8", "mandatory": true},
|
||||
{"tag": "SetupTime", "path": "*cgreq.SetupTime", "type": "*variable", "value": "~*req.9", "mandatory": true},
|
||||
{"tag": "AnswerTime", "path": "*cgreq.AnswerTime", "type": "*variable", "value": "~*req.10", "mandatory": true},
|
||||
{"tag": "Usage", "path": "*cgreq.Usage", "type": "*variable", "value": "~*req.11", "mandatory": true},
|
||||
{"tag": "RunID", "path": "*cgreq.RunID", "type": "*variable", "value": "~*req.12", "mandatory": true},
|
||||
{"tag": "Cost", "path": "*cgreq.Cost", "type": "*variable", "value": "~*req.13", "mandatory": true}
|
||||
]
|
||||
}
|
||||
]
|
||||
@@ -79,7 +82,7 @@
|
||||
{
|
||||
"id": "CSVExporter",
|
||||
"type": "*file_csv",
|
||||
"export_path": "/tmp/ers/in",
|
||||
"export_path": "/tmp/ees/mv",
|
||||
"timezone": "UTC",
|
||||
"synchronous": true,
|
||||
"attempts": 1,
|
||||
@@ -96,7 +99,7 @@
|
||||
{"tag": "Destination", "path": "*exp.Destination", "type": "*variable", "value": "~*req.Destination"},
|
||||
{"tag": "SetupTime", "path": "*exp.SetupTime", "type": "*variable", "value": "~*req.SetupTime{*time_string}" },
|
||||
{"tag": "AnswerTime", "path": "*exp.AnswerTime", "type": "*variable", "value": "~*req.AnswerTime{*time_string}"},
|
||||
{"tag": "Usage", "path": "*exp.Usage", "type": "*variable", "value": "~*req.Usage{*duration_seconds}"},
|
||||
{"tag": "Usage", "path": "*exp.Usage", "type": "*variable", "value": "~*req.Usage"},
|
||||
{"tag": "RunID", "path": "*exp.RunID", "type": "*variable", "value": "~*req.RunID"},
|
||||
{"tag": "Cost", "path": "*exp.Cost", "type": "*variable", "value": "~*req.Cost{*round:4}"}
|
||||
]
|
||||
|
||||
3
data/tariffplans/reratecdrs/Attributes.csv
Normal file
3
data/tariffplans/reratecdrs/Attributes.csv
Normal file
@@ -0,0 +1,3 @@
|
||||
#Tenant,ID,Contexts,FilterIDs,ActivationInterval,AttributeFilterIDs,Path,Type,Value,Blocker,Weight
|
||||
|
||||
cgrates.org,ATTR_1,,,,,*req.Field,*constant,Value,,
|
||||
|
@@ -21,9 +21,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package general_tests
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -40,7 +40,7 @@ var (
|
||||
rrErsCdrsCfg *config.CGRConfig
|
||||
rrErsCdrsRPC *birpc.Client
|
||||
rrErsCdrsDelay int
|
||||
rrErsCdrsUUID = utils.GenUUID()
|
||||
rrErsCdrsUUID = "38e4d9f4-577f-4260-a7a5-bae8cd5417de"
|
||||
cdrEvent *utils.CGREvent
|
||||
|
||||
rrErsCdrsTests = []func(t *testing.T){
|
||||
@@ -54,8 +54,10 @@ var (
|
||||
testRerateCDRsERsSetBalance,
|
||||
testRerateCDRsERsGetAccountAfterBalanceSet,
|
||||
testRerateCDRsERsProcessEventCDR1,
|
||||
testRerateCDRsERsGetCDRs,
|
||||
testRerateCDRsERsGetCDRs1,
|
||||
testRerateCDRsERsExport,
|
||||
testRerateCDRsERsMoveFiles,
|
||||
testRerateCDRsERsGetCDRs2,
|
||||
testRerateCDRsERsStopEngine,
|
||||
testRerateCDRsERsDeleteFolders,
|
||||
}
|
||||
@@ -69,42 +71,26 @@ func TestReRateCDRsERs(t *testing.T) {
|
||||
}
|
||||
|
||||
func testRerateCDRsERsCreateFolders(t *testing.T) {
|
||||
inPath := "/tmp/ers/in"
|
||||
outPath := "/tmp/ers/out"
|
||||
folders := []string{"/tmp/ers/in", "/tmp/ees/mv", "/tmp/ers/out"}
|
||||
|
||||
// Create the /tmp/ers/in folder
|
||||
err := os.MkdirAll(inPath, os.ModePerm)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create %s: %s", inPath, err)
|
||||
for _, folder := range folders {
|
||||
err := os.MkdirAll(folder, 0755)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create folder %s: %v", folder, err)
|
||||
}
|
||||
}
|
||||
|
||||
// Create the /tmp/ers/out folder
|
||||
err = os.MkdirAll(outPath, os.ModePerm)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create %s: %s", outPath, err)
|
||||
}
|
||||
|
||||
t.Log("Created folders successfully")
|
||||
}
|
||||
|
||||
func testRerateCDRsERsDeleteFolders(t *testing.T) {
|
||||
time.Sleep(5 * time.Second)
|
||||
inPath := "/tmp/ers/in"
|
||||
outPath := "/tmp/ers/out"
|
||||
folders := []string{"/tmp/ers/in", "/tmp/ees/mv", "/tmp/ers/out"}
|
||||
|
||||
// Remove the /tmp/ers/in folder
|
||||
err := os.RemoveAll(inPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to delete %s: %s", inPath, err)
|
||||
for _, folder := range folders {
|
||||
err := os.RemoveAll(folder)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to delete folder %s: %v", folder, err)
|
||||
}
|
||||
}
|
||||
|
||||
// Remove the /tmp/ers/out folder
|
||||
err = os.RemoveAll(outPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to delete %s: %s", outPath, err)
|
||||
}
|
||||
|
||||
t.Log("Deleted folders successfully")
|
||||
}
|
||||
|
||||
func testRerateCDRsERsLoadConfig(t *testing.T) {
|
||||
@@ -197,14 +183,14 @@ func testRerateCDRsERsGetAccountAfterBalanceSet(t *testing.T) {
|
||||
expAcnt.UpdateTime = acnt.UpdateTime
|
||||
expAcnt.BalanceMap[utils.MetaVoice][0].Uuid = acnt.BalanceMap[utils.MetaVoice][0].Uuid
|
||||
if !reflect.DeepEqual(acnt, expAcnt) {
|
||||
t.Errorf("expected: <%+v>,\nreceived: <%+v>", utils.ToJSON(expAcnt), utils.ToJSON(acnt))
|
||||
t.Errorf("expected: <%+v>,\nreceived: \n<%+v>", utils.ToJSON(expAcnt), utils.ToJSON(acnt))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testRerateCDRsERsProcessEventCDR1(t *testing.T) {
|
||||
argsEv := &engine.ArgV1ProcessEvent{
|
||||
Flags: []string{utils.MetaRALs},
|
||||
Flags: []string{utils.MetaRALs, "*export:false"},
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "event1",
|
||||
@@ -235,25 +221,24 @@ func testRerateCDRsERsProcessEventCDR1(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
func testRerateCDRsERsGetCDRs(t *testing.T) {
|
||||
attrs := &utils.RPCCDRsFilter{}
|
||||
func testRerateCDRsERsGetCDRs1(t *testing.T) {
|
||||
rpsCdrFltr := &utils.RPCCDRsFilter{}
|
||||
|
||||
var replies []*engine.ExternalCDR
|
||||
if err := rrErsCdrsRPC.Call(context.Background(), utils.APIerSv2GetCDRs, attrs, &replies); err != nil {
|
||||
if err := rrErsCdrsRPC.Call(context.Background(), utils.APIerSv2GetCDRs, rpsCdrFltr, &replies); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if len(replies) != 1 {
|
||||
t.Fatalf("Expected 1 reply, received \n<%+v>", utils.ToJSON(replies))
|
||||
}
|
||||
|
||||
log.Printf("APIerSv2GetCDRsreply []*engine.ExternalCDR <%+v>", utils.ToJSON(replies))
|
||||
|
||||
if len(replies) == 1 {
|
||||
if reply, err := engine.NewCDRFromExternalCDR(replies[0], utils.EmptyString); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != nil {
|
||||
cdrEvent = reply.AsCGREvent()
|
||||
log.Printf("\nreply <%+v>\n", utils.ToJSON(cdrEvent))
|
||||
}
|
||||
if reply, err := engine.NewCDRFromExternalCDR(replies[0], utils.EmptyString); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply.Usage == 2*time.Minute {
|
||||
cdrEvent = reply.AsCGREvent()
|
||||
cdrEvent.Event[utils.Usage] = 1 * time.Minute
|
||||
} else {
|
||||
t.Error("More than 1 reply")
|
||||
t.Errorf("Expected Usage <%+v>, Received CDR\n<%+v>", 2*time.Minute, utils.ToJSON(reply))
|
||||
}
|
||||
|
||||
}
|
||||
@@ -262,12 +247,52 @@ func testRerateCDRsERsExport(t *testing.T) {
|
||||
cgrEv := &engine.CGREventWithEeIDs{
|
||||
CGREvent: cdrEvent,
|
||||
}
|
||||
log.Printf("cgrEv <%+v>", utils.ToJSON(cgrEv))
|
||||
exp := map[string]map[string]any{
|
||||
"CSVExporter": {},
|
||||
}
|
||||
var reply map[string]map[string]any
|
||||
if err := rrErsCdrsRPC.Call(context.Background(), utils.EeSv1ProcessEvent, cgrEv, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(reply, exp) {
|
||||
t.Errorf("Expected <%+v>, received \n<%+v>", exp, reply)
|
||||
}
|
||||
}
|
||||
|
||||
func testRerateCDRsERsMoveFiles(t *testing.T) {
|
||||
time.Sleep(1 * time.Second)
|
||||
// Move all files from /tmp/ees/mv to /tmp/ers/in
|
||||
srcDir := "/tmp/ees/mv"
|
||||
destDir := "/tmp/ers/in"
|
||||
fileInfos, err := os.ReadDir(srcDir)
|
||||
if err != nil {
|
||||
t.Fatalf("Error reading source directory: %v", err)
|
||||
}
|
||||
|
||||
log.Printf("EeSv1ProcessEvent reply <%+v>", reply)
|
||||
for _, fileInfo := range fileInfos {
|
||||
srcPath := filepath.Join(srcDir, fileInfo.Name())
|
||||
destPath := filepath.Join(destDir, fileInfo.Name())
|
||||
if err := os.Rename(srcPath, destPath); err != nil {
|
||||
t.Fatalf("Error moving file: %v", err)
|
||||
}
|
||||
}
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
}
|
||||
|
||||
func testRerateCDRsERsGetCDRs2(t *testing.T) {
|
||||
rpsCdrFltr := &utils.RPCCDRsFilter{}
|
||||
|
||||
var replies []*engine.ExternalCDR
|
||||
if err := rrErsCdrsRPC.Call(context.Background(), utils.APIerSv2GetCDRs, rpsCdrFltr, &replies); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if len(replies) != 1 {
|
||||
t.Fatalf("Expected 1 reply, received \n<%+v>", utils.ToJSON(replies))
|
||||
}
|
||||
|
||||
if reply, err := engine.NewCDRFromExternalCDR(replies[0], utils.EmptyString); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply.Usage != 1*time.Minute {
|
||||
t.Errorf("Expected Usage <%+v>, Received CDR\n<%+v>", 1*time.Minute, utils.ToJSON(reply))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user