From fd5a3f30aee5de83d38413d12e76db6199880ae6 Mon Sep 17 00:00:00 2001 From: ionutboangiu Date: Fri, 9 Jul 2021 17:47:59 +0300 Subject: [PATCH] Add verification to onEviction test in ers --- ers/ers_it_test.go | 45 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/ers/ers_it_test.go b/ers/ers_it_test.go index 929beea6a..e1efbf707 100644 --- a/ers/ers_it_test.go +++ b/ers/ers_it_test.go @@ -24,6 +24,7 @@ import ( "errors" "log" "os" + "path/filepath" "reflect" "strings" "testing" @@ -771,6 +772,9 @@ func TestErsOnEvictedMetaDumpToFileOK(t *testing.T) { } defer os.RemoveAll(dirPath) + val1 := config.NewRSRParsersMustCompile("TestTenant", ",") + val2 := config.NewRSRParsersMustCompile("1001", ",") + val3 := config.NewRSRParsersMustCompile("1002", ",") value := &erEvents{ events: []*utils.CGREvent{ { @@ -788,8 +792,31 @@ func TestErsOnEvictedMetaDumpToFileOK(t *testing.T) { utils.PartialCacheActionOpt: utils.MetaDumpToFile, utils.PartialPathOpt: dirPath, }, + CacheDumpFields: []*config.FCTemplate{ + { + Tag: "Tenant", + Type: utils.MetaConstant, + Path: "*exp.Tenant", + Value: val1, + }, + { + Tag: "Account", + Type: utils.MetaConstant, + Path: "*exp.Account", + Value: val2, + }, + { + Tag: "Destination", + Type: utils.MetaConstant, + Path: "*exp.Destination", + Value: val3, + }, + }, }, } + for _, field := range value.rdrCfg.CacheDumpFields { + field.ComputePath() + } cfg := config.NewDefaultCGRConfig() data := engine.NewInternalDB(nil, nil, true) dm := engine.NewDataManager(data, cfg.CacheCfg(), nil) @@ -799,13 +826,19 @@ func TestErsOnEvictedMetaDumpToFileOK(t *testing.T) { rdrEvents: make(chan *erEvent, 1), filterS: fltrS, } - erS.onEvicted("ID", value) + expBody := "TestTenant,1001,1002\n" + erS.onEvicted("FileID", value) - // rcv, err := os.ReadFile(filepath.Join(dirPath, "ID.*.*")) - // if err != nil { - // t.Error(err) - // } - // fmt.Println(rcv) + path := filepath.Join(dirPath, "FileID.*.tmp") + if match, err := filepath.Glob(path); err != nil { + t.Error(err) + } else if len(match) != 1 { + t.Error("expected exactly one file") + } else if body, err := os.ReadFile(match[0]); err != nil { + t.Error(err) + } else if expBody != string(body) { + t.Errorf("expected: %q\nreceived: %q", expBody, string(body)) + } } func TestErsOnEvictedMetaDumpToFileCSVWriteErr(t *testing.T) {