mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-16 05:39:54 +05:00
Testing DumpToFile case in onEvicted method in ers when CacheDumpFields opt does not exist
This commit is contained in:
committed by
Dan Christian Bogos
parent
e379624037
commit
ee7f372010
@@ -959,3 +959,108 @@ func TestErsOnEvictedMetaDumpToFileCreateErr(t *testing.T) {
|
||||
|
||||
utils.Logger.SetLogLevel(0)
|
||||
}
|
||||
|
||||
func TestErsOnEvictedNoCacheDumpFields(t *testing.T) {
|
||||
dirPath := "/tmp/TestErsOnEvictedCacheDumpfields"
|
||||
err := os.MkdirAll(dirPath, 0755)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
value := &erEvents{
|
||||
events: []*utils.CGREvent{
|
||||
{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "EventErsOnEvicted",
|
||||
Event: map[string]interface{}{
|
||||
utils.AccountField: "1001",
|
||||
utils.Usage: "10s",
|
||||
utils.Category: "call",
|
||||
utils.Destination: "1002",
|
||||
utils.OriginHost: "local",
|
||||
utils.OriginID: "123456",
|
||||
utils.ToR: utils.MetaVoice,
|
||||
utils.CGRID: "1133dc80896edf5049b46aa911cb9085eeb27f4c",
|
||||
utils.Password: "secure_pass",
|
||||
"Additional_Field": "Additional_Value",
|
||||
},
|
||||
},
|
||||
},
|
||||
rdrCfg: &config.EventReaderCfg{ // CacheDumpFields will be empty
|
||||
ID: "ER1",
|
||||
Type: utils.MetaNone,
|
||||
Opts: map[string]interface{}{
|
||||
utils.PartialCacheActionOpt: utils.MetaDumpToFile,
|
||||
utils.PartialPathOpt: dirPath,
|
||||
utils.PartialOrderFieldOpt: 2,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
value2 := &erEvents{
|
||||
events: []*utils.CGREvent{
|
||||
{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "EventErsOnEvicted2",
|
||||
Event: map[string]interface{}{
|
||||
utils.AccountField: "1002",
|
||||
utils.Usage: "12s",
|
||||
utils.Category: "call",
|
||||
utils.Destination: "1003",
|
||||
utils.OriginID: "1234567",
|
||||
utils.ToR: utils.MetaSMS,
|
||||
utils.CGRID: "1133dc80896edf5049b46aa911cb9085eeb27f4d",
|
||||
utils.Password: "secure_password",
|
||||
"Additional_Field": "Additional_Value2",
|
||||
},
|
||||
},
|
||||
},
|
||||
rdrCfg: &config.EventReaderCfg{ // CacheDumpFields will be empty
|
||||
ID: "ER2",
|
||||
Type: utils.MetaNone,
|
||||
Opts: map[string]interface{}{
|
||||
utils.PartialCacheActionOpt: utils.MetaDumpToFile,
|
||||
utils.PartialPathOpt: dirPath,
|
||||
utils.PartialOrderFieldOpt: 2,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
data := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items)
|
||||
dm := engine.NewDataManager(data, cfg.CacheCfg(), nil)
|
||||
fltrS := engine.NewFilterS(cfg, nil, dm)
|
||||
erS := &ERService{
|
||||
cfg: cfg,
|
||||
rdrEvents: make(chan *erEvent, 1),
|
||||
filterS: fltrS,
|
||||
}
|
||||
|
||||
erS.onEvicted("ID", value)
|
||||
erS.onEvicted("ID2", value2)
|
||||
|
||||
var files []string
|
||||
err = filepath.Walk(dirPath, func(path string, info os.FileInfo, err error) error {
|
||||
if !info.IsDir() {
|
||||
files = append(files, path)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
var compare map[int][]string
|
||||
compare = make(map[int][]string, 2)
|
||||
for idx, file := range files {
|
||||
data, err := os.ReadFile(file)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
s := strings.Split(string((data)), ",")
|
||||
|
||||
compare[idx] = s
|
||||
}
|
||||
if len(compare[0]) != 10 && len(compare[1]) != 9 {
|
||||
t.Error("Expected 10 and 9")
|
||||
}
|
||||
if err := os.RemoveAll(dirPath); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user